components.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. $("#qrcode").hide();
  193. })
  194. let lis = $("#share>ul>li");
  195. for (let i = 0; i < lis.length; i++) {
  196. if (i == 1) {
  197. $(lis[i]).click(function () {
  198. shareModel.shareQQ();
  199. })
  200. }
  201. if (i == 2) {
  202. var dom = $("<div>");
  203. dom.attr("id", "qrcode");
  204. $(dom).appendTo($("#share"));
  205. var qrcode = new QRCode("qrcode", {
  206. text: window.location.href,
  207. width: 128,
  208. height: 128,
  209. colorDark: "#000000",
  210. colorLight: "#ffffff",
  211. correctLevel: QRCode.CorrectLevel.H
  212. });
  213. qrcode.clear();
  214. qrcode.makeCode(window.location.href)
  215. $(lis[i]).click(function () {
  216. $("#qrcode").show();
  217. })
  218. }
  219. if (i == 3) {
  220. $(lis[i]).click(function () {
  221. shareModel.sinaWeiBo();
  222. })
  223. }
  224. }
  225. })
  226. // 按钮锁
  227. $(function () {
  228. $("#top").click(function () {
  229. let dom = globaldata.body;
  230. // let top = document.documentElement.scrollTop || document.body.scrollTop;
  231. $(dom).animate({ scrollTop: 0 }, 500);
  232. })
  233. })
  234. // toast 背景事件
  235. $(function () {
  236. $("#toast").click(function (e) {
  237. if (e.target.id != 'toast') return false
  238. $(this).removeClass("show");
  239. Array.prototype.slice.call($(this).find(".show")).forEach(e => {
  240. $(e).removeClass("show")
  241. })
  242. })
  243. })
  244. // 下载app
  245. $(function () {
  246. $("#download button").click(
  247. function () {
  248. window.location.href = "http://down.gaokaoapp.net";
  249. }
  250. )
  251. })
  252. // 评论区 点赞
  253. $(function () {
  254. const globaldata = {
  255. // 用户是否登录
  256. user: false,
  257. // 登录弹框
  258. sgin () {
  259. $("#toast").addClass("show").find(".msg").addClass("show").unbind("click").click(function () {
  260. window.location.href = "http://down.gaokaoapp.net"
  261. });
  262. }
  263. }
  264. // 显示区高度
  265. let ch = document.documentElement.clientHeight || document.body.clientHeight;
  266. // 实现评论区加载
  267. let lock = false;
  268. $(window).scroll(function () {
  269. if (lock) return false;
  270. // 滑动区高度
  271. let sh = document.documentElement.scrollHeight || document.body.scrollHeight;
  272. // 滑动位置
  273. let st = document.documentElement.scrollTop || document.body.scrollTop;
  274. let c = sh * 1 - ch * 1 - st * 1;
  275. if (c == 0) {
  276. lock = true;
  277. $(".comment>.loading").addClass("show")
  278. setTimeout(function (
  279. ) {
  280. $(".comment>.loading").removeClass("show");
  281. data().then(res => {
  282. if (res) {
  283. $(".comment>.nodata").addClass("show");
  284. }
  285. lock = res;
  286. });
  287. }, 2000)
  288. }
  289. })
  290. // 阅读量问题
  291. // 评论区
  292. function data () {
  293. // 请求 根据请求改变内容 唯一标识 data-userid="1" data-good="false"
  294. let com = `<div class="user" data-good="false" data-userid="1" >
  295. <div class="u-img"><img src="../imgs/qq.png" alt="" class="img"></div>
  296. <div class="u-content">
  297. <div class="u-flex">
  298. <div class="u-name">QQ官方</div>
  299. <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>
  300. </div>
  301. <div class="u-detail">
  302. 对此,广东警官学院表示,其普通高等教育(全日制)招生工作严格执行教育部的“阳光高考”规定和工作程序,不以任何形式承诺录取,不因任何理由降低标准录取。学校从未委托任何个人、中介组织或招生机构开展提前招生、高职扩招等宣
  303. </div>
  304. <div class="u-flex">
  305. <div class="u-date">2020-12-15</div>
  306. <div data-gods="2" class="u-report">举报</div>
  307. </div>
  308. </div>
  309. </div>`;
  310. return new Promise(resolve => {
  311. $("#detail").append(com);
  312. //评论点赞 登录状态 请求
  313. let lists = $("#detail>.user");
  314. // 模拟无信息加载情况
  315. if (lists.length == 10) {
  316. resolve(true)
  317. }
  318. for (let i = 0; i < lists.length; i++) {
  319. $(lists[i]).unbind("click");
  320. $(lists[i]).click(function (e) {
  321. if (!globaldata.user) {
  322. globaldata.sgin();
  323. return false
  324. }
  325. let userid = $(this).data("userid");
  326. let lock = $(this).data("good");
  327. let gods = e.target.dataset.gods;
  328. if (gods == 1) {
  329. let $i = $(this).find("i");
  330. let $span = $(this).find("span");
  331. let num = $span.text();
  332. if (!lock) {
  333. $i.addClass("color");
  334. $(this).data("good", true);
  335. $span.text(num * 1 + 1);
  336. } else {
  337. $i.removeClass("color");
  338. $(this).data("good", false);
  339. $span.text(num * 1 - 1);
  340. }
  341. return false;
  342. }
  343. if (gods == 2) {
  344. $("#toast").addClass("show").find("#report").addClass("show").data("userid", userid);
  345. }
  346. })
  347. }
  348. resolve(false);
  349. })
  350. }
  351. // 阅读点赞 登录状态 请求
  352. $("#read>.good").click(function () {
  353. if (!globaldata.user) {
  354. globaldata.sgin();
  355. return false
  356. }
  357. let $i = $(this).find("i");
  358. let $span = $(this).find("span");
  359. let num = $span.text();
  360. let lock = $i.data("good");
  361. if (!lock) {
  362. $i.addClass("color");
  363. $i.data("good", true);
  364. $span.text(num * 1 + 1);
  365. } else {
  366. $i.removeClass("color");
  367. $i.data("good", false);
  368. $span.text(num * 1 - 1);
  369. }
  370. })
  371. })
  372. // 省份
  373. $(function () {
  374. function province (data) {
  375. let str = ``;
  376. data.forEach(item => str += `<li>${item}</li>`);
  377. str = `<ul >${str}</ul>`;
  378. return str
  379. }
  380. // 底部弹出框
  381. let lis = $("[data-province='true']").append(province(globaldata.province)).find("li");
  382. Array.prototype.slice.call(lis).forEach(item => {
  383. $(item).click(function () {
  384. let text = $(this).text();
  385. if (text == "默认") {
  386. $(".my-province div[data-province='true']").hide();
  387. return false;
  388. }
  389. alert("跳转:" + $(this).text())
  390. })
  391. })
  392. function province_show () {
  393. $(".my-province div[data-province='true']").show().unbind("mouseleave").mouseleave(function () { $(this).hide() });
  394. }
  395. $(".my-province>span").click(province_show);
  396. $(".my-province>i").click(province_show);
  397. })