util.js 38 KB

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