暂无描述

fund_h5_api.js 22KB

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