components.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. // 通用数据
  2. let globaldata = {
  3. // 滚动高度
  4. scrollheight: 50,
  5. // body
  6. body: document.documentElement || document.body,
  7. // 省份
  8. province: ["全国", "北京", "天津", "河北", "山西", "内蒙古", "辽宁", "吉林", "黑龙江", "上海", "江苏", "浙江", "安徽", "福建", "江西", "山东", "河南", "湖北", "湖南", "广东", "海南", "广西", "甘肃", "陕西", "新疆", "青海", "宁夏", "重庆", "四川", "贵州", "云南", "西藏", "台湾", "澳门", "香港", "默认"]
  9. }
  10. // 大屏 下拉菜单
  11. $(
  12. function () {
  13. let navitems = $("#nav>.nav-item");
  14. const move = (that, show) => {
  15. let lis = $(that).find("li"),
  16. i = $(that).find("i");
  17. ul = $(that).find("ul");
  18. if (lis.length != 0 && show) {
  19. ul.addClass("show");
  20. i.removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
  21. return false;
  22. }
  23. if (lis.length != 0 && !show) {
  24. ul.removeClass("show")
  25. i.removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
  26. return false;
  27. }
  28. return false;
  29. }
  30. for (let i = 0; i < navitems.length; i++) {
  31. $(navitems[i]).mouseenter(function () {
  32. let that = this;
  33. move(that, true)
  34. }).mouseleave(function () {
  35. let that = this;
  36. move(that, false)
  37. })
  38. }
  39. }
  40. )
  41. // 监听滚动轴
  42. $(function () {
  43. // face显示锁
  44. let lock = true;
  45. // top显示锁
  46. let locktop = false;
  47. // 滚动高度
  48. let height = globaldata.scrollheight;
  49. $("body")[0].onscroll = function () {
  50. let stop = globaldata.body.scrollTop;
  51. // console.log(stop)
  52. // 可是区域宽度;
  53. if (stop > height && !locktop) {
  54. $("#top").removeClass("noshow");
  55. locktop = true;
  56. }
  57. if (stop < height && locktop) {
  58. $("#top").addClass("noshow");
  59. locktop = false;
  60. }
  61. if ($("body")[0].clientWidth < 768) {
  62. return false;
  63. }
  64. if (stop > height && lock) {
  65. $("#face").addClass("noshow");
  66. lock = false
  67. return false;
  68. }
  69. if (stop <= height && !lock) {
  70. $("#face").removeClass("noshow");
  71. lock = true;
  72. return false;
  73. }
  74. }
  75. })
  76. // 小屏幕 下拉菜单
  77. $(function () {
  78. // 按钮开关
  79. let lock = false;
  80. const open = () => {
  81. if (!lock) {
  82. $("#nav-sm").addClass("nav-sm-show").removeClass("nav-sm-noshow");
  83. globaldata.body.addEventListener('touchmove', e =>
  84. e.preventDefault()
  85. , { passive: false })
  86. lock = true
  87. return false;
  88. }
  89. if (lock) {
  90. $("#nav-sm").addClass("nav-sm-noshow").removeClass("nav-sm-show");
  91. globaldata.body.removeEventListener('touchmove', e => e.preventDefault() = true, { passive: false })
  92. lock = false;
  93. return false;
  94. }
  95. }
  96. $('#listbutton').click(function () {
  97. open()
  98. })
  99. // 可视区域变化
  100. window.onresize = () => {
  101. let appwidth = $("body")[0].clientWidth;
  102. if (appwidth > 768) {
  103. $("#nav-sm").removeClass("nav-sm-show");
  104. lock = false;
  105. return false;
  106. } else {
  107. // face 移动端显示
  108. try {
  109. $("#face").removeClass("noshow");
  110. } catch (err) { }
  111. }
  112. // if (lock) {
  113. // $("#nav-sm").addClass("nav-sm-show");
  114. // return false;
  115. // }
  116. }
  117. })
  118. // 分享设置
  119. var shareModel = {
  120. // /**
  121. // * 分享QQ好友
  122. // * @param {[type]} title [分享标题]
  123. // * @param {[type]} url [分享url链接,默认当前页面链接]
  124. // * @param {[type]} pic [分享图片]
  125. // * @return {[type]} [description]
  126. // */
  127. shareQQ: function (url, title, pic) {
  128. var param = {
  129. url: url || window.location.href,
  130. desc: '', /*分享理由*/
  131. title: title || '', /*分享标题(可选)*/
  132. summary: '',/*分享描述(可选)*/
  133. pics: pic || '',/*分享图片(可选)*/
  134. flash: '', /*视频地址(可选)*/
  135. site: '' /*分享来源 (可选) */
  136. };
  137. var s = [];
  138. for (var i in param) {
  139. s.push(i + '=' + encodeURIComponent(param[i] || ''));
  140. }
  141. var targetUrl = "https://connect.qq.com/widget/shareqq/iframe_index.html?" + s.join('&');
  142. window.open(targetUrl, 'qq');
  143. },
  144. // /**
  145. // * 微信分享
  146. // * @return {[type]} [description]
  147. // */
  148. weixin: function () {
  149. var url = window.location.href,
  150. encodePath = encodeURIComponent(url),
  151. targetUrl = 'https://api.gaokaozhitongche.com/v1/direct?text=' + encodePath;
  152. window.open(targetUrl, 'weixin');
  153. },
  154. // /**
  155. // * 分享新浪微博
  156. // * @param {[type]} title [分享标题]
  157. // * @param {[type]} url [分享url链接,默认当前页面]
  158. // * @param {[type]} pic [分享图片]
  159. // * @return {[type]} [description]
  160. // */
  161. sinaWeiBo: function (title, url, pic) {
  162. var param = {
  163. url: url || window.location.href,
  164. type: '3',
  165. count: '1', /** 是否显示分享数,1显示(可选)*/
  166. appkey: '', /** 您申请的应用appkey,显示分享来源(可选)*/
  167. title: '', /** 分享的文字内容(可选,默认为所在页面的title)*/
  168. pic: pic || '', /**分享图片的路径(可选)*/
  169. ralateUid: '', /**关联用户的UID,分享微博会@该用户(可选)*/
  170. rnd: new Date().valueOf()
  171. }
  172. var temp = [];
  173. for (var p in param) {
  174. temp.push(p + '=' + encodeURIComponent(param[p] || ''))
  175. }
  176. var targetUrl = 'https://service.weibo.com/share/share.php?' + temp.join('&');
  177. window.open(targetUrl, 'sinaweibo');
  178. }
  179. };
  180. $(function () {
  181. $("#share").mouseenter(function () {
  182. $(this).children("ul").css("width", 'auto')
  183. }).mouseleave(function () {
  184. $(this).children("ul").css("width", '0px')
  185. })
  186. let lis = $("#share>ul>li");
  187. for (let i = 0; i < lis.length; i++) {
  188. if (i == 1) {
  189. $(lis[i]).click(function () {
  190. shareModel.shareQQ();
  191. })
  192. }
  193. // if (i == 2) {
  194. // $(lis[i]).click(function () {
  195. // shareModel.weixin(url = "https://app.gaokaozhitongche.com/");
  196. // })
  197. // }
  198. if (i == 2) {
  199. $(lis[i]).click(function () {
  200. console.log(1)
  201. shareModel.sinaWeiBo();
  202. })
  203. }
  204. }
  205. })
  206. // 按钮锁
  207. $(function () {
  208. $("#top").click(function () {
  209. let dom = globaldata.body;
  210. // let top = document.documentElement.scrollTop || document.body.scrollTop;
  211. $(dom).animate({ scrollTop: 0 }, 500);
  212. })
  213. })
  214. // toast 背景事件
  215. $(function () {
  216. $("#toast").click(function (e) {
  217. if (e.target.id != 'toast') return false
  218. $(this).removeClass("show");
  219. Array.prototype.slice.call($(this).find(".show")).forEach(e => {
  220. $(e).removeClass("show")
  221. })
  222. })
  223. })
  224. // 下载app
  225. $(function () {
  226. $("#download button").click(
  227. function () {
  228. window.location.href = "http://down.gaokaoapp.net";
  229. }
  230. )
  231. })
  232. // 评论区 点赞
  233. $(function () {
  234. const globaldata = {
  235. // 用户是否登录
  236. user: false,
  237. // 登录弹框
  238. sgin () {
  239. $("#toast").addClass("show").find(".msg").addClass("show").unbind("click").click(function () {
  240. window.location.href = "http://down.gaokaoapp.net"
  241. });
  242. }
  243. }
  244. // 显示区高度
  245. let ch = document.documentElement.clientHeight || document.body.clientHeight;
  246. // 实现评论区加载
  247. let lock = false;
  248. $(window).scroll(function () {
  249. if (lock) return false;
  250. // 滑动区高度
  251. let sh = document.documentElement.scrollHeight || document.body.scrollHeight;
  252. // 滑动位置
  253. let st = document.documentElement.scrollTop || document.body.scrollTop;
  254. let c = sh * 1 - ch * 1 - st * 1;
  255. if (c == 0) {
  256. lock = true;
  257. $(".comment>.loading").addClass("show")
  258. setTimeout(function (
  259. ) {
  260. $(".comment>.loading").removeClass("show");
  261. data().then(res => {
  262. if (res) {
  263. $(".comment>.nodata").addClass("show");
  264. }
  265. lock = res;
  266. });
  267. }, 2000)
  268. }
  269. })
  270. // 阅读量问题
  271. // 评论区
  272. function data () {
  273. // 请求 根据请求改变内容 唯一标识 data-userid="1" data-good="false"
  274. let com = `<div class="user" data-good="false" data-userid="1" >
  275. <div class="u-img"><img src="../imgs/qq.png" alt="" class="img"></div>
  276. <div class="u-content">
  277. <div class="u-flex">
  278. <div class="u-name">QQ官方</div>
  279. <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>
  280. </div>
  281. <div class="u-detail">
  282. 对此,广东警官学院表示,其普通高等教育(全日制)招生工作严格执行教育部的“阳光高考”规定和工作程序,不以任何形式承诺录取,不因任何理由降低标准录取。学校从未委托任何个人、中介组织或招生机构开展提前招生、高职扩招等宣
  283. </div>
  284. <div class="u-flex">
  285. <div class="u-date">2020-12-15</div>
  286. <div data-gods="2" class="u-report">举报</div>
  287. </div>
  288. </div>
  289. </div>`;
  290. return new Promise(resolve => {
  291. $("#detail").append(com);
  292. //评论点赞 登录状态 请求
  293. let lists = $("#detail>.user");
  294. // 模拟无信息加载情况
  295. if (lists.length == 10) {
  296. resolve(true)
  297. }
  298. for (let i = 0; i < lists.length; i++) {
  299. $(lists[i]).unbind("click");
  300. $(lists[i]).click(function (e) {
  301. if (!globaldata.user) {
  302. globaldata.sgin();
  303. return false
  304. }
  305. let userid = $(this).data("userid");
  306. let lock = $(this).data("good");
  307. let gods = e.target.dataset.gods;
  308. if (gods == 1) {
  309. let $i = $(this).find("i");
  310. let $span = $(this).find("span");
  311. let num = $span.text();
  312. if (!lock) {
  313. $i.addClass("color");
  314. $(this).data("good", true);
  315. $span.text(num * 1 + 1);
  316. } else {
  317. $i.removeClass("color");
  318. $(this).data("good", false);
  319. $span.text(num * 1 - 1);
  320. }
  321. return false;
  322. }
  323. if (gods == 2) {
  324. $("#toast").addClass("show").find("#report").addClass("show").data("userid", userid);
  325. }
  326. })
  327. }
  328. resolve(false);
  329. })
  330. }
  331. // 阅读点赞 登录状态 请求
  332. $("#read>.good").click(function () {
  333. if (!globaldata.user) {
  334. globaldata.sgin();
  335. return false
  336. }
  337. let $i = $(this).find("i");
  338. let $span = $(this).find("span");
  339. let num = $span.text();
  340. let lock = $i.data("good");
  341. if (!lock) {
  342. $i.addClass("color");
  343. $i.data("good", true);
  344. $span.text(num * 1 + 1);
  345. } else {
  346. $i.removeClass("color");
  347. $i.data("good", false);
  348. $span.text(num * 1 - 1);
  349. }
  350. })
  351. })
  352. // 省份
  353. $(function () {
  354. function province (data) {
  355. let str = ``;
  356. data.forEach(item => str += `<li>${item}</li>`);
  357. str = `<ul >${str}</ul>`;
  358. return str
  359. }
  360. // 底部弹出框
  361. let lis = $("[data-province='true']").append(province(globaldata.province)).find("li");
  362. Array.prototype.slice.call(lis).forEach(item => {
  363. $(item).click(function () {
  364. let text = $(this).text();
  365. if (text == "默认") {
  366. $(".my-province div[data-province='true']").hide();
  367. return false;
  368. }
  369. alert("跳转:" + $(this).text())
  370. })
  371. })
  372. function province_show () {
  373. $(".my-province div[data-province='true']").show().unbind("mouseleave").mouseleave(function () { $(this).hide() });
  374. }
  375. $(".my-province>span").click(province_show);
  376. $(".my-province>i").click(province_show);
  377. })