components.js 12 KB

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