暫無描述

fund_h5_api.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. var token = '';
  2. var tid = '';
  3. var returnUrl = '';
  4. var cityInfo = '';
  5. var retrievePwd = '';
  6. var qs = parseQueryString(window.location.href);
  7. var httpStr=location.href.substr(0,location.href.indexOf("?") + 1); //str得到?之前的字符串
  8. $().ready(function() {
  9. if (qs.returnUrl) {
  10. returnUrl = qs.returnUrl;
  11. }
  12. if (qs.token) {
  13. token = qs.token;
  14. } else {
  15. showMsg('未提供token!')
  16. }
  17. if (qs.name && qs.code) {
  18. $('.city-name').text(qs.name).attr('data-code', qs.code);
  19. }
  20. httpStr += "returnUrl=" + returnUrl;
  21. httpStr = encodeURIComponent(httpStr)
  22. console.log(httpStr)
  23. getLoginInfo();
  24. //头部切换公积金类型
  25. switchingType();
  26. });
  27. //头部切换公积金类型
  28. function switchingType() {
  29. var btn = $("nav p");
  30. btn.click(function () {
  31. console.log(cityInfo)
  32. if(cityInfo !='' && cityInfo){
  33. window.location.href = './typeChoice.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : '') + '&httpStr=' + httpStr;
  34. }else{
  35. showMsg('获取城市信息失败:' + cityInfo.region + '公积金查询');
  36. }
  37. })
  38. }
  39. /**
  40. * [showMsg 提示各种错误信息,3s后消失]
  41. */
  42. function showMsg(msg) {
  43. var msgBox = $('.alert-info');
  44. msgBox.children('p').text(msg);
  45. msgBox.show();
  46. setTimeout(function() {
  47. msgBox.hide();
  48. }, 3000);
  49. }
  50. /**
  51. * [showDialog 弹窗提示,传不同的参数提示不同的内容以及按钮的内容和点击之后的作用]
  52. * failed 任务失败,点击关闭弹窗
  53. * maintain 当前城市维护中,点击关闭弹窗
  54. * timeout token过期,点击关闭页面
  55. */
  56. function showDialog(type) {
  57. var mask = $('.mask');
  58. mask.show();
  59. $('.dialog-wrapper input').val('确定');
  60. $('.dialog-wrapper div').hide();
  61. if (type === 'failed') {
  62. $('.dialog-failed').show();
  63. $('.mask').addClass('bg-white').siblings().hide();
  64. } else if (type === 'maintain') {
  65. $('.dialog-maintain').show();
  66. } else if (type === 'timeout') {
  67. $('.dialog-timeout').show();
  68. $('.dialog-wrapper input').val('关闭').click(function() {
  69. redirectToFailedReturnUrl(tid, 'failed', 1020, '无效的token, 会话不存在或已过期');
  70. })
  71. } else if (type === 'forget') {
  72. var html = '如果您忘记密码,需前往' + qs.name+ '公积金官网<br>重置密码'
  73. $('.dialog-forget').show();
  74. $('.dialog-forget').find('p').html(html)
  75. $('.dialog-wrapper input').val('立即前往').click(function() {
  76. tips.find(function(item, index) {
  77. if(item.region == cityInfo.region){
  78. if(item.URL.password){
  79. retrievePwd = item.URL.password;
  80. // window.location.href=retrievePwd;
  81. window.webkit.messageHandlers.OutPushMessageHandler.postMessage({'name':qs.name,'url':retrievePwd});
  82. }else{
  83. retrievePwd = item.URL.web;
  84. // window.location.href=retrievePwd;
  85. window.webkit.messageHandlers.OutPushMessageHandler.postMessage({'name':qs.name,'url':retrievePwd});
  86. }
  87. }
  88. })
  89. })
  90. }
  91. }
  92. /**
  93. * [enableCommitButton 启用/禁用提交按钮]
  94. * @param {Boolean} isEnableButton [是否启用提交按钮]
  95. */
  96. function enableCommitButton(isEnableButton) {
  97. var commitButton = $('#submitButton');
  98. if (isEnableButton) {
  99. commitButton.attr('disabled', false).removeClass('disable-commit').addClass('enable-commit');
  100. } else {
  101. commitButton.attr('disabled', true).removeClass('enable-commit').addClass('disable-commit');
  102. }
  103. }
  104. /**
  105. * [isInputReady 检查参数是否输入完毕]
  106. * @return {Boolean} [参数是否输入完毕]
  107. */
  108. function isInputReady() {
  109. var isInputReady = true;
  110. var activeID = $('.tab-tab-active').attr('data-id');
  111. $('.tab-content [data-id="' + activeID + '"]')
  112. .find('input')
  113. .each(
  114. function(index, item) {
  115. if ($(item).val().trim() === '') {
  116. isInputReady = false;
  117. }
  118. if (!$('.check').hasClass('check-active')) {
  119. isInputReady = false;
  120. }
  121. })
  122. return isInputReady;
  123. }
  124. /**
  125. * [initEvent 初始化各种事件]
  126. */
  127. function initEvent() {
  128. var tabs = $('.tab-tab');
  129. var activeID = $('.tab-tab-active').attr('data-id');
  130. // tab页切换
  131. tabs.click(function(event) {
  132. var currItem = $(this);
  133. var currId = currItem.attr('data-id');
  134. $('.tab-tab[data-id="' + currId + '"]').addClass('tab-tab-active').siblings().removeClass('tab-tab-active');
  135. $('.tab-content div[data-id=' + currId + ']').show().siblings().hide();
  136. enableCommitButton(isInputReady());
  137. })
  138. // 监测用户输入来设置提交按钮的状态
  139. $('.tab-content').on('keyup', function() {
  140. enableCommitButton(isInputReady());
  141. })
  142. // 确定按钮点击事件
  143. $('#closeMask').click(function(event) {
  144. $('.mask').removeClass('bg-white').hide().siblings().show();
  145. $('#tid').hide();
  146. $('.alert-info').hide();
  147. $('.loading-wrapper').hide();
  148. })
  149. // 解析协议checkBox选中/取消选中事件
  150. $('.check').click(function() {
  151. var currentItem = $(this);
  152. if (currentItem.hasClass('check-active')) {
  153. enableCommitButton(false);
  154. currentItem.removeClass('check-active');
  155. } else {
  156. currentItem.addClass('check-active');
  157. enableCommitButton(isInputReady());
  158. }
  159. })
  160. // 提交按钮点击事件
  161. $('#submitButton').click(function() {
  162. if (isInputValid()) {
  163. submitTask();
  164. }
  165. });
  166. // 导航栏左上角退出H5的点击事件
  167. $('#back').click(function() {
  168. // redirectToFailedReturnUrl(tid, 'failed', 1020, '退出公积金查询页');
  169. // window.history.go(-1)
  170. window.webkit.messageHandlers.PopRootMessageHandler.postMessage({name:"1"});
  171. })
  172. }
  173. /**
  174. * [getLoginInfo 获取城市登录信息]
  175. */
  176. function getLoginInfo() {
  177. var regionCode = $('.city-name').attr('data-code');
  178. $.ajax({
  179. type: "GET",
  180. url: BASEURL + 'city_list?type=fund&token=' + token + '&regionCode=' + regionCode + '&time=' + Math.round(Date.now() / 1000),
  181. // url: '../../city_list?type=fund&token=' + token + '&regionCode=' + regionCode + '&time=' + Math.round(Date.now() / 1000),
  182. contentType: 'application/json;charset=utf-8',
  183. success: function(data) {
  184. cityInfo = data;
  185. console.log('data')
  186. console.log(data)
  187. return renderLoginInfo(data);
  188. },
  189. error: function(err) {
  190. // return showMsg('获取城市信息失败:' + JSON.stringify(err));
  191. return showMsg('获取城市信息失败:' + qs.name + '公积金查询');
  192. }
  193. });
  194. }
  195. /**
  196. * [renderLoginInfo 渲染城市登录信息]
  197. * @param {[type]} cityInfo [城市登录信息]
  198. */
  199. function renderLoginInfo(cityInfo) {
  200. var tabWrapper = $('.tab-tab-wrapper');
  201. var tabConWrapper = $('.tab-content');
  202. var tabsHtmlStr = '';
  203. var tabConHtmlStr = '';
  204. $('.city-name').text(cityInfo.region).attr('data-code', cityInfo.regionCode);
  205. // $('.choose-city a').attr('href', './choose_city.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : ''));
  206. $('nav span a').attr('href', './choose_city.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : ''));
  207. $('.obtainPwd a').attr('href', './queryHelp.html?name=' + cityInfo.region + '&code=' + cityInfo.regionCode + (token ? ('&token=' + token) : '') + '&httpStr=' + httpStr);
  208. for (var index in cityInfo.loginTypes) {
  209. var loginType = cityInfo.loginTypes[index];
  210. if (index === '0') {
  211. tabsHtmlStr += '<div class="tab-tab tab-tab-active" data-id ="' + loginType.loginTypeId + '"><p class="tab-title">' + loginType.loginLabel + '</p><i class="hr-active"></i></div>';
  212. tabConHtmlStr += '<div data-id="' + loginType.loginTypeId + '" style="display:block">';
  213. } else {
  214. tabsHtmlStr += '<div class="tab-tab" data-id ="' + loginType.loginTypeId + '"><p class="tab-title">' + loginType.loginLabel + '</p><i class="hr-active"></i></div>';
  215. tabConHtmlStr += '<div data-id="' + loginType.loginTypeId + '" style="display:none">';
  216. }
  217. for (var loginField of loginType.loginFields) {
  218. var type = '';
  219. var placeStr = '';
  220. if (loginField.name.includes('联名卡')) {
  221. placeStr = '请输入公积金联名卡号';
  222. } else if (loginField.name.includes('身份证')) {
  223. placeStr = '首次查询请选择联名卡号';
  224. } else if (loginField.name.includes('密码')) {
  225. placeStr = '请输入密码';
  226. type = 'password';
  227. }
  228. if(loginField.name.includes('密码')){
  229. tabConHtmlStr += '<div class="input-wrapper inputForget" ><label for="">' + loginField.name + ':</label><input id="' + loginField.code + '" type="' + type + '" placeholder="' + placeStr + '"><div class="forget" onclick="forgetEvent()">忘记密码</div></div>';
  230. }else{
  231. tabConHtmlStr += '<div class="input-wrapper" ><label for="">' + loginField.name + ':</label><input id="' + loginField.code + '" type="' + type + '" placeholder="' + placeStr + '"></div>';
  232. }
  233. }
  234. tabConHtmlStr += '</div>';
  235. }
  236. tabWrapper.html(tabsHtmlStr);
  237. tabConWrapper.html(tabConHtmlStr);
  238. renderTips($('.city-name').text());
  239. initEvent(); // 各种事件绑定
  240. checkToken();
  241. }
  242. //点击忘记密码按钮
  243. function forgetEvent () {
  244. showDialog('forget')
  245. }
  246. /**
  247. * [isInputValid 校验输入信息是否合法]
  248. * @return {Boolean} [输入信息是否合法]
  249. */
  250. function isInputValid() {
  251. var isInputValid = true;
  252. var activeID = $('.tab-tab-active').attr('data-id');
  253. $('.tab-content [data-id="' + activeID + '"]')
  254. .find('input')
  255. .each(
  256. function(index, item) {
  257. var currentEle = $(item);
  258. // 通过label标签里面的文本来判断输入项的类型
  259. // 例如:
  260. // 身份证号:
  261. var labelText = currentEle.parent().find('label').text().replace(':', '');
  262. var value = currentEle.val();
  263. var reg = null;
  264. if (labelText && labelText.includes('身份证')) {
  265. reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/;
  266. if (!reg.test(value)) {
  267. showMsg('身份证输入格式不正确');
  268. isInputValid = false;
  269. return false;
  270. }
  271. }
  272. if (labelText && (labelText.includes('电话') || labelText.includes('手机'))) {
  273. reg = /^1[3456879]\d{9}$/;
  274. if (!reg.test(value)) {
  275. showMsg('电话(手机)号码输入格式不正确')
  276. isInputValid = false;
  277. return false;
  278. }
  279. }
  280. if (labelText && labelText.includes('公积金')) {
  281. reg = /^\d+$/;
  282. if (!reg.test(value)) {
  283. showMsg('公积金账号输入格式不正确')
  284. isInputValid = false;
  285. return false;
  286. }
  287. }
  288. if (labelText && labelText.includes('联名卡')) {
  289. reg = /^\d+$/;
  290. if (!reg.test(value)) {
  291. showMsg('联名卡输入格式不正确')
  292. isInputValid = false;
  293. return false;
  294. }
  295. }
  296. })
  297. return isInputValid;
  298. }
  299. /**
  300. * [checkToken 校验token信息]
  301. */
  302. function checkToken() {
  303. var getTokenInfo = $.ajax({
  304. type: 'GET',
  305. url: BASEURL + 'token?token=' + token + '&time=' + Math.round(Date.now() / 1000),
  306. // url: '../../token?token=' + token + '&time=' + Math.round(Date.now() / 1000),
  307. timeout: 30000,
  308. contentType: 'application/json;charset=utf-8'
  309. });
  310. getTokenInfo.done(function(data) {
  311. if (data.returnUrl && !returnUrl) {
  312. window.sessionStorage.isTokenValid = true;
  313. returnUrl = data.returnUrl;
  314. }
  315. if (data.appName) {
  316. var agreementLink = $('.agreement-wrapper a');
  317. agreementLink.attr('href', agreementLink.attr('href') + '?appName=' + data.appName);
  318. }
  319. if (data.region && data.loginLabel && data.inputData) {
  320. // 防止每次刷新都提交任务
  321. if (!window.sessionStorage.tid) {
  322. var task = {
  323. type: 'fund',
  324. region: data.region,
  325. loginLabel: data.loginLabel,
  326. inputData: JSON.parse(data.inputData),
  327. }
  328. return submitTask(task);
  329. }
  330. }
  331. if (data.tid) {
  332. $("#tid").val(data.tid);
  333. tid = data.tid;
  334. autoInputTaskInfo();
  335. checkTaskStatus(data.tid);
  336. }
  337. });
  338. getTokenInfo.fail(function(error) {
  339. window.sessionStorage.isTokenValid = false;
  340. enableCommitButton(false);
  341. if (error.responseJSON.code === 1020) {
  342. showDialog('timeout');
  343. } else {
  344. showMsg(error.responseJSON.error);
  345. }
  346. });
  347. }
  348. /**
  349. * [submitTask 提交查询任务]
  350. * @param {[type]} data [查询任务相关参数]
  351. */
  352. function submitTask(data) {
  353. showLoading(true);
  354. var url = BASEURL + "task?token=" + token + "&time=" + Math.round(Date.now() / 1000);
  355. // var url = "../../task?token=" + token + "&time=" + Math.round(Date.now() / 1000);
  356. var task = data || getTaskInfo();
  357. data ? null : saveTaskInfo();
  358. var posting = $.ajax({
  359. type: "POST",
  360. url: url,
  361. data: JSON.stringify(task),
  362. timeout: 30000,
  363. contentType: 'application/json;charset=utf-8'
  364. });
  365. posting.done(function(task) {
  366. tid = task.tid;
  367. $("#tid").val(task.tid); // for next submit
  368. window.sessionStorage.tid = tid;
  369. checkTaskStatus(task.tid);
  370. });
  371. posting.fail(function(error) {
  372. showLoading(false);
  373. if (error.responseJSON.code === 1029) {
  374. showDialog('maintain');
  375. } else if (error.responseJSON.code === 1011) {
  376. showMsg('身份证输入不正确');
  377. } else if (error.responseJSON.code === 1020) {
  378. showDialog('timeout');
  379. } else {
  380. showDialog('failed');
  381. }
  382. });
  383. }
  384. /**
  385. * [getTaskInfo 获取提交任务所需参数]
  386. * @return {[Object]} [提交任务所需参数]
  387. */
  388. function getTaskInfo() {
  389. var task = {};
  390. var activeID = $('.tab-tab-active').attr('data-id');
  391. task.region = $('.city-name').attr('data-code');
  392. task.loginLabel = $(".tab-tab-active").text().trim();
  393. task.inputData = []; // 完整记录用户输入信息
  394. $("div[data-id='" + activeID + "'] input").each(function(index, item) {
  395. var currEle = $(item);
  396. task.inputData.push({
  397. key: currEle.attr('id'),
  398. value: currEle.val()
  399. })
  400. })
  401. if ($("#tid").val()) {
  402. task.tid = $("#tid").val();
  403. } else {
  404. task.type = 'fund';
  405. }
  406. return task;
  407. }
  408. /**
  409. * [saveTaskInfo 保存提交用户输入的信息在sessionStorage中,用于用户刷新后数据回填]
  410. */
  411. function saveTaskInfo() {
  412. var ss = window.sessionStorage;
  413. var activeID = $('.tab-tab-active').attr('data-id');
  414. ss.activeID = activeID;
  415. var inputList = $('div [data-id="' + activeID + '"] input');
  416. inputList.each(function(index, item) {
  417. var currentEle = $(item);
  418. ss[currentEle.attr('id')] = currentEle.val();
  419. })
  420. }
  421. /**
  422. * [autoInputTaskInfo 用于用户刷新后从sessionStorage中拿到数据数据回填]
  423. */
  424. function autoInputTaskInfo() {
  425. var ss = window.sessionStorage;
  426. var activeID = $('.tab-tab-active').attr('data-id');
  427. if (ss.activeID && (activeID !== ss.activeID)) {
  428. $('.tab-tab[data-id="' + ss.activeID + '"]').addClass('tab-tab-active').siblings().removeClass('tab-tab-active');
  429. $('.tab-content div[data-id=' + ss.activeID + ']').show().siblings().hide();
  430. }
  431. $("#tid").val(ss.tid);
  432. tid = ss.tid;
  433. for (var key in ss) {
  434. var currentEle = $("div [data-id='" + ss.activeID + "'] #" + key);
  435. currentEle.length > 0 ? currentEle.val(ss[key]) : null;
  436. }
  437. enableCommitButton(isInputReady());
  438. }
  439. /**
  440. * [checkTaskStatus 轮询任务状态]
  441. * @param {[type]} tid [tid]
  442. */
  443. function checkTaskStatus(tid) {
  444. var url = BASEURL + 'task?tid=' + tid + '&token=' + token + '&time=' + Math.round(Date.now() / 1000);
  445. // var url = '../../task?tid=' + tid + '&token=' + token + '&time=' + Math.round(Date.now() / 1000);
  446. var getting = $.get(url);
  447. getting.fail(function(error) {
  448. showMsg(error.responseJSON.error);
  449. });
  450. getting.done(function(task) {
  451. if (task.status === 'done') {
  452. process.stop(100);
  453. $("#tid").val('');
  454. showLoading(false);
  455. redirectToSucsessReturnUrl(task.tid, 'success');
  456. return;
  457. }
  458. if (task.status === "processing") {
  459. if ($('.loading-wrapper').css('display') === 'none') {
  460. showLoading(true);
  461. }
  462. setTimeout(function() {
  463. checkTaskStatus(tid);
  464. }, 1000);
  465. return;
  466. }
  467. if (task.status === "failed") {
  468. process.stop(100);
  469. tid = '';
  470. $("#tid").val('');
  471. showLoading(false);
  472. window.sessionStorage.clear();
  473. if (task.failCode === 1029) {
  474. showDialog('maintain');
  475. } else {
  476. showDialog('failed');
  477. }
  478. return;
  479. }
  480. if (task.status == "suspended") {
  481. process.stop(0);
  482. showLoading(false);
  483. enableCommitButton(false);
  484. switch (task.need) {
  485. case 'changeLoginType': // 无记录,请尝试切换登录类型
  486. case 'regionOrLogintype': // 请选择地区信息 | 请选择登录类型 | 请选择补充地区信息 | 该地区不支持公积金 | 发送的fundId或loginTypeId错误
  487. // 你不是本地用户,请选择所属地区进行登录 | 所选的城市暂不支持,请选择其它城市登录
  488. showMsg('你不是本地用户,请选择所属地区进行登录');
  489. break;
  490. case 'accountOrpassword':
  491. showMsg('账号或密码输入错误');
  492. break;
  493. case 'parameterError':
  494. showMsg('输入的信息有误');
  495. break;
  496. default:
  497. showMsg(task.need);
  498. break;
  499. }
  500. }
  501. });
  502. }
  503. /**
  504. * [showLoading 显示loading界面]
  505. * @param {Boolean} isShow [description]
  506. */
  507. function showLoading(isShow) {
  508. if (isShow) {
  509. // 防止页面刷新之后进度从0开始
  510. if (window.sessionStorage.processRate) {
  511. process.start(parseInt(window.sessionStorage.processRate));
  512. } else {
  513. process.start(0);
  514. }
  515. $('.loading-wrapper').show().siblings().hide();
  516. $('html').addClass('bg-white');
  517. } else {
  518. process.stop(0);
  519. $('html').removeClass('bg-white');
  520. $('.loading-wrapper').hide().siblings().show();
  521. }
  522. }
  523. /**
  524. * [redirectToFailedReturnUrl 跳到redirectURL]
  525. */
  526. function redirectToFailedReturnUrl(tid, result, failCode, reason) {
  527. if (returnUrl.indexOf('?') < 0) {
  528. returnUrl += "?result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
  529. } else {
  530. returnUrl += "&result=" + result + "&tid=" + tid + "&token=" + token + "&failCode=" + failCode + "&reason=" + reason;
  531. }
  532. window.sessionStorage.clear();
  533. window.location.href = returnUrl;
  534. }
  535. /**
  536. * [redirectToSucsessReturnUrl 跳到redirectURL]
  537. */
  538. function redirectToSucsessReturnUrl(tid, result) {
  539. if (returnUrl.indexOf('?') < 0) {
  540. returnUrl += "?result=" + result + "&tid=" + tid + "&token=" + token;
  541. } else {
  542. returnUrl += "&result=" + result + "&tid=" + tid + "&token=" + token;
  543. }
  544. window.sessionStorage.clear();
  545. window.location.href = returnUrl;
  546. }
  547. /**
  548. * [renderTips 渲染常见问题]
  549. * @param {[type]} region [description]
  550. */
  551. function renderTips(region) {
  552. var tipStr = "<p>常见问题</p>";
  553. var defaultTip = null;
  554. var defaultRegion = '北京';
  555. var tipContent = tips.find(function(item, index) {
  556. if (item.region === defaultRegion) {
  557. defaultTip = item;
  558. }
  559. return item.region === region;
  560. });
  561. if (!tipContent) {
  562. tipContent = defaultTip; // 默认北京
  563. }
  564. tipContent = tipContent.tip;
  565. for (var list of tipContent) {
  566. tipStr += "<p>" + list.title + "</p>";
  567. if (list.content) {
  568. for (var tip of list.content) {
  569. tipStr += "<p>" + tip + "</p>"
  570. }
  571. }
  572. }
  573. $('.tips').html(tipStr);
  574. }
  575. /**
  576. * [Process 任务进度显示]
  577. */
  578. function Process(opt) {
  579. this.ele = opt.ele;
  580. this.rate = 0;
  581. this.afterStart = opt.afterStart;
  582. this.afterStop = opt.afterStop;
  583. this.timer = null;
  584. this.step = null;
  585. this._getInterval = function() {
  586. return Math.round((Math.random() * 100) + 300);
  587. };
  588. this._getStep = function() {
  589. return Math.round(Math.random() * 3);
  590. };
  591. }
  592. Process.prototype.start = function(rate) {
  593. this.rate = rate == undefined ? this.rate : rate;
  594. let _this = this;
  595. let interval = this._getInterval();
  596. this.timer = setInterval(function() {
  597. interval = _this._getInterval();
  598. _this.step = _this._getStep();
  599. _this.afterStart && _this.afterStart.call(_this);
  600. }, interval);
  601. }
  602. Process.prototype.stop = function(rate) {
  603. this.rate = rate == undefined ? this.rate : rate;
  604. clearInterval(this.timer);
  605. this.afterStop && this.afterStop();
  606. }
  607. var process = new Process({
  608. ele: $('.process'),
  609. interval: 1000,
  610. afterStart: function() {
  611. this.rate += this.step;
  612. if (this.rate >= 97) {
  613. this.rate = 99;
  614. this.stop(this.rate);
  615. }
  616. this.ele.text(this.rate + '%');
  617. window.sessionStorage.processRate = this.rate;
  618. },
  619. afterStop: function() {
  620. this.ele.text(this.rate + '%');
  621. window.sessionStorage.processRate = this.rate;
  622. }
  623. })