/* * 版 本 Learun-ADMS V7.0.0 数字化智慧校园(http://www.learun.cn) * Copyright (c) 2013-2017 北京泉江科技有限公司 * 创建人:数字化智慧校园-前端开发组 * 日 期:2018.7.12 * 描 述:数字化智慧校园移动端框架(ADMS) 数字化智慧校园移动框架方法扩展 */ (function ($, learun) { "use strict"; // http 方法(加了登录信息) learun.httpget = function (url, data, callback) { var param = {}; var logininfo = learun.storage.get('logininfo'); if (!logininfo) { callback(null); return false; } param.token = logininfo.token; param.loginMark = learun.deviceId(); var type = learun.type(data); if (type === 'object' || type === 'array') { param.data = JSON.stringify(data); } else if (type === 'string') { param.data = data; } learun.http.get(url, param, function (res) { if (res === null) { learun.layer.toast('无法连接服务器,请检测网络!'); callback(null); } else if (res.code === 410) { callback(null); if (!learun.isOutLogin) { learun.isOutLogin = true; learun.layer.toast('登录过期,请重新登录!'); learun.storage.set('logininfo', null); learun.nav.go({ path: 'login', isBack: false, isHead: false }); } } else { if (res.code === 200) { callback(res.data); } else { callback(null); learun.layer.toast(res.info); } } }); }; learun.httpgetnosy = function (url, data, callback) { var param = {}; var logininfo = learun.storage.get('logininfo'); if (!logininfo) { callback(null); return false; } param.token = logininfo.token; param.loginMark = learun.deviceId(); var type = learun.type(data); if (type === 'object' || type === 'array') { param.data = JSON.stringify(data); } else if (type === 'string') { param.data = data; } learun.http.getNoAsyno(url, param, function (res) { if (res === null) { learun.layer.toast('无法连接服务器,请检测网络!'); callback(null); } else if (res.code === 410) { callback(null); if (!learun.isOutLogin) { learun.isOutLogin = true; learun.layer.toast('登录过期,请重新登录!'); learun.storage.set('logininfo', null); learun.nav.go({ path: 'login', isBack: false, isHead: false }); } } else { if (res.code === 200) { callback(res.data); } else { callback(null); learun.layer.toast(res.info); } } }); }; learun.httppost = function (url, data, callback) { var param = {}; var logininfo = learun.storage.get('logininfo'); if (!logininfo) { callback(null); return false; } param.token = logininfo.token; param.loginMark = learun.deviceId(); var type = learun.type(data); if (type === 'object' || type === 'array') { param.data = JSON.stringify(data); } else if (type === 'string') { param.data = data; } learun.http.post(url, param, function (res) { if (res === null) { learun.layer.toast('无法连接服务器,请检测网络!'); callback(null); } else if (res.code === 410) { callback(null); if (!learun.isOutLogin) { learun.isOutLogin = true; learun.layer.toast('登录过期,请重新登录!'); learun.storage.set('logininfo', null); learun.nav.go({ path: 'login', isBack: false, isHead: false }); } } else { if (res.code === 200) { callback(res.data, res.info); } else { callback(null); learun.layer.toast(res.info); } } }); }; learun.httppostnoLogin = function (url, data, callback) { var param = {}; var type = learun.type(data); if (type === 'object' || type === 'array') { param.data = JSON.stringify(data); } else if (type === 'string') { param.data = data; } learun.http.post(url, param, function (res) { if (res === null) { learun.layer.toast('无法连接服务器,请检测网络!'); callback(null); } else if (res.code === 410) { callback(null); if (!learun.isOutLogin) { learun.isOutLogin = true; learun.layer.toast('登录过期,请重新登录!'); learun.storage.set('logininfo', null); learun.nav.go({ path: 'login', isBack: false, isHead: false }); } } else { if (res.code === 200) { callback(res.data, res.info); } else { callback(null); learun.layer.toast(res.info); } } }); }; // 获取后台信息(基础信息) var loadSate = { no: -1, // 还未加载 yes: 1, // 已经加载成功 ing: 0, // 正在加载中 fail: 2 // 加载失败 }; var clientAsyncData = {}; learun.clientdata = { init: function () { clientAsyncData.company.init(); }, get: function (name, op) {// return clientAsyncData[name].get(op); }, getAll: function (name, op) {// return clientAsyncData[name].getAll(op); }, clear: function (name) { clientAsyncData[name].states = loadSate.no; } }; // 公司信息 clientAsyncData.company = { states: loadSate.no, init: function () { if (clientAsyncData.company.states === loadSate.no) { clientAsyncData.company.states = loadSate.ing; var data = learun.storage.get("companyData") || {}; var ver = data.ver || ""; learun.httpget(config.webapi + "learun/adms/company/map", { ver: ver }, function (data) { if (data) { if (data.ver) { learun.storage.set("companyData", data); } clientAsyncData.company.states = loadSate.yes; clientAsyncData.department.init(); } else { clientAsyncData.company.states = loadSate.fail; } }); } }, get: function (op) { clientAsyncData.company.init(); if (clientAsyncData.company.states === loadSate.ing) { setTimeout(function () { clientAsyncData.company.get(op); }, 100);// 如果还在加载100ms后再检测 } else { var _dataTmp = learun.storage.get("companyData") || {}; var data = _dataTmp.data || {}; op.callback(data[op.key] || {}, op); } }, getAll: function (op) { clientAsyncData.company.init(); if (clientAsyncData.company.states === loadSate.ing) { setTimeout(function () { clientAsyncData.company.getAll(op); }, 100);// 如果还在加载100ms后再检测 } else { var _dataTmp = learun.storage.get("companyData") || {}; var data = _dataTmp.data || {}; op.callback(data, op); } } }; // 获取桌面配置信息 clientAsyncData.desktop = { states: loadSate.no, init: function () { if (clientAsyncData.desktop.states === loadSate.no) { clientAsyncData.desktop.states = loadSate.ing; var data = learun.storage.get("desktopData") || {}; var ver = data.ver || ""; learun.httpget(config.webapi + "learun/adms/desktop/setting", { ver: ver }, function (data) { if (data) { if (data.ver) { learun.storage.set("desktopData", data); } clientAsyncData.desktop.states = loadSate.yes; } else { clientAsyncData.desktop.states = loadSate.fail; } }); } }, get: function (op) { clientAsyncData.desktop.init(); if (clientAsyncData.desktop.states === loadSate.ing) { setTimeout(function () { clientAsyncData.desktop.get(op); }, 100);// 如果还在加载100ms后再检测 } else { var _tmpData = learun.storage.get("desktopData"); var data = _tmpData.data || {}; op.callback(data, op); } } }; // 部门信息 clientAsyncData.department = { states: loadSate.no, init: function () { if (clientAsyncData.department.states === loadSate.no) { clientAsyncData.department.states = loadSate.ing; var data = learun.storage.get("departmentData") || {}; var ver = data.ver || ""; learun.httpget(config.webapi + "learun/adms/department/map", { ver: ver }, function (data) { if (data) { if (data.ver) { learun.storage.set("departmentData", data); } clientAsyncData.department.states = loadSate.yes; clientAsyncData.user.init(); } else { clientAsyncData.department.states = loadSate.fail; } }); } }, get: function (op) { clientAsyncData.department.init(); if (clientAsyncData.department.states === loadSate.ing) { setTimeout(function () { clientAsyncData.department.get(op); }, 100);// 如果还在加载100ms后再检测 } else { var _dataTmp = learun.storage.get("departmentData") || {}; var data = _dataTmp.data || {}; op.callback(data[op.key] || {}, op); } }, getAll: function (op) { clientAsyncData.department.init(); if (clientAsyncData.department.states === loadSate.ing) { setTimeout(function () { clientAsyncData.department.getAll(op); }, 100);// 如果还在加载100ms后再检测 } else { var _dataTmp = learun.storage.get("departmentData") || {}; var data = _dataTmp.data || {}; op.callback(data, op); } } }; // 人员信息 clientAsyncData.user = { states: loadSate.no, init: function () { if (clientAsyncData.user.states === loadSate.no) { clientAsyncData.user.states = loadSate.ing; var data = learun.storage.get("userData") || {}; var ver = data.ver || ""; learun.httpget(config.webapi + "learun/adms/user/map", { ver: ver }, function (data) { if (data) { if (data.ver) { learun.storage.set("userData", data); } clientAsyncData.user.states = loadSate.yes; clientAsyncData.dataItem.init(); } else { clientAsyncData.user.states = loadSate.fail; } }); } }, get: function (op) { clientAsyncData.user.init(); if (clientAsyncData.user.states === loadSate.ing) { setTimeout(function () { clientAsyncData.user.get(op); }, 100);// 如果还在加载100ms后再检测 } else { var _dataTmp = learun.storage.get("userData") || {}; var data = _dataTmp.data || {}; op.callback(data[op.key] || {}, op); } }, getAll: function (op) { clientAsyncData.user.init(); if (clientAsyncData.user.states === loadSate.ing) { setTimeout(function () { clientAsyncData.user.getAll(op); }, 100);// 如果还在加载100ms后再检测 } else { var _dataTmp = learun.storage.get("userData") || {}; var data = _dataTmp.data || {}; op.callback(data, op); } } }; // 数据字典 clientAsyncData.dataItem = { states: loadSate.no, init: function () { if (clientAsyncData.dataItem.states === loadSate.no) { clientAsyncData.dataItem.states = loadSate.ing; var data = learun.storage.get("dataItemData") || {}; var ver = data.ver || ""; learun.httpget(config.webapi + "learun/adms/dataitem/map", { ver: ver }, function (data) { if (data) { if (data.ver) { learun.storage.set("dataItemData", data); } clientAsyncData.dataItem.states = loadSate.yes; } else { clientAsyncData.dataItem.states = loadSate.fail; } }); } }, get: function (op) { clientAsyncData.dataItem.init(); if (clientAsyncData.dataItem.states === loadSate.ing) { setTimeout(function () { clientAsyncData.dataItem.get(op); }, 100);// 如果还在加载100ms后再检测 } else { var _dataTmp = learun.storage.get("dataItemData") || {}; var data = _dataTmp.data || {}; op.callback(clientAsyncData.dataItem.find(op.key, data[op.code] || {}) || {}, op); } }, getAll: function (op) { clientAsyncData.dataItem.init(); if (clientAsyncData.dataItem.states === loadSate.ing) { setTimeout(function () { clientAsyncData.dataItem.getAll(op); }, 100);// 如果还在加载100ms后再检测 } else { var _dataTmp = learun.storage.get("dataItemData") || {}; var data = _dataTmp.data || {}; op.callback(data[op.code] || {}, op); } }, loadnologin: function (code) { var _tmpData = learun.storage.get("sourceData_" + code) || {}; if (!_tmpData.data) { var params = { code: code }; var param = {}; var type = learun.type(params); if (type === 'object' || type === 'array') { param.data = JSON.stringify(params); } else if (type === 'string') { param.data = params; } // $.get(config.webapi + "learun/nologin/adms/datasource/map", param, function (res) { // if (res.code == 200) { // if (res.data) { // if (res.data.ver) { // learun.storage.set("sourceData_" + code, res.data); // } // clientAsyncData.sourceData.states[code] = loadSate.yes; // } // else { // clientAsyncData.sourceData.states[code] = loadSate.fail; // } // } // }) $.ajax({ url: config.webapi + "learun/nologin/adms/datasource/itemmap", data: param, type: "get", dataType: "json", async: false, success: function (res) { if (res.code == 200) { if (res.data) { if (res.data.ver) { learun.storage.set("dataItemData", res.data); } clientAsyncData.dataItem.states = loadSate.yes; } else { clientAsyncData.dataItem.states = loadSate.fail; } } } }); } }, find: function (key, data) { var res = {}; for (var id in data) { if (data[id].value === key) { res = data[id]; break; } } return res; } }; // 数据源数据 clientAsyncData.sourceData = { states: {}, get: function (op) { if (clientAsyncData.sourceData.states[op.code] === undefined || clientAsyncData.sourceData.states[op.code] === loadSate.no) { clientAsyncData.sourceData.states[op.code] = loadSate.ing; clientAsyncData.sourceData.load(op.code); } if (clientAsyncData.sourceData.states[op.code] === loadSate.ing) { setTimeout(function () { clientAsyncData.sourceData.get(op); }, 100);// 如果还在加载100ms后再检测 } else { var _tmpData = learun.storage.get("sourceData_" + op.code) || {}; var data = _tmpData.data || []; if (data) { op.callback(clientAsyncData.sourceData.find(op.key, op.keyId, data) || {}, op); } else { op.callback({}, op); } } }, getAll: function (op) { if (clientAsyncData.sourceData.states[op.code] === undefined || clientAsyncData.sourceData.states[op.code] === loadSate.no) { clientAsyncData.sourceData.states[op.code] = loadSate.ing; clientAsyncData.sourceData.load(op.code); } if (clientAsyncData.sourceData.states[op.code] === loadSate.ing) { setTimeout(function () { clientAsyncData.sourceData.getAll(op); }, 100);// 如果还在加载100ms后再检测 } else { var _tmpData = learun.storage.get("sourceData_" + op.code) || {}; var data = _tmpData.data || []; if (data) { op.callback(data, op); } else { op.callback({}, op); } } }, loadnologin: function (code) { var _tmpData = learun.storage.get("sourceData_" + code) || {}; if (!_tmpData.data) { var params = { code: code }; var param = {}; var type = learun.type(params); if (type === 'object' || type === 'array') { param.data = JSON.stringify(params); } else if (type === 'string') { param.data = params; } // $.get(config.webapi + "learun/nologin/adms/datasource/map", param, function (res) { // if (res.code == 200) { // if (res.data) { // if (res.data.ver) { // learun.storage.set("sourceData_" + code, res.data); // } // clientAsyncData.sourceData.states[code] = loadSate.yes; // } // else { // clientAsyncData.sourceData.states[code] = loadSate.fail; // } // } // }) $.ajax({ url: config.webapi + "learun/nologin/adms/datasource/map", data: param, type: "get", dataType: "json", async: false, success: function (res) { if (res.code == 200) { if (res.data) { if (res.data.ver) { learun.storage.set("sourceData_" + code, res.data); } clientAsyncData.sourceData.states[code] = loadSate.yes; } else { clientAsyncData.sourceData.states[code] = loadSate.fail; } } } }) } }, load: function (code) { var data = learun.storage.get("sourceData_" + code) || {}; var ver = data.ver || ""; learun.httpget(config.webapi + "learun/adms/datasource/map", { code: code, ver: ver }, function (data) { if (data) { if (data.ver) { learun.storage.set("sourceData_" + code, data); } clientAsyncData.sourceData.states[code] = loadSate.yes; } else { clientAsyncData.sourceData.states[code] = loadSate.fail; } }); }, find: function (key, keyId, data) { var res = {}; for (var i = 0, l = data.length; i < l; i++) { if (data[i][keyId] === key) { res = data[i]; break; } } return res; } }; // 自定义数据 var custmerData = {}; clientAsyncData.custmerData = { states: {}, get: function (op) { if (clientAsyncData.custmerData.states[op.url] === undefined || clientAsyncData.custmerData.states[op.url] === loadSate.no) { clientAsyncData.custmerData.states[op.url] = loadSate.ing; clientAsyncData.custmerData.load(op.url); } if (clientAsyncData.custmerData.states[op.url] === loadSate.ing) { setTimeout(function () { clientAsyncData.custmerData.get(op); }, 100);// 如果还在加载100ms后再检测 } else { var data = custmerData[op.url]; if (data) { op.callback(clientAsyncData.custmerData.find(op.key, op.keyId, data) || {}, op); } else { op.callback({}, op); } } }, getAll: function (op) { if (clientAsyncData.custmerData.states[op.url] === undefined || clientAsyncData.custmerData.states[op.url] === loadSate.no) { clientAsyncData.custmerData.states[op.url] = loadSate.ing; clientAsyncData.custmerData.load(op.url); } if (clientAsyncData.custmerData.states[op.url] === loadSate.ing) { setTimeout(function () { clientAsyncData.custmerData.getAll(op); }, 100);// 如果还在加载100ms后再检测 } else { var data = custmerData[op.url]; op.callback(data || [], op); } }, load: function (url) { learun.httpget(config.webapi + url, null, function (data) { if (data) { custmerData[url] = data; clientAsyncData.custmerData.states[url] = loadSate.yes; } else { clientAsyncData.custmerData.states[url] = loadSate.fail; } }); }, find: function (key, keyId, data) { var res = {}; for (var i = 0, l = data.length; i < l; i++) { if (data[i][keyId] === key) { res = data[i]; break; } } return res; } }; // 获取功能列表 clientAsyncData.module = { states: loadSate.no, init: function () { if (clientAsyncData.module.states === loadSate.no) { clientAsyncData.module.states = loadSate.ing; var data = learun.storage.get("moduleData") || {}; var ver = data.ver || ""; learun.httpget(config.webapi + "learun/adms/function/list", { ver: ver }, function (data) { if (data) { if (data.ver) { learun.storage.set("moduleData", data); } clientAsyncData.module.states = loadSate.yes; } else { clientAsyncData.module.states = loadSate.fail; } }); } }, get: function (op) { clientAsyncData.module.init(); if (clientAsyncData.module.states === loadSate.ing) { setTimeout(function () { clientAsyncData.module.get(op); }, 100);// 如果还在加载100ms后再检测 } else { var _tmpData = learun.storage.get("moduleData"); var data = _tmpData.data || {}; op.callback(data, op); } } }; // 获取我的应用列表 learun.myModule = { states: loadSate.no, init: function (modules) { if (learun.myModule.states === loadSate.no) { learun.myModule.states = loadSate.ing; var mymoduleData = learun.storage.get("mymoduleData"); if (mymoduleData === null) { var len = 7; if (len > modules.length) { len = modules.length; } var list = []; for (var i = 0; i < len; i++) { var item = modules[i]; list.push(item.F_Id); } learun.storage.set("mymoduleData", list); learun.httppost(config.webapi + "learun/adms/function/mylist/update", String(list), (res) => { }); learun.myModule.states = loadSate.yes; } else { learun.httpget(config.webapi + "learun/adms/function/mylist", null, function (data) { if (data) { learun.storage.set("mymoduleData", data); } learun.myModule.states = loadSate.yes; }); } } }, get: function (modules, callback) { learun.myModule.init(modules); if (learun.myModule.states === loadSate.ing) { setTimeout(function () { learun.myModule.get(modules, callback); }, 100);// 如果还在加载100ms后再检测 } else { callback(learun.storage.get("mymoduleData")); } } }; // 获取单据编码 learun.getRuleCode = function (code, callback) { learun.httpget(config.webapi + "learun/adms/coderule/code", code, function (data) { if (data) { callback(data); } else { callback(''); } }); }; /*选择框方法扩展(包含单选框)*/ // 选择框扩展(url(后台数据地址),数据字典,数据源), $.fn.lrpickerex = function (op) { var $this = $(this); if ($this.length === 0) { return $this; } if (!op.data) { op.data = []; if (op.firstRead) { clientAsyncData.sourceData.loadnologin(op.code); } if (op.firstDateItem) { clientAsyncData.dataItem.loadnologin(op.code); } switch (op.type) { case 'dataItem': $this.lrpicker(op); learun.clientdata.getAll('dataItem', { code: op.code, callback: function (data) { var _tmpdata = []; $.each(data, function (_index, _item) { _tmpdata.push({ value: _item.value, text: _item.text }); }); $this.lrpickerSetData(_tmpdata); } }); break; case 'sourceData': $this.lrpicker(op); learun.clientdata.getAll('sourceData', { code: op.code, callback: function (data) { if (op.placeHolders != '') { console.log(data); var obj={}; obj[op.ivalue] = op.placeHolders; obj[op.itext] = op.placeHolders; data.splice(0, 0, obj); } $this.lrpickerSetData(data); } }); break; default: $this.lrpicker(op); if (op.url) {// 如果有连接地址 learun.clientdata.getAll('custmerData', { url: op.url, callback: function (data) { $this.lrpickerSetData(data); } }); } break; } } else { $this.lrpicker(op); } return $this; }; // 组织单位选择 $.fn.lrselect = function (op) { var $this = $(this); if ($this.length === 0) { return $this; } var dfop = { placeholder: '请选择', type: 'company', companyId: '', departmentId: '', change: false }; $.extend(dfop, op || {}); $this.attr('type', 'lrselect'); $this.addClass('lr-select'); $this.html('