components.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. let h = style["height"] * 1 / 2;
  243. let w = style["width"] * 1 / 2;
  244. style["width"] += "px";
  245. style["height"] += "px";
  246. style["top"] = `calc(50vh - ${h}px )`;
  247. style["left"] = `calc(50vw - ${w}px )`;
  248. dom.css(style);
  249. dom.find("a").click(function () {
  250. window.location.href = $(this).attr("href")
  251. })
  252. $("#toast").click(function (e) {
  253. if (e.target.id != 'toast') return false
  254. $(this).removeClass("show");
  255. Array.prototype.slice.call($(this).find(".show")).forEach(e => {
  256. $(e).removeClass("show")
  257. })
  258. })
  259. })
  260. // 下载app
  261. $(function () {
  262. $("#download button").click(
  263. function () {
  264. window.location.href = "http://down.gaokaoapp.net";
  265. }
  266. )
  267. })
  268. // 评论区 点赞
  269. $(function () {
  270. const globaldata = {
  271. // 用户是否登录
  272. user: false,
  273. // 登录弹框
  274. sgin () {
  275. $("#toast").addClass("show").find(".msg").addClass("show").unbind("click").click(function () {
  276. window.location.href = "http://down.gaokaoapp.net"
  277. });
  278. }
  279. }
  280. // 显示区高度
  281. let ch = document.documentElement.clientHeight || document.body.clientHeight;
  282. // 实现评论区加载
  283. let lock = false;
  284. $(window).scroll(function () {
  285. if (lock) return false;
  286. // 滑动区高度
  287. let sh = document.documentElement.scrollHeight || document.body.scrollHeight;
  288. // 滑动位置
  289. let st = document.documentElement.scrollTop || document.body.scrollTop;
  290. let c = sh * 1 - ch * 1 - st * 1;
  291. if (c == 0) {
  292. lock = true;
  293. $(".comment>.loading").addClass("show")
  294. setTimeout(function (
  295. ) {
  296. $(".comment>.loading").removeClass("show");
  297. data().then(res => {
  298. if (res) {
  299. $(".comment>.nodata").addClass("show");
  300. }
  301. lock = res;
  302. });
  303. }, 2000)
  304. }
  305. })
  306. // 阅读量问题
  307. // 评论区
  308. function data () {
  309. // 请求 根据请求改变内容 唯一标识 data-userid="1" data-good="false"
  310. let com = `<div class="user" data-good="false" data-userid="1" >
  311. <div class="u-img"><img src="../imgs/qq.png" alt="" class="img"></div>
  312. <div class="u-content">
  313. <div class="u-flex">
  314. <div class="u-name">QQ官方</div>
  315. <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>
  316. </div>
  317. <div class="u-detail">
  318. 对此,广东警官学院表示,其普通高等教育(全日制)招生工作严格执行教育部的“阳光高考”规定和工作程序,不以任何形式承诺录取,不因任何理由降低标准录取。学校从未委托任何个人、中介组织或招生机构开展提前招生、高职扩招等宣
  319. </div>
  320. <div class="u-flex">
  321. <div class="u-date">2020-12-15</div>
  322. <div data-gods="2" class="u-report">举报</div>
  323. </div>
  324. </div>
  325. </div>`;
  326. return new Promise(resolve => {
  327. $("#detail").append(com);
  328. //评论点赞 登录状态 请求
  329. let lists = $("#detail>.user");
  330. // 模拟无信息加载情况
  331. if (lists.length == 10) {
  332. resolve(true)
  333. }
  334. for (let i = 0; i < lists.length; i++) {
  335. $(lists[i]).unbind("click");
  336. $(lists[i]).click(function (e) {
  337. if (!globaldata.user) {
  338. globaldata.sgin();
  339. return false
  340. }
  341. let userid = $(this).data("userid");
  342. let lock = $(this).data("good");
  343. let gods = e.target.dataset.gods;
  344. if (gods == 1) {
  345. let $i = $(this).find("i");
  346. let $span = $(this).find("span");
  347. let num = $span.text();
  348. if (!lock) {
  349. $i.addClass("color");
  350. $(this).data("good", true);
  351. $span.text(num * 1 + 1);
  352. } else {
  353. $i.removeClass("color");
  354. $(this).data("good", false);
  355. $span.text(num * 1 - 1);
  356. }
  357. return false;
  358. }
  359. if (gods == 2) {
  360. $("#toast").addClass("show").find("#report").addClass("show").data("userid", userid);
  361. }
  362. })
  363. }
  364. resolve(false);
  365. })
  366. }
  367. // 阅读点赞 登录状态 请求
  368. $("#read>.good").click(function () {
  369. if (!globaldata.user) {
  370. globaldata.sgin();
  371. return false
  372. }
  373. let $i = $(this).find("i");
  374. let $span = $(this).find("span");
  375. let num = $span.text();
  376. let lock = $i.data("good");
  377. if (!lock) {
  378. $i.addClass("color");
  379. $i.data("good", true);
  380. $span.text(num * 1 + 1);
  381. } else {
  382. $i.removeClass("color");
  383. $i.data("good", false);
  384. $span.text(num * 1 - 1);
  385. }
  386. })
  387. })
  388. // 省份
  389. $(function () {
  390. function province (data) {
  391. let str = ``;
  392. data.forEach(item => str += `<li>${item}</li>`);
  393. str = `<ul >${str}</ul>`;
  394. return str
  395. }
  396. // 底部弹出框
  397. let lis = $("[data-province='true']").append(province(globaldata.province)).find("li");
  398. Array.prototype.slice.call(lis).forEach(item => {
  399. $(item).click(function (e) {
  400. e.stopPropagation();
  401. let text = $(this).text();
  402. if (text == "默认") {
  403. $(".my-province div[data-province='true']").hide();
  404. return false;
  405. }
  406. alert("跳转:" + $(this).text())
  407. })
  408. })
  409. function province_show (e) {
  410. e.stopPropagation();
  411. $(".my-province div[data-province='true']").show().unbind("mouseleave").mouseleave(function () { $(this).hide() });
  412. }
  413. $(".my-province>span").click(province_show);
  414. $(".my-province>i").click(province_show);
  415. })
  416. // 全局添加路径解析
  417. $(function () {
  418. var r = {
  419. protocol: /([^\/]+:)\/\/(.*)/i,
  420. host: /(^[^\:\/]+)((?:\/|:|$)?.*)/,
  421. port: /\:?([^\/]*)(\/?.*)/,
  422. pathname: /([^\?#]+)(\??[^#]*)(#?.*)/
  423. };
  424. function parseUrl (url) {
  425. var tmp, res = {};
  426. res["href"] = url;
  427. for (p in r) {
  428. tmp = r[p].exec(url);
  429. res[p] = tmp[1];
  430. url = tmp[2];
  431. if (url === "") {
  432. url = "/";
  433. }
  434. if (p === "pathname") {
  435. res["pathname"] = tmp[1];
  436. res["search"] = tmp[2];
  437. res["hash"] = tmp[3];
  438. }
  439. }
  440. let param = res.search.replace('?', '').split("&");
  441. let params = {};
  442. param.forEach(item => {
  443. let arr = item.split("=");
  444. params[arr[0]] = arr[1]
  445. })
  446. res["query"] = params;
  447. return res;
  448. };
  449. window["lxd"] = {
  450. parseUrl
  451. }
  452. })
  453. // 页面内通过 .click-dom .click-href 进行业内跳转
  454. $(function () {
  455. $(".click-dom").click(function () {
  456. let top = $(".click-href").offset().top;
  457. $(window).scrollTop(top)
  458. })
  459. })