123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185 |
- // -------------------------------------------------------------页面初始化操作
- let plusStatus = false;
- let loadingStatus = false;
- // plus end
- // 系统运行环境
- let SYSTEM_ENVIRONMENT = "DEV";
- let ENVIRONMENT = {
- // 本地测试环境(公司服务器)
- DEV: {
- BASE_RUL: "http://121.43.55.7:10091",
- DMS_BASE_URL: "http://121.43.55.7:2101/"
- },
- // 预生产环境(内网地址)
- Beta: {
- BASE_RUL: "http://10.12.242.163:2025",
- DMS_BASE_URL: "http://121.43.55.7:2101/"
- }
- }
- let allCount = 0; // 数据总条数
- let pageSize = 20; // 每页显示数据条数
- let page = 0; // 初始页
- let searchStateValue = 0;
- let page_e; // mui-pullRefresh
- // 后台服务地址
- const BASE_RUL = ENVIRONMENT[SYSTEM_ENVIRONMENT].BASE_RUL;
- const DMS_BASE_URL = ENVIRONMENT[SYSTEM_ENVIRONMENT].DMS_BASE_URL;
- // 接口URL
- // ----------------系统设置-用户
- // 登录
- const loginUrl = "/ioc-server/system_user/login";
- // 注销登录
- const logoutUrl = "/ioc-server/system_user/logout";
- // token验证
- const getUserInfoUrl = "/ioc-server/system_user/validate";
- // DMS登录接口
- const dmsLoginUrl = "/proxy_oauth/user/login";
- // 添加dms数据
- const dmsAddContent = "/proxy_dms/content/addContent";
- // dms文件上传
- const uploadFile = "/proxy_dms/file/uploadFile";
- // ajax配置
- let requestSettins = {
- type: "POST",
- dataType: "json",
- async: true,
- crossDomain: true,
- processData: false,
- contentType: "application/json",
- timeout: 10000,
- headers: {
- "Content-Type": "application/json;charset=utf-8",
- "token": localStorage.getItem("token")
- }
- };
- let requestSettins2 = {
- type: "POST",
- dataType: "json",
- async: false,
- crossDomain: true,
- processData: false,
- contentType: "application/json",
- timeout: 10000,
- headers: {
- "Content-Type": "application/json;charset=utf-8",
- "token": localStorage.getItem("token")
- }
- };
- // 记住密码变量
- let isActive = localStorage.key('isActive') ? localStorage.getItem('isActive') : false;
- // -------------------------------------------------------------自定义的mui事件监听事件
- function muiInit() {
- let pageNameDom = document.getElementById("pageName");
- if (pageNameDom) {
- let pageName = pageNameDom.innerText;
- if (pageName == "opinionFeedback") {
- getDmsToken();
- }
- }
- //扩展mui.showLoading
- (function($, window) {
- //显示加载框
- $.showLoading = function showLoading(message, type) {
- if (loadingStatus) {
- return;
- } else {
- loadingStatus = true;
- }
- if ($.os.plus && type !== 'div') {
- $.plusReady(function() {
- plus.nativeUI.showWaiting(message);
- });
- } else {
- var html = '';
- html += '<i class="mui-spinner mui-spinner-white"></i>';
- html += '<p class="text">' + (message || "数据加载中") + '</p>';
- //遮罩层
- var mask = document.getElementsByClassName("mui-show-loading-mask");
- if (mask.length == 0) {
- mask = document.createElement('div');
- mask.classList.add("mui-show-loading-mask");
- document.body.appendChild(mask);
- mask.addEventListener("touchmove", function(e) {
- e.stopPropagation();
- e.preventDefault();
- });
- } else {
- mask[0].classList.remove("mui-show-loading-mask-hidden");
- }
- //加载框
- var toast = document.getElementsByClassName("mui-show-loading");
- if (toast.length == 0) {
- toast = document.createElement('div');
- toast.classList.add("mui-show-loading");
- toast.classList.add('loading-visible');
- document.body.appendChild(toast);
- toast.innerHTML = html;
- toast.addEventListener("touchmove", function(e) {
- e.stopPropagation();
- e.preventDefault();
- });
- } else {
- toast[0].innerHTML = html;
- toast[0].classList.add("loading-visible");
- }
- }
- };
- //隐藏加载框
- $.hideLoading = function(callback) {
- loadingStatus = false;
- setTimeout(() => {
- if ($.os.plus) {
- $.plusReady(function() {
- plus.nativeUI.closeWaiting();
- });
- }
- var mask = document.getElementsByClassName("mui-show-loading-mask");
- var toast = document.getElementsByClassName("mui-show-loading");
- if (mask.length > 0) {
- mask[0].classList.add("mui-show-loading-mask-hidden");
- }
- if (toast.length > 0) {
- toast[0].classList.remove("loading-visible");
- callback && callback();
- }
- }, 500);
- }
- })(mui, window);
- // 监听用户点击状态触发事件
- mui('body').on('tap', '#loginButton', function() {
- // 首页登录按钮触发事件
- login();
- }).on('tap', '.menuLocalPage', function(event) {
- /**
- * 自定义页面跳转事件,且阻止事件冒泡
- * class="menuLocalPage" data-page-name="要跳转的页面名称"
- */
- clearSearchValue();
- event.stopPropagation();
- let pageName = this.dataset.pageName;
- if (pageName == "404") {
- mui.alert('页面开发中,敬请期待!', '系统提示')
- } else {
- mui.openWindow("./" + pageName + ".html", pageName);
- }
- }).on('tap', '.loginOutBtu', function(event) {
- // 个人中心退出登录
- loginOut();
- }).on('tap', '#muiSearchCancel', function(event) {
- /**
- * 首页搜索弹窗取消按钮
- */
- if (document.getElementById('searchPanelBox')) {
- document.getElementById('muiSearchCancel').style.display = "none";
- document.getElementsByClassName('mui-icon-clear')[0].style.right = "0";
- document.getElementById('searchInput').style.width = "100%";
- document.getElementById('searchPanelBox').style.height = "0";
- }
- }).on('tap', '.tabList div,.tabList span', function(event) {
- /**
- * 自定义切换组件
- * 子元素:
- * class="active" disabled="disabled" data-key="xxx" name="xxx"
- */
- if (document.getElementsByClassName('active') && document.getElementsByClassName(
- 'active')[0]
- .getAttribute('name') !=
- this.dataset.key && !document.getElementsByName(this.dataset.key)[0]
- .getAttribute('disabled')) {
- document.getElementsByName(this.dataset.key)[0].parentNode.getElementsByClassName(
- 'active')[0]
- .className = ""
- document.getElementsByName(this.dataset.key)[0].className = "active";
- if (document.getElementsByName(this.dataset.key) && this.dataset.url) {
- mui.showLoading("正在加载..", "div");
- let dataUrl = JSON.parse(this.dataset.url);
- kanbanData(dataUrl);
- }
- }
- }).on('change', '[required="required"] .formInput', function() {
- if (this.value) {
- // 非空验证通过
- var nextElementSibling = this.nextElementSibling;
- if (nextElementSibling && nextElementSibling.className == 'requiredMsgShow') {
- nextElementSibling.className = 'requiredMsgHide';
- }
- } else {
- // 提示该字段不可为空,或者直接通过js直接修改是否显示为空信息
- var nextElementSibling = this.nextElementSibling;
- if (nextElementSibling && nextElementSibling.className == 'requiredMsgHide') {
- nextElementSibling.className = 'requiredMsgShow';
- }
- }
- }).on('tap', '[customizeName="datePoppicker"]', function(event) {
- /**
- * 自定义时间组件
- * input type="text" readonly
- * customizeName="datePoppicker"
- * name="xxx" 类似id,唯一标识
- * data-key="xxx" 与name属性值一致
- * data-type="xxx" [datetime|date|time|month|hour] 配置详情: https://dev.dcloud.net.cn/mui/ui/#dtpicker
- */
- var dtPicker = new mui.DtPicker(this.dataset.type ? {
- type: this.dataset.type
- } : {
- type: "datetime"
- });
- let that = this;
- dtPicker.show(function(selectItems) {
- if (document.getElementsByName(that.dataset.key)) {
- document.getElementsByName(that.dataset.key)[0].value = selectItems
- .text;
- }
- })
- }).on('tap', '[name="submit"]', function(event) {
- /**
- * 自定义时间组件(提交按钮,自动校验非空字段并检验正确性)
- * div name="submit"
- * 本页面存在input标签且符合class="formInput"
- */
- let formOptionDoms = document.getElementsByClassName('formInput');
- let formOption = {};
- let that = this;
- let verification = true;
- if (formOptionDoms.length > 0) {
- for (let i = 0; i < formOptionDoms.length; i++) {
- // 是否必填
- let required = formOptionDoms[i].parentNode.parentNode.getAttribute('required');
- if (!required || required && formOptionDoms[i].value) {
- // 非空验证通过
- var nextElementSibling = formOptionDoms[i].nextElementSibling;
- if (nextElementSibling && nextElementSibling.className ==
- 'requiredMsgShow') {
- nextElementSibling.className = 'requiredMsgHide';
- }
- } else {
- // 提示该字段不可为空,或者直接通过js直接修改是否显示为空信息
- var nextElementSibling = formOptionDoms[i].nextElementSibling;
- if (nextElementSibling && nextElementSibling.className ==
- 'requiredMsgHide') {
- nextElementSibling.className = 'requiredMsgShow';
- }
- verification = false;
- }
- }
- }
- if (verification) {
- let pageName = this.dataset.pageName;
- mui.openWindow("./" + pageName + ".html", pageName);
- }
- }).on('tap', '[type="picker"]', function(event) {
- /**
- * 自定义下拉框组件
- * div type="picker" name = "xxx" parentOption = "xxx"
- */
- let that = this;
- let parentOptionList = pickerLists[this.getAttribute('parentOption')];
- if (parentOptionList) {
- for (let i = 0; i < parentOptionList.length; i++) {
- if (that.getAttribute('name') == parentOptionList[i].name) {
- let itemData = parentOptionList[i].data;
- let pickerData = [];
- var statePicker = new mui.PopPicker();
- for (let index in itemData) {
- pickerData.push({
- value: itemData[index].label != undefined ? itemData[index]
- .value : itemData[index],
- text: itemData[index].label != undefined ? itemData[index]
- .label : itemData[
- index]
- })
- }
- statePicker.setData(pickerData);
- statePicker.show(function(items) {
- that.innerText = items[0].text;
- if (document.getElementById('pageName')) {
- let pageName = document.getElementById('pageName')
- .innerText;
- dataUrl[pageName].params[that.getAttribute('name')] = items[
- 0].value;
- if (dataUrl[pageName].url) {
- resetPageInfo();
- }
- }
- });
- }
- }
- }
- }).on('tap', '#addImage', function() {
- // 触发文件上传按钮
- document.getElementById("uploadFileInput").click();
- }).on('change', '#uploadFileInput', function(e) {
- // 获取上传的文件列表
- // let mapImageListDom = document.getElementById('mapImageList');
- const file = e.target.files[0]
- if (!/\.(jpg|jpeg|png|JPG|PNG)$/.test(e.target.value)) {
- mui.alert('请上传.png/.jpg/.jpeg格式的图片', '系统提示');
- return false;
- } else {
- fileToBase64Async(file).then(item => {
- let of_image = document.getElementById("of_image");
- of_image.setAttribute('src',item);
- of_image.style.display = "block";
- document.getElementById("addImage").style.display = "none";
- })
- }
- }).on('tap', '.changeLoginTypeToPhone', function() {
- // 首页切换登录方式,为手机号码登录
- console.log("首页切换登录方式,为手机号码登录")
- document.getElementById('loginFormBox').style.display = "none";
- document.getElementById('loginForm2Box').style.display = "block";
- }).on('tap', '.changeLoginTypeToUser', function() {
- // 首页切换登录方式,为账号登录
- console.log("首页切换登录方式,为账号登录")
- document.getElementById('loginForm2Box').style.display = "none";
- document.getElementById('loginFormBox').style.display = "block";
- }).on('change', '#autoLogin', function() {
- isActive = this.checked ? "true" : "false";
- localStorage.setItem('isActive', isActive);
- }).on('tap', '#reSearch', function() {
- // 数据列表刷新,搜索框重置
- mui.confirm("是否重置并刷新?", "系统提示", function(status) {
- if (status.index == 1) {
- clearSearchValue();
- resetPageInfo();
- }
- })
- }).on('tap', '.toBackPage', function() {
- mui.back();
- })
- }
- // 原生请求
- function postRequest(url, setting, funSuccess, funError) {
- if (setting.data) {
- setting.data = JSON.stringify(setting.data);
- }
- requestSettins.success = funSuccess;
- requestSettins.error = funError;
- let newSetting = Object.assign(requestSettins, setting);
- mui.ajax(BASE_RUL + url, newSetting);
- }
- function postRequest2(url, setting, otherParams, funSuccess, funError) {
- try {
- if (setting.data) {
- setting.data = JSON.stringify(setting.data);
- }
- requestSettins2.success = (data) => {
- funSuccess(data, otherParams);
- };
- requestSettins2.error = funError;
- let newSetting = Object.assign(requestSettins2, setting);
- mui.ajax(BASE_RUL + url, newSetting);
- } catch (e) {
- //TODO handle the exception
- console.log("postRequest2 error:", e);
- }
- }
- function dmsPostRequest(url, setting, funSuccess, funError) {
- var xhr = new XMLHttpRequest();
- // 请求成功回调函数
- xhr.onload = e => {
- console.log('request success');
- };
- // 请求结束
- xhr.onloadend = e => {
- console.log('request loadend');
- };
- // 请求出错
- xhr.onerror = e => {
- console.log('request error');
- funError("request error");
- };
- // 请求超时
- xhr.ontimeout = e => {
- console.log('request timeout');
- funError("request timeout");
- };
- xhr.open('POST', DMS_BASE_URL + url, true);
- if (localStorage.getItem("dmsToken")) {
- xhr.setRequestHeader("token", localStorage.getItem("dmsToken"))
- }
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4 && xhr.status == 200) {
- funSuccess(JSON.parse(xhr.responseText));
- }
- }
- xhr.send(setting.data);
- }
- // -------------------------------------------------------------自定义事件
- // 页面自动化配置生效
- function pageInit() {
- let tabBoxs = document.getElementsByClassName('tabBox');
- if (tabBoxs.length > 0) {
- for (let i = 0; i < tabBoxs.length; i++) {
- if (tabBoxs[i].getAttribute('option')) {
- let option_ = formTabOptions[tabBoxs[i].getAttribute('option')];
- if (option_.length > 0) {
- for (let i1 = 0; i1 < option_.length; i1++) {
- let dom = document.createElement('span');
- dom.setAttribute("data-key", option_[i1].lable + option_[i1].key);
- dom.setAttribute("data-url", JSON.stringify(option_[i1].url));
- dom.setAttribute("name", option_[i1].lable + option_[i1].key);
- dom.className = option_[i1].active ? 'active' : '';
- dom.innerText = option_[i1].lable
- tabBoxs[i].appendChild(dom);
- setTimeout(() => {
- if (option_[i1].active) {
- if (mui.showLoading != undefined) {
- mui.showLoading("正在加载..", "div");
- }
- kanbanData(option_[i1].url);
- }
- });
- }
- } else {
- mui.toast('form option:' + tabBoxs[i].getAttribute('option') + 'is undefined!');
- }
- }
- }
- }
- let echartDoms = document.getElementsByClassName('echartDom');
- if (echartDoms.length > 0) {
- for (let index = 0; index < echartDoms.length; index++) {
- let domId = echartDoms[index].getAttribute('id');
- let option = options[domId];
- if (option) {
- initEchart(domId, option, false);
- }
- }
- }
- if (document.getElementById('searchInput')) {
- // 存在搜索框的话开始监听{focus:获取焦点,input:内容修改,blur:失去焦点}
- document.getElementById('searchInput').addEventListener('focus', function(event) {
- if (document.getElementById('searchPanelBox')) {
- document.getElementsByClassName('mui-icon-clear')[0].style.right = "2rem";
- document.getElementById('searchInput').style.width = "calc(100% - 4rem)"
- document.getElementById('muiSearchCancel').style.display = "block";
- }
- // 展开搜索结果框
- homeSearch();
- })
- document.getElementById('searchInput').addEventListener('input', function(event) {
- if (document.getElementById('searchPanelBox')) {
- document.getElementsByClassName('mui-icon-clear')[0].style.right = "3rem";
- document.getElementById('searchInput').style.width = "calc(100% - 3rem)"
- document.getElementById('muiSearchCancel').style.display = "block";
- }
- // 展开搜索结果框
- homeSearch();
- })
- document.getElementById('searchInput').addEventListener('keypress', function(event) {
- if (event.keyCode == 13) {
- document.activeElement.blur(); // 收起模拟键盘
- // 展开搜索结果框
- if (document.getElementById('searchPanelBox')) {
- homeSearch();
- } else {
- resetPageInfo();
- }
- event.preventDefault(); // 阻止页面刷新
- }
- })
- }
- let formBoxs = document.getElementsByClassName('form-box');
- if (formBoxs.length > 0) {
- for (let i = 0; i < formBoxs.length; i++) {
- if (formBoxs[i].getAttribute('option')) {
- console.log("初始化表单", formBoxs[i].getAttribute('option'))
- let option_ = formOptions[formBoxs[i].getAttribute('option')];
- let dom = document.createElement('div');
- dom.innerHTML = `<div class="form-title">${formBoxs[i].getAttribute('title')}</div>`;
- formBoxs[i].appendChild(dom);
- if (option_.length > 0) {
- for (let i1 = 0; i1 < option_.length; i1++) {
- let doms = document.createElement('div');
- doms.innerHTML = `
- <div class="row" title="${option_[i1].title}" ${option_[i1].required ? 'required="required"' : ''}>
- <div>${option_[i1].title}</div>
- <div>
- <input class="formInput" name="${option_[i1].name}" data-key="${option_[i1].name}" ${option_[i1].customizeName ? 'customizeName="'+option_[i1].customizeName+'"' : ''} type="text">
- ${option_[i1].required ? '<p class="requiredMsgHide">'+option_[i1].title+'不能为空</p>' : ''}
- </div>
- </div>`;
- formBoxs[i].appendChild(doms);
- }
- } else {
- mui.toast('form option:' + formBoxs[i].getAttribute('option') + 'is undefined!');
- }
- }
- }
- }
- let formTabBoxs = document.getElementsByClassName('form-list-box');
- if (formTabBoxs.length > 0) {
- for (let i = 0; i < formTabBoxs.length; i++) {
- if (formTabBoxs[i].getAttribute('option')) {
- let option_ = formTabOptions[formTabBoxs[i].getAttribute('option')];
- if (option_.length > 0) {
- for (let i1 = 0; i1 < option_.length; i1++) {
- let dom = document.createElement('div');
- dom.className = "form-row tabList";
- let datas = option_[i1].data;
- for (let i2 = 0; i2 < datas.length; i2++) {
- dom.innerHTML +=
- `<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>`;
- }
- formTabBoxs[i].appendChild(dom);
- }
- } else {
- mui.toast('form option:' + formTabBoxs[i].getAttribute('option') + 'is undefined!');
- }
- }
- }
- }
- let pickerBoxs = document.getElementsByClassName('pickerBox');
- if (pickerBoxs.length > 0) {
- for (let i = 0; i < pickerBoxs.length; i++) {
- if (pickerBoxs[i].getAttribute('option') && pickerLists[pickerBoxs[i].getAttribute(
- 'option')]) {
- let pickerOptions = pickerLists[pickerBoxs[i].getAttribute('option')];
- if (pickerOptions.length > 0) {
- for (let i2 = 0; i2 < pickerOptions.length; i2++) {
- let pickerOption_ = pickerOptions[i2];
- let pickerDom = document.createElement('div');
- pickerDom.setAttribute('name', pickerOption_.name);
- pickerDom.setAttribute('type', 'picker');
- pickerDom.setAttribute('parentOption', pickerBoxs[i].getAttribute('option'));
- pickerDom.innerText = pickerOption_.label;
- pickerBoxs[i].appendChild(pickerDom);
- }
- }
- } else {
- mui.toast('picker option:' + pickerBoxs[i].getAttribute('option') + 'is undefined!');
- }
- }
- }
- }
- // 看板页面初始化配置mui请求
- function muiPageInit() {
- // mui请求
- let myTaskListDom = document.getElementById('myTaskListDom');
- if (myTaskListDom) {
- getMoveMyTaskList();
- myTaskListDom.addEventListener('scroll', function(event) {
- //scrollTop是滚动条滚动时,距离顶部的距离
- var scrollTop = myTaskListDom.scrollTop || document.body.scrollTop;
- //windowHeight是可视区的高度
- var windowHeight = myTaskListDom.clientHeight || document.body.clientHeight;
- //scrollHeight是滚动条的总高度
- var scrollHeight = myTaskListDom.scrollHeight || document.body.scrollHeight;
- //滚动条到底部的条件
- let scrollBottom = scrollHeight - scrollTop - windowHeight;
- if (scrollBottom == 0 && (allCount > page * pageSize)) {
- getMoveMyTaskList();
- }
- })
- }
- // mui请求
- // 如果在首页,先填充保存的用户名和密码,如果有token则进行token校验,通过提示欢迎回来
- if (document.getElementById('autoLogin')) {
- if (isActive) {
- document.getElementById('userName').value = localStorage.key('userName') ? localStorage
- .getItem(
- 'userName') : '';
- document.getElementById('passWord').value = localStorage.key('passWord') ? localStorage
- .getItem(
- 'passWord') : '';
- }
- document.getElementById('autoLogin').checked = isActive;
- if (localStorage.getItem('token') != null) {
- postRequest2(getUserInfoUrl, {}, null, function success(res, params) {
- if (res.code == 200) {
- mui.toast('欢迎回来', '系统提示');
- mui.openWindow("pages/homeNew.html", "homeNew");
- } else {
- localStorage.removeItem("token");
- }
- }, function error(xhr, type, errorThrown) {
- mui.alert('系统异常!请联系开发人员!', '系统提示');
- });
- }
- }
- }
- // 用户登录
- function apiLogin(setting, funSuccess, funError) {
- postRequest(loginUrl, setting, funSuccess, funError);
- }
- // dms获取token
- function getDmsToken() {
- let paramData = new FormData();
- paramData.append("userName", "user001");
- paramData.append("password", "1234567890");
- paramData.append("clientId", "1");
- dmsPostRequest(dmsLoginUrl, {
- data: paramData,
- dataType: "json"
- }, function success(res) {
- console.log("getDmsToken:", res);
- if (res.code == "200") {
- localStorage.setItem("dmsToken", res.message);
- }
- }, function error(xhr, type, errorThrown) {
- mui.alert('DMS系统异常!请联系开发人员!', '系统提示');
- })
- }
- // 首页搜索弹窗事件
- function homeSearch() {
- if (document.getElementById('searchPanelBox')) {
- let searchPanelBoxDom = document.getElementById('searchPanelBox');
- let searchPanelBoxDomInnerHTML = ``;
- let paramValue = document.getElementById('searchInput').value;
- for (let key in menuList) {
- searchPanelBoxDomInnerHTML += `<h5>${key}</h5>
- <div>`;
- for (let i = 0; i < menuList[key].length; i++) {
- if (menuList[key][i].name.indexOf(paramValue) != -1) {
- if (menuList[key][i].pageName) {
- searchPanelBoxDomInnerHTML += `<div class="menuLocalPage" data-page-name="${menuList[key][i].pageName}" menuName="${menuList[key][i].name}">
- <div></div>${menuList[key][i].name}
- </div>`;
- }
- }
- }
- searchPanelBoxDomInnerHTML += `</div>`;
- }
- searchPanelBoxDom.innerHTML = searchPanelBoxDomInnerHTML;
- searchPanelBoxDom.style.height = "calc(100vh - 6.5rem)";
- }
- }
- // 登录请求
- function login() {
- let docUserName = document.getElementById('userName').value;
- let docPassword = document.getElementById('passWord').value;
- if (!docUserName) {
- mui.alert('请输入用户名!', '表单校验', function() {
- return false;
- });
- return false;
- }
- if (!docPassword) {
- mui.alert('请输入密码!', '表单校验', function() {
- return false;
- });
- return false;
- }
- // 登录请求
- if (docUserName && docPassword) {
- let param = {
- username: docUserName,
- password: docPassword
- }
- // 开始请求登录接口
- apiLogin({
- data: param
- }, function success(res, textStatus, xhr) {
- if (res.code == 200) {
- // 如果用户选中了记住密码,则保存账户信息
- if (isActive) {
- localStorage.setItem('userName', docUserName);
- localStorage.setItem('passWord', docPassword);
- }
- // 缓存登录状态主要信息
- localStorage.setItem("userId", res.data.userInfo.id);
- localStorage.setItem("userName", res.data.userInfo.userName);
- localStorage.setItem("token", res.data.token);
- // 跳转到主页
- mui.openWindow({
- url: "pages/homeNew.html",
- id: "homeNew",
- createNew: true
- });
- } else {
- mui.alert(res.msg ? res.msg : '登录失败!', '系统提示');
- }
- }, function error(xhr, type, errorThrown) {
- mui.alert('登录失败!', '系统提示');
- });
- }
- }
- // 看板数据初始化(主要是echart的自动化配置比较复杂)
- function kanbanData(url) {
- let outEchartBoxDom = document.getElementById('outEchartBox');
- outEchartBoxDom.innerHTML = "";
- // 数据指标
- if (url.countUrl) {
- let params = {};
- if (url.countParams) {
- params = {
- data: url.countParams
- };
- }
- postRequest2(url.countUrl, params, url.countList, function success(res, otherParams) {
- if (res.code == 200) {
- for (let i = 0; i < 4; i++) {
- document.getElementById('countTitle' + i).innerText = otherParams[i];
- document.getElementById('countValue' + i).innerText = res.data.list[i]
- .value;
- if (res.data.list[i].compare != undefined) {
- document.getElementById('countValue' + i).innerText = res.data.list[i]
- .value;
- document.getElementById('countValue' + i).className = "";
- document.getElementById('countCompare' + i).innerHTML = `同比 <span class="${res.data.list[i].compare > 0 ? 'monthOnMonth2' : 'monthOnMonth0'}">
- ${res.data.list[i].compare + "%"}
- </span>`
- } else {
- document.getElementById('countValue' + i).innerText = res.data.list[i]
- .value + "%";
- if (res.data.list[i].value > 0) {
- document.getElementById('countValue' + i).className = "trend1";
- } else if (res.data.list[i].value < 0) {
- document.getElementById('countValue' + i).className = "trend0";
- }
- document.getElementById('countCompare' + i).innerText = '';
- }
- }
- document.getElementById('worthAttention').innerText = res.data.worthAttention;
- if (url.listUrl) {
- for (let i_ = 0; i_ < url.listUrl.length; i_++) {
- let params = {};
- let listUrlItem = url.listUrl[i_];
- if (listUrlItem.params) {
- params = {
- data: listUrlItem.params
- };
- }
- let echartBox = document.createElement('div');
- echartBox.innerHTML = `<h4 style="padding-left: 10px;" class="echartTitle">${listUrlItem.title}</h4>
- <div class="echartBox">
- <div class="echartDom" id="${listUrlItem.echartDomId}"></div>
- </div>`;
- document.getElementById('outEchartBox').append(echartBox);
- setTimeout(() => {
- postRequest2(listUrlItem.url, params, listUrlItem,
- function success2(
- res2, otherParams) {
- if (res2.code == 200) {
- if (otherParams.jsonObject) {
- let echartData = {
- xData: []
- }
- echartData.echartJsonObject =
- otherParams
- .jsonObject;
- echartData.serverData = {};
- for (let key in otherParams
- .jsonObject) {
- echartData.serverData[key] = []
- }
- for (let i2 = 0; i2 < res2.data
- .length; i2++) {
- let item = res2.data[i2];
- echartData.xData.push(item.label);
- for (let key in otherParams
- .jsonObject) {
- echartData.serverData[key].push(
- item
- .jsonObject[key]);
- }
- }
- let option = options[otherParams
- .echartDomId];
- option.legend.data = [];
- option.color = [];
- option.xAxis[0].data = echartData.xData;
- option.xAxis[0].name = otherParams
- .xAxisName;
- option.yAxis = [];
- if (otherParams.yAxisName) {
- option.yAxis = [{
- type: 'value',
- name: otherParams
- .yAxisName,
- axisLine: {
- show: true,
- },
- }];
- }
- option.legend.selected = {};
- option.series = [];
- for (let serverItemKey in echartData
- .echartJsonObject) {
- let type = "line";
- if (echartData.echartJsonObject[
- serverItemKey]
- .hideSelected) {
- option.legend.selected[
- echartData
- .echartJsonObject[
- serverItemKey]
- .seriesName] =
- false;
- }
- if (otherParams.series) {
- type = otherParams.series[
- serverItemKey]
- .type;
- let yAxisItem = {
- type: "value",
- name: otherParams
- .series[
- serverItemKey]
- .yAxisName,
- position: otherParams
- .series[
- serverItemKey]
- .position,
- axisLine: {
- show: true,
- lineStyle: {
- color: echartData
- .echartJsonObject[
- serverItemKey
- ].color
- }
- }
- }
- option.yAxis.push(yAxisItem);
- }
- let seriesItem = {
- name: echartData
- .echartJsonObject[
- serverItemKey]
- .seriesName,
- type: type,
- smooth: true,
- lineStyle: {
- width: 0
- },
- // showSymbol: false,
- yAxisIndex: otherParams
- .series &&
- otherParams.series[
- serverItemKey]
- .yAxisIndex ?
- otherParams.series[
- serverItemKey]
- .yAxisIndex : 0,
- areaStyle: {
- opacity: 0.8,
- color: echartData
- .echartJsonObject[
- serverItemKey]
- .noLinearGradient ?
- echartData
- .echartJsonObject[
- serverItemKey]
- .color : new echarts
- .graphic
- .LinearGradient(0,
- 0, 0,
- 1, [{
- offset: 0,
- color: echartData
- .echartJsonObject[
- serverItemKey
- ]
- .color
- },
- {
- offset: 1,
- color: '#FFFFFF'
- }
- ])
- },
- emphasis: {
- focus: 'series'
- },
- data: echartData.serverData[
- serverItemKey]
- }
- if (!otherParams.series || !
- otherParams.series[
- serverItemKey].stack ==
- false) {
- seriesItem.stack = 'Total';
- }
- if (otherParams.series &&
- otherParams.series[
- serverItemKey].itemStyle) {
- seriesItem.itemStyle =
- otherParams.series[
- serverItemKey]
- .itemStyle;
- }
- if (otherParams.series &&
- otherParams.series[
- serverItemKey].barWidth) {
- seriesItem.barWidth =
- otherParams.series[
- serverItemKey].barWidth;
- }
- option.series.push(seriesItem);
- option.legend.data.push(echartData
- .echartJsonObject[
- serverItemKey]
- .seriesName);
- option.color.push(echartData
- .echartJsonObject[
- serverItemKey].color);
- }
- initEchart(otherParams.echartDomId,
- option, true);
- } else {
- let option = options[otherParams
- .echartDomId];
- option.series[0].data = res2.data;
- if (otherParams.labelFormatter) {
- option.series[0].label.formatter =
- otherParams
- .labelFormatter;
- }
- initEchart(otherParams.echartDomId,
- option, true);
- }
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- } else {
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- initEchart(otherParams.echartDomId, null,
- true);
- }
- },
- function error2(xhr, type, errorThrown) {
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- mui.alert('系统异常!请联系开发人员!', '系统提示');
- });
- })
- }
- }
- } else {
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- if (res.msg == "当前未登录" || res.msg == "请登录后重试" || res.msg == "登录失效") {
- if (mui.plus) {
- mui.alert(resJson.msg, '系统提示', function() {
- localStorage.removeItem("token");
- mui.openWindow("../index.html", "login");
- });
- } else {
- localStorage.removeItem("token");
- mui.openWindow("../index.html", "login");
- }
- }
- }
- }, function error(xhr, type, errorThrown) {
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- mui.alert('系统异常!请联系开发人员!', '系统提示');
- });
- }
- }
- // 注销登录
- function loginOut() {
- postRequest(logoutUrl, {}, function success(res, textStatus, xhr) {
- if (res.code == 200) {
- mui.toast('退出成功', '系统提示');
- localStorage.removeItem("token");
- mui.openWindow("../index.html", "login");
- }
- }, function error(xhr, type, errorThrown) {
- mui.alert('系统异常!请联系开发人员!', '系统提示');
- });
- }
- // 请求我的任务列表(下一页)
- function getMoveMyTaskList() {
- page_e = this;
- getMyTaskList();
- }
- // 清空搜索框值
- function clearSearchValue() {
- if (document.getElementById('searchInput')) {
- document.getElementById('searchInput').value = null;
- }
- }
- // 重置页面信息并查询
- function resetPageInfo() {
- allCount = 0;
- pageSize = 20;
- page = 0;
- // 删除数据列表
- if (document.getElementsByClassName('dataItem4').length > 0) {
- let displayFlexDoms = document.getElementsByClassName('dataItem4');
- const displayFlexDomsSize = displayFlexDoms.length;
- if (displayFlexDomsSize > 0) {
- for (let index = 0; index < displayFlexDomsSize; index++) {
- if (displayFlexDoms[0]) {
- displayFlexDoms[0].remove();
- }
- }
- }
- }
- // 重新请求数据
- getMyTaskList();
- if (document.getElementById('listMoveDom')) {
- // mui('#listMoveDom').pullRefresh().refresh(true);
- }
- };
- /**
- * file 转Base64 DataURL
- * @param {File} file
- * @returns
- */
- function fileToBase64Async(file) {
- return new Promise((resolve, reject) => {
- let reader = new FileReader();
- reader.readAsDataURL(file);
- reader.onload = (e) => {
- resolve(e.target.result);
- };
- });
- }
- // 请求数据列表
- function getMyTaskList() {
- if (mui.showLoading != undefined) {
- mui.showLoading("正在加载..", "div");
- }
- sessionStorage.clear();
- // 首先获取页面标志
- let pageName = document.getElementById('pageName').innerText;
- dataUrl[pageName].params.pageStart = (page) * pageSize;
- postRequest2(dataUrl[pageName].url, {
- data: dataUrl[pageName].params
- }, {}, function funSuccess(res, params) {
- let resJson = res;
- try {
- if (resJson.code == 200 && resJson.data != null) {
- allCount = resJson.data.total;
- if (resJson.data.data && resJson.data.data.length > 0) {
- let listDom = document.getElementById('myTaskListDom');
- for (let i = 0; i < resJson.data.data.length; i++) {
- let moveDom = document.createElement('div');
- moveDom.className = "dataItem4 borderBottom";
- moveDom.setAttribute("data-messageId", resJson.data.data[i].id);
- moveDom.setAttribute("readStatus", resJson.data.data[i].status);
- moveDom.innerHTML = `<div>
- <span class="title">${resJson.data.data[i].title ? resJson.data.data[i].title : resJson.data.data[i].type}</span>
- <p>${resJson.data.data[i].time}</p>
- <div class="content">
- ${resJson.data.data[i].content}
- </div>
- </div>`;
- listDom.insertBefore(moveDom, document.getElementById(
- 'listMoveDom'));
- }
- }
- // 分页配置
- if (page_e) {
- if (allCount > (page + 1) * pageSize) {
- document.getElementById("upTitle").innerHTML = "上拉加载更多……";
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- // page_e.endPullupToRefresh(false);
- } else {
- mui.toast('没有更多数据了');
- document.getElementById("upTitle").innerHTML = "没有更多数据了";
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- }
- } else {
- console.log('page_e is null!')
- }
- page++;
- } else {
- // 请求失败!
- document.getElementById("upTitle").innerHTML = resJson.msg;
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- if (resJson.msg === "当前未登录" || resJson.msg === "请登录后重试" || res.msg == "登录失效") {
- if (mui.plus) {
- mui.alert(resJson.msg, '系统提示', function() {
- localStorage.removeItem("token");
- mui.openWindow("../index.html", "login");
- });
- } else {
- localStorage.removeItem("token");
- mui.openWindow("../index.html", "login");
- }
- }
- }
- } catch (e) {
- // 处理异常
- //TODO handle the exception
- mui.alert('try处理异常!' + e, '系统提示', function() {
- document.getElementById("upTitle").innerHTML = "处理异常!";
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- });
- }
- }, function error(xhr, type, errorThrown) {
- // request异常
- mui.alert('请求失败!' + JSON.stringify(xhr), '系统提示', function() {
- document.getElementById("upTitle").innerHTML = "请求失败!";
- if (mui.hideLoading != undefined)(
- mui.hideLoading()
- );
- });
- });
- };
- // echart初始化
- function initEchart(chartDomId, option, state) {
- var chartDom = document.getElementById(chartDomId);
- try {
- if (state) {
- echarts.init(chartDom).dispose();
- }
- if (option) {
- echarts.init(chartDom).setOption(option);
- }
- } catch (e) {
- //TODO handle the exception
- console.log(chartDomId, "dispose error", e);
- }
- }
- // 获取设备类型,后续很有可能会用到
- let deviceType = "ios";
- if (mui.os.ios) {
- console.log('苹果设备', 'version:' + mui.os.version, 'iphone:' + mui.os.iphone, 'ipad:' + mui.os.ipad);
- deviceType = "ios";
- } else if (mui.os.android) {
- console.log('安卓设备', 'version:' + mui.os.version, 'isBadAndroid:' + mui.os.isBadAndroid);
- deviceType = "android";
- }
- pageInit();
- if (SYSTEM_ENVIRONMENT == "android") {
- mui.plusReady(function() {
- if (plus) {
- console.log("plus初始化成功!")
- plusStatus = true;
- mui.init();
- muiInit();
- muiPageInit();
- }
- }, true);
- } else {
- mui.init();
- muiInit();
- muiPageInit();
- }
|