components.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. // 通用数据
  2. let globaldata = {
  3. // 滚动高度
  4. scrollheight: 50,
  5. // body
  6. body: document.documentElement || document.body
  7. }
  8. // 大屏 下拉菜单
  9. $(
  10. function () {
  11. let navitems = $("#nav>.nav-item");
  12. const move = (that, show) => {
  13. let lis = $(that).find("li"),
  14. i = $(that).find("i");
  15. ul = $(that).find("ul");
  16. if (lis.length != 0 && show) {
  17. ul.addClass("show");
  18. i.removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
  19. return false;
  20. }
  21. if (lis.length != 0 && !show) {
  22. ul.removeClass("show")
  23. i.removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
  24. return false;
  25. }
  26. return false;
  27. }
  28. for (let i = 0; i < navitems.length; i++) {
  29. $(navitems[i]).mouseenter(function () {
  30. let that = this;
  31. move(that, true)
  32. }).mouseleave(function () {
  33. let that = this;
  34. move(that, false)
  35. })
  36. }
  37. }
  38. )
  39. // 监听滚动轴
  40. $(function () {
  41. // face显示锁
  42. let lock = true;
  43. // top显示锁
  44. let locktop = false;
  45. // 滚动高度
  46. let height = globaldata.scrollheight;
  47. $("body")[0].onscroll = function () {
  48. let stop = globaldata.body.scrollTop;
  49. // console.log(stop)
  50. // 可是区域宽度;
  51. if (stop > height && !locktop) {
  52. $("#top").removeClass("noshow");
  53. locktop = true;
  54. }
  55. if (stop < height && locktop) {
  56. $("#top").addClass("noshow");
  57. locktop = false;
  58. }
  59. if ($("body")[0].clientWidth < 768) {
  60. return false;
  61. }
  62. if (stop > height && lock) {
  63. $("#face").addClass("noshow");
  64. lock = false
  65. return false;
  66. }
  67. if (stop <= height && !lock) {
  68. $("#face").removeClass("noshow");
  69. lock = true;
  70. return false;
  71. }
  72. }
  73. })
  74. // 小屏幕 下拉菜单
  75. $(function () {
  76. // 按钮开关
  77. let lock = false;
  78. const open = () => {
  79. if (!lock) {
  80. $("#nav-sm").addClass("nav-sm-show").removeClass("nav-sm-noshow");
  81. globaldata.body.addEventListener('touchmove', e =>
  82. e.preventDefault()
  83. , { passive: false })
  84. lock = true
  85. return false;
  86. }
  87. if (lock) {
  88. $("#nav-sm").addClass("nav-sm-noshow").removeClass("nav-sm-show");
  89. globaldata.body.removeEventListener('touchmove', e => e.preventDefault() = true, { passive: false })
  90. lock = false;
  91. return false;
  92. }
  93. }
  94. $('#listbutton').click(function () {
  95. open()
  96. })
  97. // 可视区域变化
  98. window.onresize = () => {
  99. let appwidth = $("body")[0].clientWidth;
  100. if (appwidth > 768) {
  101. $("#nav-sm").removeClass("nav-sm-show");
  102. lock = false;
  103. return false;
  104. } else {
  105. // face 移动端显示
  106. try {
  107. $("#face").removeClass("noshow");
  108. } catch (err) { }
  109. }
  110. // if (lock) {
  111. // $("#nav-sm").addClass("nav-sm-show");
  112. // return false;
  113. // }
  114. }
  115. })
  116. // 分享设置
  117. var shareModel = {
  118. // /**
  119. // * 分享QQ好友
  120. // * @param {[type]} title [分享标题]
  121. // * @param {[type]} url [分享url链接,默认当前页面链接]
  122. // * @param {[type]} pic [分享图片]
  123. // * @return {[type]} [description]
  124. // */
  125. shareQQ: function (url, title, pic) {
  126. var param = {
  127. url: url || window.location.href,
  128. desc: '', /*分享理由*/
  129. title: title || '', /*分享标题(可选)*/
  130. summary: '',/*分享描述(可选)*/
  131. pics: pic || '',/*分享图片(可选)*/
  132. flash: '', /*视频地址(可选)*/
  133. site: '' /*分享来源 (可选) */
  134. };
  135. var s = [];
  136. for (var i in param) {
  137. s.push(i + '=' + encodeURIComponent(param[i] || ''));
  138. }
  139. var targetUrl = "https://connect.qq.com/widget/shareqq/iframe_index.html?" + s.join('&');
  140. window.open(targetUrl, 'qq');
  141. },
  142. // /**
  143. // * 微信分享
  144. // * @return {[type]} [description]
  145. // */
  146. weixin: function () {
  147. var url = window.location.href,
  148. encodePath = encodeURIComponent(url),
  149. targetUrl = 'https://api.gaokaozhitongche.com/v1/direct?text=' + encodePath;
  150. window.open(targetUrl, 'weixin');
  151. },
  152. // /**
  153. // * 分享新浪微博
  154. // * @param {[type]} title [分享标题]
  155. // * @param {[type]} url [分享url链接,默认当前页面]
  156. // * @param {[type]} pic [分享图片]
  157. // * @return {[type]} [description]
  158. // */
  159. sinaWeiBo: function (title, url, pic) {
  160. var param = {
  161. url: url || window.location.href,
  162. type: '3',
  163. count: '1', /** 是否显示分享数,1显示(可选)*/
  164. appkey: '', /** 您申请的应用appkey,显示分享来源(可选)*/
  165. title: '', /** 分享的文字内容(可选,默认为所在页面的title)*/
  166. pic: pic || '', /**分享图片的路径(可选)*/
  167. ralateUid: '', /**关联用户的UID,分享微博会@该用户(可选)*/
  168. rnd: new Date().valueOf()
  169. }
  170. var temp = [];
  171. for (var p in param) {
  172. temp.push(p + '=' + encodeURIComponent(param[p] || ''))
  173. }
  174. var targetUrl = 'https://service.weibo.com/share/share.php?' + temp.join('&');
  175. window.open(targetUrl, 'sinaweibo');
  176. }
  177. };
  178. $(function () {
  179. $("#share").mouseenter(function () {
  180. $(this).children("ul").css("width", 'auto')
  181. }).mouseleave(function () {
  182. $(this).children("ul").css("width", '0px')
  183. })
  184. let lis = $("#share>ul>li");
  185. for (let i = 0; i < lis.length; i++) {
  186. if (i == 1) {
  187. $(lis[i]).click(function () {
  188. shareModel.shareQQ();
  189. })
  190. }
  191. // if (i == 2) {
  192. // $(lis[i]).click(function () {
  193. // shareModel.weixin(url = "https://app.gaokaozhitongche.com/");
  194. // })
  195. // }
  196. if (i == 2) {
  197. $(lis[i]).click(function () {
  198. console.log(1)
  199. shareModel.sinaWeiBo();
  200. })
  201. }
  202. }
  203. })
  204. // 按钮锁
  205. $(function () {
  206. $("#top").click(function () {
  207. let dom = globaldata.body;
  208. // let top = document.documentElement.scrollTop || document.body.scrollTop;
  209. $(dom).animate({ scrollTop: 0 }, 500);
  210. })
  211. })
  212. // toast 背景事件
  213. $(function () {
  214. $("#toast").click(function (e) {
  215. if (e.target.id != 'toast') return false
  216. $(this).removeClass("show");
  217. Array.prototype.slice.call($(this).find(".show")).forEach(e => {
  218. $(e).removeClass("show")
  219. })
  220. })
  221. })
  222. // 下载app
  223. $(function () {
  224. $("#download button").click(
  225. function () {
  226. window.location.href = "http://down.gaokaoapp.net";
  227. }
  228. )
  229. })
  230. // 评论区 点赞
  231. $(function () {
  232. const globaldata = {
  233. // 用户是否登录
  234. user: false,
  235. // 登录弹框
  236. sgin () {
  237. $("#toast").addClass("show").find(".msg").addClass("show").unbind("click").click(function () {
  238. window.location.href = "http://down.gaokaoapp.net"
  239. });
  240. }
  241. }
  242. // 显示区高度
  243. let ch = document.documentElement.clientHeight || document.body.clientHeight;
  244. // 实现评论区加载
  245. let lock = false;
  246. $(window).scroll(function () {
  247. if (lock) return false;
  248. // 滑动区高度
  249. let sh = document.documentElement.scrollHeight || document.body.scrollHeight;
  250. // 滑动位置
  251. let st = document.documentElement.scrollTop || document.body.scrollTop;
  252. let c = sh * 1 - ch * 1 - st * 1;
  253. if (c == 0) {
  254. lock = true;
  255. $(".comment>.loading").addClass("show")
  256. setTimeout(function (
  257. ) {
  258. $(".comment>.loading").removeClass("show");
  259. data().then(res => {
  260. if (res) {
  261. $(".comment>.nodata").addClass("show");
  262. }
  263. lock = res;
  264. });
  265. }, 2000)
  266. }
  267. })
  268. // 阅读量问题
  269. // 评论区
  270. function data () {
  271. // 请求 根据请求改变内容 唯一标识 data-userid="1" data-good="false"
  272. let com = `<div class="user" data-good="false" data-userid="1" >
  273. <div class="u-img"><img src="../imgs/qq.png" alt="" class="img"></div>
  274. <div class="u-content">
  275. <div class="u-flex">
  276. <div class="u-name">QQ官方</div>
  277. <div class="u-fabulous" data-gods="1"><span>0</span><i data-gods="1" style="margin-left:5px" class="glyphicon glyphicon-thumbs-up"></i></div>
  278. </div>
  279. <div class="u-detail">
  280. 对此,广东警官学院表示,其普通高等教育(全日制)招生工作严格执行教育部的“阳光高考”规定和工作程序,不以任何形式承诺录取,不因任何理由降低标准录取。学校从未委托任何个人、中介组织或招生机构开展提前招生、高职扩招等宣
  281. </div>
  282. <div class="u-flex">
  283. <div class="u-date">2020-12-15</div>
  284. <div data-gods="2" class="u-report">举报</div>
  285. </div>
  286. </div>
  287. </div>`;
  288. return new Promise(resolve => {
  289. $("#detail").append(com);
  290. //评论点赞 登录状态 请求
  291. let lists = $("#detail>.user");
  292. // 模拟无信息加载情况
  293. if (lists.length == 10) {
  294. resolve(true)
  295. }
  296. for (let i = 0; i < lists.length; i++) {
  297. $(lists[i]).unbind("click");
  298. $(lists[i]).click(function (e) {
  299. if (!globaldata.user) {
  300. globaldata.sgin();
  301. return false
  302. }
  303. let userid = $(this).data("userid");
  304. let lock = $(this).data("good");
  305. let gods = e.target.dataset.gods;
  306. if (gods == 1) {
  307. let $i = $(this).find("i");
  308. let $span = $(this).find("span");
  309. let num = $span.text();
  310. if (!lock) {
  311. $i.addClass("color");
  312. $(this).data("good", true);
  313. $span.text(num * 1 + 1);
  314. } else {
  315. $i.removeClass("color");
  316. $(this).data("good", false);
  317. $span.text(num * 1 - 1);
  318. }
  319. return false;
  320. }
  321. if (gods == 2) {
  322. $("#toast").addClass("show").find("#report").addClass("show").data("userid", userid);
  323. }
  324. })
  325. }
  326. resolve(false);
  327. })
  328. }
  329. // 阅读点赞 登录状态 请求
  330. $("#read>.good").click(function () {
  331. if (!globaldata.user) {
  332. globaldata.sgin();
  333. return false
  334. }
  335. let $i = $(this).find("i");
  336. let $span = $(this).find("span");
  337. let num = $span.text();
  338. let lock = $i.data("good");
  339. if (!lock) {
  340. $i.addClass("color");
  341. $i.data("good", true);
  342. $span.text(num * 1 + 1);
  343. } else {
  344. $i.removeClass("color");
  345. $i.data("good", false);
  346. $span.text(num * 1 - 1);
  347. }
  348. })
  349. })