components.js 13 KB

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