util.js 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. // -------------------------------------------------------------页面初始化操作
  2. let plusStatus = false;
  3. let loadingStatus = false;
  4. // plus end
  5. // 系统运行环境
  6. let SYSTEM_ENVIRONMENT = "DEV";
  7. let ENVIRONMENT = {
  8. // 本地测试环境(公司服务器)
  9. DEV: {
  10. BASE_RUL: "http://121.43.55.7:10091"
  11. },
  12. // 预生产环境(内网地址)
  13. Beta: {
  14. BASE_RUL: "http://10.12.242.163:2025"
  15. }
  16. }
  17. let allCount = 0; // 数据总条数
  18. let pageSize = 20; // 每页显示数据条数
  19. let page = 0; // 初始页
  20. let searchStateValue = 0;
  21. let page_e; // mui-pullRefresh
  22. // 后台服务地址
  23. const BASE_RUL = ENVIRONMENT[SYSTEM_ENVIRONMENT].BASE_RUL;
  24. // 接口URL
  25. // ----------------系统设置-用户
  26. // 登录
  27. const loginUrl = "/ioc-server/system_user/login";
  28. // 注销登录
  29. const logoutUrl = "/ioc-server/system_user/logout";
  30. // token验证
  31. const getUserInfoUrl = "/ioc-server/system_user/validate";
  32. // ajax配置
  33. let requestSettins = {
  34. type: "POST",
  35. dataType: "json",
  36. async: true,
  37. crossDomain: true,
  38. processData: false,
  39. contentType: "application/json",
  40. timeout: 10000,
  41. headers: {
  42. "Content-Type": "application/json;charset=utf-8",
  43. "token": localStorage.getItem("token")
  44. }
  45. };
  46. let requestSettins2 = {
  47. type: "POST",
  48. dataType: "json",
  49. async: false,
  50. crossDomain: true,
  51. processData: false,
  52. contentType: "application/json",
  53. timeout: 10000,
  54. headers: {
  55. "Content-Type": "application/json;charset=utf-8",
  56. "token": localStorage.getItem("token")
  57. }
  58. };
  59. // 记住密码变量
  60. let isActive = localStorage.key('isActive') ? localStorage.getItem('isActive') : false;
  61. // -------------------------------------------------------------自定义的mui事件监听事件
  62. function muiInit() {
  63. //扩展mui.showLoading
  64. (function($, window) {
  65. //显示加载框
  66. $.showLoading = function showLoading(message, type) {
  67. if (loadingStatus) {
  68. return;
  69. } else {
  70. loadingStatus = true;
  71. }
  72. if ($.os.plus && type !== 'div') {
  73. $.plusReady(function() {
  74. plus.nativeUI.showWaiting(message);
  75. });
  76. } else {
  77. var html = '';
  78. html += '<i class="mui-spinner mui-spinner-white"></i>';
  79. html += '<p class="text">' + (message || "数据加载中") + '</p>';
  80. //遮罩层
  81. var mask = document.getElementsByClassName("mui-show-loading-mask");
  82. if (mask.length == 0) {
  83. mask = document.createElement('div');
  84. mask.classList.add("mui-show-loading-mask");
  85. document.body.appendChild(mask);
  86. mask.addEventListener("touchmove", function(e) {
  87. e.stopPropagation();
  88. e.preventDefault();
  89. });
  90. } else {
  91. mask[0].classList.remove("mui-show-loading-mask-hidden");
  92. }
  93. //加载框
  94. var toast = document.getElementsByClassName("mui-show-loading");
  95. if (toast.length == 0) {
  96. toast = document.createElement('div');
  97. toast.classList.add("mui-show-loading");
  98. toast.classList.add('loading-visible');
  99. document.body.appendChild(toast);
  100. toast.innerHTML = html;
  101. toast.addEventListener("touchmove", function(e) {
  102. e.stopPropagation();
  103. e.preventDefault();
  104. });
  105. } else {
  106. toast[0].innerHTML = html;
  107. toast[0].classList.add("loading-visible");
  108. }
  109. }
  110. };
  111. //隐藏加载框
  112. $.hideLoading = function(callback) {
  113. loadingStatus = false;
  114. setTimeout(() => {
  115. if ($.os.plus) {
  116. $.plusReady(function() {
  117. plus.nativeUI.closeWaiting();
  118. });
  119. }
  120. var mask = document.getElementsByClassName("mui-show-loading-mask");
  121. var toast = document.getElementsByClassName("mui-show-loading");
  122. if (mask.length > 0) {
  123. mask[0].classList.add("mui-show-loading-mask-hidden");
  124. }
  125. if (toast.length > 0) {
  126. toast[0].classList.remove("loading-visible");
  127. callback && callback();
  128. }
  129. }, 500);
  130. }
  131. })(mui, window);
  132. // 监听用户点击状态触发事件
  133. mui('body').on('tap', '#loginButton', function() {
  134. // 首页登录按钮触发事件
  135. login();
  136. }).on('tap', '.menuLocalPage', function(event) {
  137. /**
  138. * 自定义页面跳转事件,且阻止事件冒泡
  139. * class="menuLocalPage" data-page-name="要跳转的页面名称"
  140. */
  141. clearSearchValue();
  142. event.stopPropagation();
  143. let pageName = this.dataset.pageName;
  144. if (pageName == "404") {
  145. mui.alert('页面开发中,敬请期待!', '系统提示')
  146. } else {
  147. mui.openWindow("./" + pageName + ".html", pageName);
  148. }
  149. }).on('tap', '.loginOutBtu', function(event) {
  150. // 个人中心退出登录
  151. loginOut();
  152. }).on('tap', '#muiSearchCancel', function(event) {
  153. /**
  154. * 首页搜索弹窗取消按钮
  155. */
  156. if (document.getElementById('searchPanelBox')) {
  157. document.getElementById('muiSearchCancel').style.display = "none";
  158. document.getElementsByClassName('mui-icon-clear')[0].style.right = "0";
  159. document.getElementById('searchInput').style.width = "100%";
  160. document.getElementById('searchPanelBox').style.height = "0";
  161. }
  162. }).on('tap', '.tabList div,.tabList span', function(event) {
  163. /**
  164. * 自定义切换组件
  165. * 子元素:
  166. * class="active" disabled="disabled" data-key="xxx" name="xxx"
  167. */
  168. if (document.getElementsByClassName('active') && document.getElementsByClassName(
  169. 'active')[0]
  170. .getAttribute('name') !=
  171. this.dataset.key && !document.getElementsByName(this.dataset.key)[0]
  172. .getAttribute('disabled')) {
  173. document.getElementsByName(this.dataset.key)[0].parentNode.getElementsByClassName(
  174. 'active')[0]
  175. .className = ""
  176. document.getElementsByName(this.dataset.key)[0].className = "active";
  177. if (document.getElementsByName(this.dataset.key) && this.dataset.url) {
  178. mui.showLoading("正在加载..", "div");
  179. let dataUrl = JSON.parse(this.dataset.url);
  180. kanbanData(dataUrl);
  181. }
  182. }
  183. }).on('change', '[required="required"] .formInput', function() {
  184. if (this.value) {
  185. // 非空验证通过
  186. var nextElementSibling = this.nextElementSibling;
  187. if (nextElementSibling && nextElementSibling.className == 'requiredMsgShow') {
  188. nextElementSibling.className = 'requiredMsgHide';
  189. }
  190. } else {
  191. // 提示该字段不可为空,或者直接通过js直接修改是否显示为空信息
  192. var nextElementSibling = this.nextElementSibling;
  193. if (nextElementSibling && nextElementSibling.className == 'requiredMsgHide') {
  194. nextElementSibling.className = 'requiredMsgShow';
  195. }
  196. }
  197. }).on('tap', '[customizeName="datePoppicker"]', function(event) {
  198. /**
  199. * 自定义时间组件
  200. * input type="text" readonly
  201. * customizeName="datePoppicker"
  202. * name="xxx" 类似id,唯一标识
  203. * data-key="xxx" 与name属性值一致
  204. * data-type="xxx" [datetime|date|time|month|hour] 配置详情: https://dev.dcloud.net.cn/mui/ui/#dtpicker
  205. */
  206. var dtPicker = new mui.DtPicker(this.dataset.type ? {
  207. type: this.dataset.type
  208. } : {
  209. type: "datetime"
  210. });
  211. let that = this;
  212. dtPicker.show(function(selectItems) {
  213. if (document.getElementsByName(that.dataset.key)) {
  214. document.getElementsByName(that.dataset.key)[0].value = selectItems
  215. .text;
  216. }
  217. })
  218. }).on('tap', '[name="submit"]', function(event) {
  219. /**
  220. * 自定义时间组件(提交按钮,自动校验非空字段并检验正确性)
  221. * div name="submit"
  222. * 本页面存在input标签且符合class="formInput"
  223. */
  224. let formOptionDoms = document.getElementsByClassName('formInput');
  225. let formOption = {};
  226. let that = this;
  227. let verification = true;
  228. if (formOptionDoms.length > 0) {
  229. for (let i = 0; i < formOptionDoms.length; i++) {
  230. // 是否必填
  231. let required = formOptionDoms[i].parentNode.parentNode.getAttribute('required');
  232. if (!required || required && formOptionDoms[i].value) {
  233. // 非空验证通过
  234. var nextElementSibling = formOptionDoms[i].nextElementSibling;
  235. if (nextElementSibling && nextElementSibling.className ==
  236. 'requiredMsgShow') {
  237. nextElementSibling.className = 'requiredMsgHide';
  238. }
  239. } else {
  240. // 提示该字段不可为空,或者直接通过js直接修改是否显示为空信息
  241. var nextElementSibling = formOptionDoms[i].nextElementSibling;
  242. if (nextElementSibling && nextElementSibling.className ==
  243. 'requiredMsgHide') {
  244. nextElementSibling.className = 'requiredMsgShow';
  245. }
  246. verification = false;
  247. }
  248. }
  249. }
  250. if (verification) {
  251. let pageName = this.dataset.pageName;
  252. mui.openWindow("./" + pageName + ".html", pageName);
  253. }
  254. }).on('tap', '[type="picker"]', function(event) {
  255. /**
  256. * 自定义下拉框组件
  257. * div type="picker" name = "xxx" parentOption = "xxx"
  258. */
  259. let that = this;
  260. let parentOptionList = pickerLists[this.getAttribute('parentOption')];
  261. if (parentOptionList) {
  262. for (let i = 0; i < parentOptionList.length; i++) {
  263. if (that.getAttribute('name') == parentOptionList[i].name) {
  264. let itemData = parentOptionList[i].data;
  265. let pickerData = [];
  266. var statePicker = new mui.PopPicker();
  267. for (let index in itemData) {
  268. pickerData.push({
  269. value: itemData[index].label != undefined ? itemData[index]
  270. .value : itemData[index],
  271. text: itemData[index].label != undefined ? itemData[index]
  272. .label : itemData[
  273. index]
  274. })
  275. }
  276. statePicker.setData(pickerData);
  277. statePicker.show(function(items) {
  278. that.innerText = items[0].text;
  279. if (document.getElementById('pageName')) {
  280. let pageName = document.getElementById('pageName')
  281. .innerText;
  282. dataUrl[pageName].params[that.getAttribute('name')] = items[
  283. 0].value;
  284. resetPageInfo();
  285. }
  286. });
  287. }
  288. }
  289. }
  290. }).on('tap', '.changeLoginTypeToPhone', function() {
  291. // 首页切换登录方式,为手机号码登录
  292. console.log("首页切换登录方式,为手机号码登录")
  293. document.getElementById('loginFormBox').style.display = "none";
  294. document.getElementById('loginForm2Box').style.display = "block";
  295. }).on('tap', '.changeLoginTypeToUser', function() {
  296. // 首页切换登录方式,为账号登录
  297. console.log("首页切换登录方式,为账号登录")
  298. document.getElementById('loginForm2Box').style.display = "none";
  299. document.getElementById('loginFormBox').style.display = "block";
  300. }).on('change', '#autoLogin', function() {
  301. isActive = this.checked ? "true" : "false";
  302. localStorage.setItem('isActive', isActive);
  303. }).on('tap', '#reSearch', function() {
  304. // 数据列表刷新,搜索框重置
  305. mui.confirm("是否重置并刷新?", "系统提示", function(status) {
  306. if (status.index == 1) {
  307. clearSearchValue();
  308. resetPageInfo();
  309. }
  310. })
  311. }).on('tap', '.toBackPage', function() {
  312. mui.back();
  313. })
  314. }
  315. // 原生请求
  316. function postRequest(url, setting, funSuccess, funError) {
  317. if (setting.data) {
  318. setting.data = JSON.stringify(setting.data);
  319. }
  320. requestSettins.success = funSuccess;
  321. requestSettins.error = funError;
  322. let newSetting = Object.assign(requestSettins, setting);
  323. mui.ajax(BASE_RUL + url, newSetting);
  324. }
  325. function postRequest2(url, setting, otherParams, funSuccess, funError) {
  326. try {
  327. if (setting.data) {
  328. setting.data = JSON.stringify(setting.data);
  329. }
  330. requestSettins2.success = (data) => {
  331. funSuccess(data, otherParams);
  332. };
  333. requestSettins2.error = funError;
  334. let newSetting = Object.assign(requestSettins2, setting);
  335. mui.ajax(BASE_RUL + url, newSetting);
  336. } catch (e) {
  337. //TODO handle the exception
  338. console.log("postRequest2 error:", e);
  339. }
  340. }
  341. // -------------------------------------------------------------自定义事件
  342. // 页面自动化配置生效
  343. function pageInit() {
  344. let tabBoxs = document.getElementsByClassName('tabBox');
  345. if (tabBoxs.length > 0) {
  346. for (let i = 0; i < tabBoxs.length; i++) {
  347. if (tabBoxs[i].getAttribute('option')) {
  348. let option_ = formTabOptions[tabBoxs[i].getAttribute('option')];
  349. if (option_.length > 0) {
  350. for (let i1 = 0; i1 < option_.length; i1++) {
  351. let dom = document.createElement('span');
  352. dom.setAttribute("data-key", option_[i1].lable + option_[i1].key);
  353. dom.setAttribute("data-url", JSON.stringify(option_[i1].url));
  354. dom.setAttribute("name", option_[i1].lable + option_[i1].key);
  355. dom.className = option_[i1].active ? 'active' : '';
  356. dom.innerText = option_[i1].lable
  357. tabBoxs[i].appendChild(dom);
  358. setTimeout(() => {
  359. if (option_[i1].active) {
  360. if (mui.showLoading != undefined) {
  361. mui.showLoading("正在加载..", "div");
  362. }
  363. kanbanData(option_[i1].url);
  364. }
  365. });
  366. }
  367. } else {
  368. mui.toast('form option:' + tabBoxs[i].getAttribute('option') + 'is undefined!');
  369. }
  370. }
  371. }
  372. }
  373. let echartDoms = document.getElementsByClassName('echartDom');
  374. if (echartDoms.length > 0) {
  375. for (let index = 0; index < echartDoms.length; index++) {
  376. let domId = echartDoms[index].getAttribute('id');
  377. let option = options[domId];
  378. if (option) {
  379. initEchart(domId, option, false);
  380. }
  381. }
  382. }
  383. if (document.getElementById('searchInput')) {
  384. // 存在搜索框的话开始监听{focus:获取焦点,input:内容修改,blur:失去焦点}
  385. document.getElementById('searchInput').addEventListener('focus', function(event) {
  386. if (document.getElementById('searchPanelBox')) {
  387. document.getElementsByClassName('mui-icon-clear')[0].style.right = "2rem";
  388. document.getElementById('searchInput').style.width = "calc(100% - 4rem)"
  389. document.getElementById('muiSearchCancel').style.display = "block";
  390. }
  391. // 展开搜索结果框
  392. homeSearch();
  393. })
  394. document.getElementById('searchInput').addEventListener('input', function(event) {
  395. if (document.getElementById('searchPanelBox')) {
  396. document.getElementsByClassName('mui-icon-clear')[0].style.right = "3rem";
  397. document.getElementById('searchInput').style.width = "calc(100% - 3rem)"
  398. document.getElementById('muiSearchCancel').style.display = "block";
  399. }
  400. // 展开搜索结果框
  401. homeSearch();
  402. })
  403. document.getElementById('searchInput').addEventListener('keypress', function(event) {
  404. if (event.keyCode == 13) {
  405. document.activeElement.blur(); // 收起模拟键盘
  406. // 展开搜索结果框
  407. if (document.getElementById('searchPanelBox')) {
  408. homeSearch();
  409. } else {
  410. resetPageInfo();
  411. }
  412. event.preventDefault(); // 阻止页面刷新
  413. }
  414. })
  415. }
  416. let formBoxs = document.getElementsByClassName('form-box');
  417. if (formBoxs.length > 0) {
  418. for (let i = 0; i < formBoxs.length; i++) {
  419. if (formBoxs[i].getAttribute('option')) {
  420. console.log("初始化表单", formBoxs[i].getAttribute('option'))
  421. let option_ = formOptions[formBoxs[i].getAttribute('option')];
  422. let dom = document.createElement('div');
  423. dom.innerHTML = `<div class="form-title">${formBoxs[i].getAttribute('title')}</div>`;
  424. formBoxs[i].appendChild(dom);
  425. if (option_.length > 0) {
  426. for (let i1 = 0; i1 < option_.length; i1++) {
  427. let doms = document.createElement('div');
  428. doms.innerHTML = `
  429. <div class="row" title="${option_[i1].title}" ${option_[i1].required ? 'required="required"' : ''}>
  430. <div>${option_[i1].title}</div>
  431. <div>
  432. <input class="formInput" name="${option_[i1].name}" data-key="${option_[i1].name}" ${option_[i1].customizeName ? 'customizeName="'+option_[i1].customizeName+'"' : ''} type="text">
  433. ${option_[i1].required ? '<p class="requiredMsgHide">'+option_[i1].title+'不能为空</p>' : ''}
  434. </div>
  435. </div>`;
  436. formBoxs[i].appendChild(doms);
  437. }
  438. } else {
  439. mui.toast('form option:' + formBoxs[i].getAttribute('option') + 'is undefined!');
  440. }
  441. }
  442. }
  443. }
  444. let formTabBoxs = document.getElementsByClassName('form-list-box');
  445. if (formTabBoxs.length > 0) {
  446. for (let i = 0; i < formTabBoxs.length; i++) {
  447. if (formTabBoxs[i].getAttribute('option')) {
  448. let option_ = formTabOptions[formTabBoxs[i].getAttribute('option')];
  449. if (option_.length > 0) {
  450. for (let i1 = 0; i1 < option_.length; i1++) {
  451. let dom = document.createElement('div');
  452. dom.className = "form-row tabList";
  453. let datas = option_[i1].data;
  454. for (let i2 = 0; i2 < datas.length; i2++) {
  455. dom.innerHTML +=
  456. `<div ${datas[i2].active ? 'class="active"' : ''} ${datas[i2].disabled ? 'disabled="disabled"' : ''} data-key="${option_[i1].name + datas[i2].key}" name="${option_[i1].name + datas[i2].key}">${datas[i2].lable}</div>`;
  457. }
  458. formTabBoxs[i].appendChild(dom);
  459. }
  460. } else {
  461. mui.toast('form option:' + formTabBoxs[i].getAttribute('option') + 'is undefined!');
  462. }
  463. }
  464. }
  465. }
  466. let pickerBoxs = document.getElementsByClassName('pickerBox');
  467. if (pickerBoxs.length > 0) {
  468. for (let i = 0; i < pickerBoxs.length; i++) {
  469. if (pickerBoxs[i].getAttribute('option') && pickerLists[pickerBoxs[i].getAttribute(
  470. 'option')]) {
  471. let pickerOptions = pickerLists[pickerBoxs[i].getAttribute('option')];
  472. if (pickerOptions.length > 0) {
  473. for (let i2 = 0; i2 < pickerOptions.length; i2++) {
  474. let pickerOption_ = pickerOptions[i2];
  475. let pickerDom = document.createElement('div');
  476. pickerDom.setAttribute('name', pickerOption_.name);
  477. pickerDom.setAttribute('type', 'picker');
  478. pickerDom.setAttribute('parentOption', pickerBoxs[i].getAttribute('option'));
  479. pickerDom.innerText = pickerOption_.label;
  480. pickerBoxs[i].appendChild(pickerDom);
  481. }
  482. }
  483. } else {
  484. mui.toast('picker option:' + pickerBoxs[i].getAttribute('option') + 'is undefined!');
  485. }
  486. }
  487. }
  488. }
  489. // 看板页面初始化配置mui请求
  490. function muiPageInit() {
  491. // mui请求
  492. let myTaskListDom = document.getElementById('myTaskListDom');
  493. if (myTaskListDom) {
  494. getMoveMyTaskList();
  495. myTaskListDom.addEventListener('scroll', function(event) {
  496. //scrollTop是滚动条滚动时,距离顶部的距离
  497. var scrollTop = myTaskListDom.scrollTop || document.body.scrollTop;
  498. //windowHeight是可视区的高度
  499. var windowHeight = myTaskListDom.clientHeight || document.body.clientHeight;
  500. //scrollHeight是滚动条的总高度
  501. var scrollHeight = myTaskListDom.scrollHeight || document.body.scrollHeight;
  502. //滚动条到底部的条件
  503. let scrollBottom = scrollHeight - scrollTop - windowHeight;
  504. if (scrollBottom == 0 && (allCount > page * pageSize)) {
  505. getMoveMyTaskList();
  506. }
  507. })
  508. }
  509. // mui请求
  510. // 如果在首页,先填充保存的用户名和密码,如果有token则进行token校验,通过提示欢迎回来
  511. if (document.getElementById('autoLogin')) {
  512. if (isActive) {
  513. document.getElementById('userName').value = localStorage.key('userName') ? localStorage
  514. .getItem(
  515. 'userName') : '';
  516. document.getElementById('passWord').value = localStorage.key('passWord') ? localStorage
  517. .getItem(
  518. 'passWord') : '';
  519. }
  520. document.getElementById('autoLogin').checked = isActive;
  521. if (localStorage.getItem('token') != null) {
  522. postRequest2(getUserInfoUrl, {}, null, function success(res, params) {
  523. if (res.code == 200) {
  524. mui.toast('欢迎回来', '系统提示');
  525. mui.openWindow("pages/homeNew.html", "homeNew");
  526. } else {
  527. localStorage.removeItem("token");
  528. }
  529. }, function error(xhr, type, errorThrown) {
  530. mui.alert('系统异常!请联系开发人员!', '系统提示');
  531. });
  532. }
  533. }
  534. }
  535. // 用户登录
  536. function apiLogin(setting, funSuccess, funError) {
  537. postRequest(loginUrl, setting, funSuccess, funError);
  538. }
  539. // 首页搜索弹窗事件
  540. function homeSearch() {
  541. if (document.getElementById('searchPanelBox')) {
  542. let searchPanelBoxDom = document.getElementById('searchPanelBox');
  543. let searchPanelBoxDomInnerHTML = ``;
  544. let paramValue = document.getElementById('searchInput').value;
  545. for (let key in menuList) {
  546. searchPanelBoxDomInnerHTML += `<h5>${key}</h5>
  547. <div>`;
  548. for (let i = 0; i < menuList[key].length; i++) {
  549. if (menuList[key][i].name.indexOf(paramValue) != -1) {
  550. if (menuList[key][i].pageName) {
  551. searchPanelBoxDomInnerHTML += `<div class="menuLocalPage" data-page-name="${menuList[key][i].pageName}" menuName="${menuList[key][i].name}">
  552. <div></div>${menuList[key][i].name}
  553. </div>`;
  554. }
  555. }
  556. }
  557. searchPanelBoxDomInnerHTML += `</div>`;
  558. }
  559. searchPanelBoxDom.innerHTML = searchPanelBoxDomInnerHTML;
  560. searchPanelBoxDom.style.height = "calc(100vh - 6.5rem)";
  561. }
  562. }
  563. // 登录请求
  564. function login() {
  565. let docUserName = document.getElementById('userName').value;
  566. let docPassword = document.getElementById('passWord').value;
  567. if (!docUserName) {
  568. mui.alert('请输入用户名!', '表单校验', function() {
  569. return false;
  570. });
  571. return false;
  572. }
  573. if (!docPassword) {
  574. mui.alert('请输入密码!', '表单校验', function() {
  575. return false;
  576. });
  577. return false;
  578. }
  579. // 登录请求
  580. if (docUserName && docPassword) {
  581. let param = {
  582. username: docUserName,
  583. password: docPassword
  584. }
  585. // 开始请求登录接口
  586. apiLogin({
  587. data: param
  588. }, function success(res, textStatus, xhr) {
  589. if (res.code == 200) {
  590. // 如果用户选中了记住密码,则保存账户信息
  591. if (isActive) {
  592. localStorage.setItem('userName', docUserName);
  593. localStorage.setItem('passWord', docPassword);
  594. }
  595. // 缓存登录状态主要信息
  596. localStorage.setItem("userId", res.data.userInfo.id);
  597. localStorage.setItem("userName", res.data.userInfo.userName);
  598. localStorage.setItem("token", res.data.token);
  599. // 跳转到主页
  600. mui.openWindow({
  601. url: "pages/homeNew.html",
  602. id: "homeNew",
  603. createNew: true
  604. });
  605. } else {
  606. mui.alert(res.msg ? res.msg : '登录失败!', '系统提示');
  607. }
  608. }, function error(xhr, type, errorThrown) {
  609. mui.alert('登录失败!', '系统提示');
  610. });
  611. }
  612. }
  613. // 看板数据初始化(主要是echart的自动化配置比较复杂)
  614. function kanbanData(url) {
  615. let outEchartBoxDom = document.getElementById('outEchartBox');
  616. outEchartBoxDom.innerHTML = "";
  617. // 数据指标
  618. if (url.countUrl) {
  619. let params = {};
  620. if (url.countParams) {
  621. params = {
  622. data: url.countParams
  623. };
  624. }
  625. postRequest2(url.countUrl, params, url.countList, function success(res, otherParams) {
  626. if (res.code == 200) {
  627. for (let i = 0; i < 4; i++) {
  628. document.getElementById('countTitle' + i).innerText = otherParams[i];
  629. document.getElementById('countValue' + i).innerText = res.data.list[i]
  630. .value;
  631. if (res.data.list[i].compare != undefined) {
  632. document.getElementById('countValue' + i).innerText = res.data.list[i]
  633. .value;
  634. document.getElementById('countValue' + i).className = "";
  635. document.getElementById('countCompare' + i).innerHTML = `同比 <span class="${res.data.list[i].compare > 0 ? 'monthOnMonth2' : 'monthOnMonth0'}">
  636. ${res.data.list[i].compare + "%"}
  637. </span>`
  638. } else {
  639. document.getElementById('countValue' + i).innerText = res.data.list[i]
  640. .value + "%";
  641. if (res.data.list[i].value > 0) {
  642. document.getElementById('countValue' + i).className = "trend1";
  643. } else if (res.data.list[i].value < 0) {
  644. document.getElementById('countValue' + i).className = "trend0";
  645. }
  646. document.getElementById('countCompare' + i).innerText = '';
  647. }
  648. }
  649. document.getElementById('worthAttention').innerText = res.data.worthAttention;
  650. if (url.listUrl) {
  651. for (let i_ = 0; i_ < url.listUrl.length; i_++) {
  652. let params = {};
  653. let listUrlItem = url.listUrl[i_];
  654. if (listUrlItem.params) {
  655. params = {
  656. data: listUrlItem.params
  657. };
  658. }
  659. let echartBox = document.createElement('div');
  660. echartBox.innerHTML = `<h4 style="padding-left: 10px;" class="echartTitle">${listUrlItem.title}</h4>
  661. <div class="echartBox">
  662. <div class="echartDom" id="${listUrlItem.echartDomId}"></div>
  663. </div>`;
  664. document.getElementById('outEchartBox').append(echartBox);
  665. setTimeout(() => {
  666. postRequest2(listUrlItem.url, params, listUrlItem,
  667. function success2(
  668. res2, otherParams) {
  669. if (res2.code == 200) {
  670. if (otherParams.jsonObject) {
  671. let echartData = {
  672. xData: []
  673. }
  674. echartData.echartJsonObject =
  675. otherParams
  676. .jsonObject;
  677. echartData.serverData = {};
  678. for (let key in otherParams
  679. .jsonObject) {
  680. echartData.serverData[key] = []
  681. }
  682. for (let i2 = 0; i2 < res2.data
  683. .length; i2++) {
  684. let item = res2.data[i2];
  685. echartData.xData.push(item.label);
  686. for (let key in otherParams
  687. .jsonObject) {
  688. echartData.serverData[key].push(
  689. item
  690. .jsonObject[key]);
  691. }
  692. }
  693. let option = options[otherParams
  694. .echartDomId];
  695. option.legend.data = [];
  696. option.color = [];
  697. option.xAxis[0].data = echartData.xData;
  698. option.xAxis[0].name = otherParams
  699. .xAxisName;
  700. option.yAxis = [];
  701. if (otherParams.yAxisName) {
  702. option.yAxis = [{
  703. type: 'value',
  704. name: otherParams
  705. .yAxisName,
  706. axisLine: {
  707. show: true,
  708. },
  709. }];
  710. }
  711. option.legend.selected = {};
  712. option.series = [];
  713. for (let serverItemKey in echartData
  714. .echartJsonObject) {
  715. let type = "line";
  716. if (echartData.echartJsonObject[
  717. serverItemKey]
  718. .hideSelected) {
  719. option.legend.selected[
  720. echartData
  721. .echartJsonObject[
  722. serverItemKey]
  723. .seriesName] =
  724. false;
  725. }
  726. if (otherParams.series) {
  727. type = otherParams.series[
  728. serverItemKey]
  729. .type;
  730. let yAxisItem = {
  731. type: "value",
  732. name: otherParams
  733. .series[
  734. serverItemKey]
  735. .yAxisName,
  736. position: otherParams
  737. .series[
  738. serverItemKey]
  739. .position,
  740. axisLine: {
  741. show: true,
  742. lineStyle: {
  743. color: echartData
  744. .echartJsonObject[
  745. serverItemKey
  746. ].color
  747. }
  748. }
  749. }
  750. option.yAxis.push(yAxisItem);
  751. }
  752. let seriesItem = {
  753. name: echartData
  754. .echartJsonObject[
  755. serverItemKey]
  756. .seriesName,
  757. type: type,
  758. smooth: true,
  759. lineStyle: {
  760. width: 0
  761. },
  762. // showSymbol: false,
  763. yAxisIndex: otherParams
  764. .series &&
  765. otherParams.series[
  766. serverItemKey]
  767. .yAxisIndex ?
  768. otherParams.series[
  769. serverItemKey]
  770. .yAxisIndex : 0,
  771. areaStyle: {
  772. opacity: 0.8,
  773. color: echartData
  774. .echartJsonObject[
  775. serverItemKey]
  776. .noLinearGradient ?
  777. echartData
  778. .echartJsonObject[
  779. serverItemKey]
  780. .color : new echarts
  781. .graphic
  782. .LinearGradient(0,
  783. 0, 0,
  784. 1, [{
  785. offset: 0,
  786. color: echartData
  787. .echartJsonObject[
  788. serverItemKey
  789. ]
  790. .color
  791. },
  792. {
  793. offset: 1,
  794. color: '#FFFFFF'
  795. }
  796. ])
  797. },
  798. emphasis: {
  799. focus: 'series'
  800. },
  801. data: echartData.serverData[
  802. serverItemKey]
  803. }
  804. if (!otherParams.series || !
  805. otherParams.series[
  806. serverItemKey].stack ==
  807. false) {
  808. seriesItem.stack = 'Total';
  809. }
  810. if (otherParams.series &&
  811. otherParams.series[
  812. serverItemKey].itemStyle) {
  813. seriesItem.itemStyle =
  814. otherParams.series[
  815. serverItemKey]
  816. .itemStyle;
  817. }
  818. if (otherParams.series &&
  819. otherParams.series[
  820. serverItemKey].barWidth) {
  821. seriesItem.barWidth =
  822. otherParams.series[
  823. serverItemKey].barWidth;
  824. }
  825. option.series.push(seriesItem);
  826. option.legend.data.push(echartData
  827. .echartJsonObject[
  828. serverItemKey]
  829. .seriesName);
  830. option.color.push(echartData
  831. .echartJsonObject[
  832. serverItemKey].color);
  833. }
  834. initEchart(otherParams.echartDomId,
  835. option, true);
  836. } else {
  837. let option = options[otherParams
  838. .echartDomId];
  839. option.series[0].data = res2.data;
  840. if (otherParams.labelFormatter) {
  841. option.series[0].label.formatter =
  842. otherParams
  843. .labelFormatter;
  844. }
  845. initEchart(otherParams.echartDomId,
  846. option, true);
  847. }
  848. if (mui.hideLoading != undefined)(
  849. mui.hideLoading()
  850. );
  851. } else {
  852. if (mui.hideLoading != undefined)(
  853. mui.hideLoading()
  854. );
  855. initEchart(otherParams.echartDomId, null,
  856. true);
  857. }
  858. },
  859. function error2(xhr, type, errorThrown) {
  860. if (mui.hideLoading != undefined)(
  861. mui.hideLoading()
  862. );
  863. mui.alert('系统异常!请联系开发人员!', '系统提示');
  864. });
  865. })
  866. }
  867. }
  868. } else {
  869. if (mui.hideLoading != undefined)(
  870. mui.hideLoading()
  871. );
  872. if (res.msg == "当前未登录" || res.msg == "请登录后重试" || res.msg == "登录失效") {
  873. if (mui.plus) {
  874. mui.alert(resJson.msg, '系统提示', function() {
  875. localStorage.removeItem("token");
  876. mui.openWindow("../index.html", "login");
  877. });
  878. } else {
  879. localStorage.removeItem("token");
  880. mui.openWindow("../index.html", "login");
  881. }
  882. }
  883. }
  884. }, function error(xhr, type, errorThrown) {
  885. if (mui.hideLoading != undefined)(
  886. mui.hideLoading()
  887. );
  888. mui.alert('系统异常!请联系开发人员!', '系统提示');
  889. });
  890. }
  891. }
  892. // 注销登录
  893. function loginOut() {
  894. postRequest(logoutUrl, {}, function success(res, textStatus, xhr) {
  895. if (res.code == 200) {
  896. mui.toast('退出成功', '系统提示');
  897. localStorage.removeItem("token");
  898. mui.openWindow("../index.html", "login");
  899. }
  900. }, function error(xhr, type, errorThrown) {
  901. mui.alert('系统异常!请联系开发人员!', '系统提示');
  902. });
  903. }
  904. // 请求我的任务列表(下一页)
  905. function getMoveMyTaskList() {
  906. page_e = this;
  907. getMyTaskList();
  908. }
  909. // 清空搜索框值
  910. function clearSearchValue() {
  911. if (document.getElementById('searchInput')) {
  912. document.getElementById('searchInput').value = null;
  913. }
  914. }
  915. // 重置页面信息并查询
  916. function resetPageInfo() {
  917. allCount = 0;
  918. pageSize = 20;
  919. page = 0;
  920. // 删除数据列表
  921. if (document.getElementsByClassName('dataItem4').length > 0) {
  922. let displayFlexDoms = document.getElementsByClassName('dataItem4');
  923. const displayFlexDomsSize = displayFlexDoms.length;
  924. if (displayFlexDomsSize > 0) {
  925. for (let index = 0; index < displayFlexDomsSize; index++) {
  926. if (displayFlexDoms[0]) {
  927. displayFlexDoms[0].remove();
  928. }
  929. }
  930. }
  931. }
  932. // 重新请求数据
  933. getMyTaskList();
  934. if (document.getElementById('listMoveDom')) {
  935. // mui('#listMoveDom').pullRefresh().refresh(true);
  936. }
  937. };
  938. // 请求数据列表
  939. function getMyTaskList() {
  940. if (mui.showLoading != undefined) {
  941. mui.showLoading("正在加载..", "div");
  942. }
  943. sessionStorage.clear();
  944. // 首先获取页面标志
  945. let pageName = document.getElementById('pageName').innerText;
  946. dataUrl[pageName].params.pageStart = (page) * pageSize;
  947. postRequest2(dataUrl[pageName].url, {
  948. data: dataUrl[pageName].params
  949. }, {}, function funSuccess(res, params) {
  950. let resJson = res;
  951. try {
  952. if (resJson.code == 200 && resJson.data != null) {
  953. allCount = resJson.data.total;
  954. if (resJson.data.data && resJson.data.data.length > 0) {
  955. let listDom = document.getElementById('myTaskListDom');
  956. for (let i = 0; i < resJson.data.data.length; i++) {
  957. let moveDom = document.createElement('div');
  958. moveDom.className = "dataItem4 borderBottom";
  959. moveDom.setAttribute("data-messageId", resJson.data.data[i].id);
  960. moveDom.setAttribute("readStatus", resJson.data.data[i].status);
  961. moveDom.innerHTML = `<div>
  962. <span class="title">${resJson.data.data[i].title ? resJson.data.data[i].title : resJson.data.data[i].type}</span>
  963. <p>${resJson.data.data[i].time}</p>
  964. <div class="content">
  965. ${resJson.data.data[i].content}
  966. </div>
  967. </div>`;
  968. listDom.insertBefore(moveDom, document.getElementById(
  969. 'listMoveDom'));
  970. }
  971. }
  972. // 分页配置
  973. if (page_e) {
  974. if (allCount > (page + 1) * pageSize) {
  975. document.getElementById("upTitle").innerHTML = "上拉加载更多……";
  976. if (mui.hideLoading != undefined)(
  977. mui.hideLoading()
  978. );
  979. // page_e.endPullupToRefresh(false);
  980. } else {
  981. mui.toast('没有更多数据了');
  982. document.getElementById("upTitle").innerHTML = "没有更多数据了";
  983. if (mui.hideLoading != undefined)(
  984. mui.hideLoading()
  985. );
  986. }
  987. } else {
  988. console.log('page_e is null!')
  989. }
  990. page++;
  991. } else {
  992. // 请求失败!
  993. document.getElementById("upTitle").innerHTML = resJson.msg;
  994. if (mui.hideLoading != undefined)(
  995. mui.hideLoading()
  996. );
  997. if (resJson.msg === "当前未登录" || resJson.msg === "请登录后重试" || res.msg == "登录失效") {
  998. if (mui.plus) {
  999. mui.alert(resJson.msg, '系统提示', function() {
  1000. localStorage.removeItem("token");
  1001. mui.openWindow("../index.html", "login");
  1002. });
  1003. } else {
  1004. localStorage.removeItem("token");
  1005. mui.openWindow("../index.html", "login");
  1006. }
  1007. }
  1008. }
  1009. } catch (e) {
  1010. // 处理异常
  1011. //TODO handle the exception
  1012. mui.alert('try处理异常!' + e, '系统提示', function() {
  1013. document.getElementById("upTitle").innerHTML = "处理异常!";
  1014. if (mui.hideLoading != undefined)(
  1015. mui.hideLoading()
  1016. );
  1017. });
  1018. }
  1019. }, function error(xhr, type, errorThrown) {
  1020. // request异常
  1021. mui.alert('请求失败!' + JSON.stringify(xhr), '系统提示', function() {
  1022. document.getElementById("upTitle").innerHTML = "请求失败!";
  1023. if (mui.hideLoading != undefined)(
  1024. mui.hideLoading()
  1025. );
  1026. });
  1027. });
  1028. };
  1029. // echart初始化
  1030. function initEchart(chartDomId, option, state) {
  1031. var chartDom = document.getElementById(chartDomId);
  1032. try {
  1033. if (state) {
  1034. echarts.init(chartDom).dispose();
  1035. }
  1036. if (option) {
  1037. echarts.init(chartDom).setOption(option);
  1038. }
  1039. } catch (e) {
  1040. //TODO handle the exception
  1041. console.log(chartDomId, "dispose error", e);
  1042. }
  1043. }
  1044. // 获取设备类型,后续很有可能会用到
  1045. let deviceType = "ios";
  1046. if (mui.os.ios) {
  1047. console.log('苹果设备', 'version:' + mui.os.version, 'iphone:' + mui.os.iphone, 'ipad:' + mui.os.ipad);
  1048. deviceType = "ios";
  1049. } else if (mui.os.android) {
  1050. console.log('安卓设备', 'version:' + mui.os.version, 'isBadAndroid:' + mui.os.isBadAndroid);
  1051. deviceType = "android";
  1052. }
  1053. pageInit();
  1054. if (SYSTEM_ENVIRONMENT == "android") {
  1055. mui.plusReady(function() {
  1056. if (plus) {
  1057. console.log("plus初始化成功!")
  1058. plusStatus = true;
  1059. mui.init();
  1060. muiInit();
  1061. muiPageInit();
  1062. }
  1063. }, true);
  1064. } else {
  1065. mui.init();
  1066. muiInit();
  1067. muiPageInit();
  1068. }