util.js 36 KB

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