components.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. // 通用数据
  2. let globaldata = {
  3. // 滚动高度
  4. scrollheight: 50,
  5. // body
  6. body: document.documentElement || document.body,
  7. // 省份
  8. province: ["全国", "北京", "天津", "河北", "山西", "内蒙古", "辽宁", "吉林", "黑龙江", "上海", "江苏", "浙江", "安徽", "福建", "江西", "山东", "河南", "湖北", "湖南", "广东", "海南", "广西", "甘肃", "陕西", "新疆", "青海", "宁夏", "重庆", "四川", "贵州", "云南", "西藏", "台湾", "澳门", "香港", "默认"]
  9. }
  10. // app 悬浮放大
  11. $(function () {
  12. $("[data-app='download']").mouseenter(function () {
  13. $(this).find("div").addClass("show")
  14. }).mouseleave(function () {
  15. $(this).find("div").removeClass("show")
  16. })
  17. })
  18. // 大屏 下拉菜单
  19. $(function () {
  20. let navitems = $("#nav>.nav-item");
  21. const move = (that, show) => {
  22. let lis = $(that).find("li"),
  23. i = $(that).find("i");
  24. ul = $(that).find("ul");
  25. if (lis.length != 0 && show) {
  26. ul.addClass("show");
  27. i.removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
  28. return false;
  29. }
  30. if (lis.length != 0 && !show) {
  31. ul.removeClass("show")
  32. i.removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
  33. return false;
  34. }
  35. return false;
  36. }
  37. for (let i = 0; i < navitems.length; i++) {
  38. $(navitems[i]).mouseenter(function () {
  39. let that = this;
  40. move(that, true)
  41. }).mouseleave(function () {
  42. let that = this;
  43. move(that, false)
  44. })
  45. }
  46. }
  47. )
  48. // 监听滚动轴
  49. $(function () {
  50. // face显示锁
  51. let lock = true;
  52. // top显示锁
  53. let locktop = false;
  54. // 滚动高度
  55. let height = globaldata.scrollheight;
  56. $("body")[0].onscroll = function () {
  57. let stop = globaldata.body.scrollTop;
  58. // console.log(stop)
  59. // 可是区域宽度;
  60. if (stop > height && !locktop) {
  61. $("#top").removeClass("noshow");
  62. locktop = true;
  63. }
  64. if (stop < height && locktop) {
  65. $("#top").addClass("noshow");
  66. locktop = false;
  67. }
  68. if ($("body")[0].clientWidth < 768) {
  69. return false;
  70. }
  71. if (stop > height && lock) {
  72. $("#face").addClass("noshow");
  73. lock = false
  74. return false;
  75. }
  76. if (stop <= height && !lock) {
  77. $("#face").removeClass("noshow");
  78. lock = true;
  79. return false;
  80. }
  81. }
  82. })
  83. // 小屏幕 下拉菜单
  84. $(function () {
  85. // 按钮开关
  86. let lock = false;
  87. const open = () => {
  88. if (!lock) {
  89. $("#nav-sm").addClass("nav-sm-show").removeClass("nav-sm-noshow");
  90. globaldata.body.addEventListener('touchmove', e =>
  91. e.preventDefault()
  92. , { passive: false })
  93. lock = true
  94. return false;
  95. }
  96. if (lock) {
  97. $("#nav-sm").addClass("nav-sm-noshow").removeClass("nav-sm-show");
  98. globaldata.body.removeEventListener('touchmove', e => e.preventDefault() = true, { passive: false })
  99. lock = false;
  100. return false;
  101. }
  102. }
  103. $('#listbutton').click(function () {
  104. open()
  105. })
  106. // 可视区域变化
  107. window.onresize = () => {
  108. let appwidth = $("body")[0].clientWidth;
  109. if (appwidth > 768) {
  110. $("#nav-sm").removeClass("nav-sm-show");
  111. lock = false;
  112. return false;
  113. } else {
  114. // face 移动端显示
  115. try {
  116. $("#face").removeClass("noshow");
  117. } catch (err) { }
  118. }
  119. // if (lock) {
  120. // $("#nav-sm").addClass("nav-sm-show");
  121. // return false;
  122. // }
  123. }
  124. })
  125. // 分享设置
  126. var shareModel = {
  127. // /**
  128. // * 分享QQ好友
  129. // * @param {[type]} title [分享标题]
  130. // * @param {[type]} url [分享url链接,默认当前页面链接]
  131. // * @param {[type]} pic [分享图片]
  132. // * @return {[type]} [description]
  133. // */
  134. shareQQ: function (url, title, pic) {
  135. var param = {
  136. url: url || window.location.href,
  137. desc: '', /*分享理由*/
  138. title: title || '', /*分享标题(可选)*/
  139. summary: '',/*分享描述(可选)*/
  140. pics: pic || '',/*分享图片(可选)*/
  141. flash: '', /*视频地址(可选)*/
  142. site: '' /*分享来源 (可选) */
  143. };
  144. var s = [];
  145. for (var i in param) {
  146. s.push(i + '=' + encodeURIComponent(param[i] || ''));
  147. }
  148. var targetUrl = "https://connect.qq.com/widget/shareqq/iframe_index.html?" + s.join('&');
  149. window.open(targetUrl, 'qq');
  150. },
  151. // /**
  152. // * 微信分享
  153. // * @return {[type]} [description]
  154. // */
  155. weixin: function () {
  156. var url = window.location.href,
  157. encodePath = encodeURIComponent(url),
  158. targetUrl = 'https://api.gaokaozhitongche.com/v1/direct?text=' + encodePath;
  159. window.open(targetUrl, 'weixin');
  160. },
  161. // /**
  162. // * 分享新浪微博
  163. // * @param {[type]} title [分享标题]
  164. // * @param {[type]} url [分享url链接,默认当前页面]
  165. // * @param {[type]} pic [分享图片]
  166. // * @return {[type]} [description]
  167. // */
  168. sinaWeiBo: function (title, url, pic) {
  169. var param = {
  170. url: url || window.location.href,
  171. type: '3',
  172. count: '1', /** 是否显示分享数,1显示(可选)*/
  173. appkey: '', /** 您申请的应用appkey,显示分享来源(可选)*/
  174. title: '', /** 分享的文字内容(可选,默认为所在页面的title)*/
  175. pic: pic || '', /**分享图片的路径(可选)*/
  176. ralateUid: '', /**关联用户的UID,分享微博会@该用户(可选)*/
  177. rnd: new Date().valueOf()
  178. }
  179. var temp = [];
  180. for (var p in param) {
  181. temp.push(p + '=' + encodeURIComponent(param[p] || ''))
  182. }
  183. var targetUrl = 'https://service.weibo.com/share/share.php?' + temp.join('&');
  184. window.open(targetUrl, 'sinaweibo');
  185. }
  186. };
  187. $(function () {
  188. $("#share").mouseenter(function () {
  189. $(this).children("ul").css("width", 'auto')
  190. }).mouseleave(function () {
  191. $(this).children("ul").css("width", '0px');
  192. })
  193. let lis = $("#share>ul>li");
  194. for (let i = 0; i < lis.length; i++) {
  195. if (i == 1) {
  196. $(lis[i]).click(function () {
  197. shareModel.shareQQ();
  198. })
  199. }
  200. if (i == 2) {
  201. var dom = $("<div>");
  202. dom.attr("id", "qrcode");
  203. $(dom).appendTo($("#share"));
  204. var qrcode = new QRCode("qrcode", {
  205. text: window.location.href,
  206. width: 100,
  207. height: 100,
  208. colorDark: "#000000",
  209. colorLight: "#ffffff",
  210. correctLevel: QRCode.CorrectLevel.H
  211. });
  212. qrcode.clear();
  213. qrcode.makeCode(window.location.href)
  214. $("#qrcode").append(
  215. `<div class="wei"><div>微信扫一扫</div><div>便可将本文分享至朋友圈</div><div>`
  216. )
  217. $(lis[i]).mouseenter(function () {
  218. $("#qrcode").show();
  219. }).mouseleave(function () {
  220. $("#qrcode").hide();
  221. })
  222. }
  223. if (i == 3) {
  224. $(lis[i]).click(function () {
  225. shareModel.sinaWeiBo();
  226. })
  227. }
  228. }
  229. })
  230. // 按钮锁
  231. $(function () {
  232. $("#top").click(function () {
  233. let dom = globaldata.body;
  234. // let top = document.documentElement.scrollTop || document.body.scrollTop;
  235. $(dom).animate({ scrollTop: 0 }, 500);
  236. })
  237. })
  238. // toast 背景事件
  239. $(function () {
  240. let dom = $("#toast>.toast-content");
  241. let style = dom.data();
  242. try {
  243. let h = style["height"] * 1 / 2;
  244. let w = style["width"] * 1 / 2;
  245. style["width"] += "px";
  246. style["height"] += "px";
  247. style["top"] = `calc(50vh - ${h}px )`;
  248. style["left"] = `calc(50vw - ${w}px )`;
  249. dom.css(style);
  250. } catch (err) { }
  251. dom.find("a").click(function () {
  252. window.location.href = $(this).attr("href")
  253. })
  254. $("#toast").click(function (e) {
  255. if (e.target.id != 'toast') return false
  256. $(this).removeClass("show");
  257. Array.prototype.slice.call($(this).find(".show")).forEach(e => {
  258. $(e).removeClass("show")
  259. })
  260. })
  261. })
  262. // 下载app
  263. $(function () {
  264. $("#download button").click(
  265. function () {
  266. window.location.href = "http://down.gaokaoapp.net";
  267. }
  268. )
  269. })
  270. // 评论区 点赞
  271. $(function () {
  272. const globaldata = {
  273. // 用户是否登录
  274. user: false,
  275. // 登录弹框
  276. sgin () {
  277. $("#toast").addClass("show").find(".msg").addClass("show").unbind("click").click(function () {
  278. window.location.href = "http://down.gaokaoapp.net"
  279. });
  280. }
  281. }
  282. // 显示区高度
  283. let ch = document.documentElement.clientHeight || document.body.clientHeight;
  284. // 实现评论区加载
  285. let lock = false;
  286. $(window).scroll(function () {
  287. if (lock) return false;
  288. // 滑动区高度
  289. let sh = document.documentElement.scrollHeight || document.body.scrollHeight;
  290. // 滑动位置
  291. let st = document.documentElement.scrollTop || document.body.scrollTop;
  292. let c = sh * 1 - ch * 1 - st * 1;
  293. if (c == 0) {
  294. lock = true;
  295. $(".comment>.loading").addClass("show")
  296. setTimeout(function (
  297. ) {
  298. $(".comment>.loading").removeClass("show");
  299. data().then(res => {
  300. if (res) {
  301. $(".comment>.nodata").addClass("show");
  302. }
  303. lock = res;
  304. });
  305. }, 2000)
  306. }
  307. })
  308. // 阅读量问题
  309. // 评论区
  310. function data () {
  311. // 请求 根据请求改变内容 唯一标识 data-userid="1" data-good="false"
  312. let com = `<div class="user" data-good="false" data-userid="1" >
  313. <div class="u-img"><img src="../imgs/qq.png" alt="" class="img"></div>
  314. <div class="u-content">
  315. <div class="u-flex">
  316. <div class="u-name">QQ官方</div>
  317. <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>
  318. </div>
  319. <div class="u-detail">
  320. 对此,广东警官学院表示,其普通高等教育(全日制)招生工作严格执行教育部的“阳光高考”规定和工作程序,不以任何形式承诺录取,不因任何理由降低标准录取。学校从未委托任何个人、中介组织或招生机构开展提前招生、高职扩招等宣
  321. </div>
  322. <div class="u-flex">
  323. <div class="u-date">2020-12-15</div>
  324. <div data-gods="2" class="u-report">举报</div>
  325. </div>
  326. </div>
  327. </div>`;
  328. return new Promise(resolve => {
  329. $("#detail").append(com);
  330. //评论点赞 登录状态 请求
  331. let lists = $("#detail>.user");
  332. // 模拟无信息加载情况
  333. if (lists.length == 10) {
  334. resolve(true)
  335. }
  336. for (let i = 0; i < lists.length; i++) {
  337. $(lists[i]).unbind("click");
  338. $(lists[i]).click(function (e) {
  339. if (!globaldata.user) {
  340. globaldata.sgin();
  341. return false
  342. }
  343. let userid = $(this).data("userid");
  344. let lock = $(this).data("good");
  345. let gods = e.target.dataset.gods;
  346. if (gods == 1) {
  347. let $i = $(this).find("i");
  348. let $span = $(this).find("span");
  349. let num = $span.text();
  350. if (!lock) {
  351. $i.addClass("color");
  352. $(this).data("good", true);
  353. $span.text(num * 1 + 1);
  354. } else {
  355. $i.removeClass("color");
  356. $(this).data("good", false);
  357. $span.text(num * 1 - 1);
  358. }
  359. return false;
  360. }
  361. if (gods == 2) {
  362. $("#toast").addClass("show").find("#report").addClass("show").data("userid", userid);
  363. }
  364. })
  365. }
  366. resolve(false);
  367. })
  368. }
  369. // 阅读点赞 登录状态 请求
  370. $("#read>.good").click(function () {
  371. if (!globaldata.user) {
  372. globaldata.sgin();
  373. return false
  374. }
  375. let $i = $(this).find("i");
  376. let $span = $(this).find("span");
  377. let num = $span.text();
  378. let lock = $i.data("good");
  379. if (!lock) {
  380. $i.addClass("color");
  381. $i.data("good", true);
  382. $span.text(num * 1 + 1);
  383. } else {
  384. $i.removeClass("color");
  385. $i.data("good", false);
  386. $span.text(num * 1 - 1);
  387. }
  388. })
  389. })
  390. // 省份
  391. $(function () {
  392. function province (data) {
  393. let str = ``;
  394. data.forEach(item => str += `<li>${item}</li>`);
  395. str = `<ul >${str}</ul>`;
  396. return str
  397. }
  398. // 底部弹出框
  399. let lis = $("[data-province='true']").append(province(globaldata.province)).find("li");
  400. Array.prototype.slice.call(lis).forEach(item => {
  401. $(item).click(function (e) {
  402. e.stopPropagation();
  403. let text = $(this).text();
  404. if (text == "默认") {
  405. $(".my-province div[data-province='true']").hide();
  406. return false;
  407. }
  408. alert("跳转:" + $(this).text())
  409. })
  410. })
  411. function province_show (e) {
  412. e.stopPropagation();
  413. $(".my-province div[data-province='true']").show().unbind("mouseleave").mouseleave(function () { $(this).hide() });
  414. }
  415. $(".my-province>span").click(province_show);
  416. $(".my-province>i").click(province_show);
  417. })
  418. // 全局添加路径解析
  419. $(function () {
  420. var r = {
  421. protocol: /([^\/]+:)\/\/(.*)/i,
  422. host: /(^[^\:\/]+)((?:\/|:|$)?.*)/,
  423. port: /\:?([^\/]*)(\/?.*)/,
  424. pathname: /([^\?#]+)(\??[^#]*)(#?.*)/
  425. };
  426. function parseUrl (url) {
  427. var tmp, res = {};
  428. res["href"] = url;
  429. for (p in r) {
  430. tmp = r[p].exec(url);
  431. res[p] = tmp[1];
  432. url = tmp[2];
  433. if (url === "") {
  434. url = "/";
  435. }
  436. if (p === "pathname") {
  437. res["pathname"] = tmp[1];
  438. res["search"] = tmp[2];
  439. res["hash"] = tmp[3];
  440. }
  441. }
  442. let param = res.search.replace('?', '').split("&");
  443. let params = {};
  444. param.forEach(item => {
  445. let arr = item.split("=");
  446. params[arr[0]] = arr[1]
  447. })
  448. res["query"] = params;
  449. return res;
  450. };
  451. window["lxd"] = {
  452. parseUrl
  453. }
  454. })
  455. // 页面内通过 .click-dom .click-href 进行业内跳转
  456. $(function () {
  457. $(".click-dom").click(function () {
  458. let top = $(".click-href").offset().top;
  459. $(window).scrollTop(top)
  460. })
  461. })
  462. // 图片观看轮播
  463. $(function () {
  464. // 获取图片
  465. let showimglist = Array.from($('.showimglist img')), imglist = [], imglistdom = $("#imglist")
  466. i = 0, size = 1;
  467. $('.showimglist img').click(function () {
  468. $("body").css({ "overflow-y": "hidden" })
  469. i = showimglist.indexOf(this);
  470. imgshow(0)
  471. imglistdom.show()
  472. })
  473. showimglist.map(item => {
  474. imglist.push($(item).data("original"));
  475. })
  476. function loop (src) {
  477. $("#imglist>div>img").attr("src", src);
  478. let newimg = new Image();
  479. newimg.src = src;
  480. newimg.onload = function (e) {
  481. let w = this.width / 2,
  482. h = this.height / 2;
  483. $("#imglist>div>img").css({ "top": `calc(50vh - ${h}px)`, "left": `calc(50vw - ${w}px)` })
  484. }
  485. }
  486. let btns = $("#imglist>div>.glyphicon");
  487. function imgshow (num) {
  488. i += num;
  489. if (i < 0) i = imglist.length - 1;
  490. if (i >= imglist.length) i = 0;
  491. loop(imglist[i]);
  492. }
  493. $(btns[0]).click(function (e) {
  494. size = 1;
  495. scale(0);
  496. imgshow(-1);
  497. });
  498. $(btns[1]).click(function (e) {
  499. size = 1;
  500. scale(0);
  501. imgshow(1);
  502. })
  503. let btnss = $("#imglist>div>span>img");
  504. function scale (num) {
  505. size += num;
  506. if (size <= 0) size = 0.5;
  507. $("#imglist>div>img").css({ "transform": `scale(${size})` })
  508. }
  509. $(btnss[0]).click(function (e) {
  510. scale(0.5);
  511. });
  512. $(btnss[1]).click(function (e) {
  513. scale(-0.5);
  514. });
  515. $(btnss[2]).click(function (e) {
  516. $("body").css({ "overflow-y": "scroll" })
  517. imglistdom.hide()
  518. });
  519. })