|
@@ -1,202 +1,206 @@
|
|
|
var util = {
|
|
|
- // 变量池
|
|
|
- variable: {},
|
|
|
- link: function() {
|
|
|
- util.labelInit('head', '<link rel="stylesheet" type="text/css" href="lib/layui/css/layui.css" />');
|
|
|
- document.write('<script type="text/javascript" src="lib/layui/layui.js"></script>');
|
|
|
- document.write('<script type="text/javascript" src="js/constant.js"></script>');
|
|
|
- },
|
|
|
- init: function(config, callback) {
|
|
|
- this.link();
|
|
|
- setTimeout(function() {
|
|
|
- layui.config({
|
|
|
- base: 'lib/encryption/'
|
|
|
- }).use(config, function() {
|
|
|
- let res = {};
|
|
|
- for (let i = 0; i < config.length; i++) {
|
|
|
- res[config[i]] = layui[config[i]];
|
|
|
- }
|
|
|
- callback(res);
|
|
|
- });
|
|
|
- }, 500);
|
|
|
- },
|
|
|
- ajax: function(config) {
|
|
|
- let index = layer.load(2);
|
|
|
- ly.ajax({
|
|
|
- type: config.type,
|
|
|
- url: config.url,
|
|
|
- dataType: 'json',
|
|
|
- data: config.data ? config.data : {},
|
|
|
- success: function(res) {
|
|
|
- if (config.success) {
|
|
|
- config.success(res);
|
|
|
- }
|
|
|
- layer.close(index);
|
|
|
- },
|
|
|
- error: function(err) {
|
|
|
- console.error('报错接口:', config.url, '报错内容:', err);
|
|
|
- layer.close(index);
|
|
|
- sessionStorage.clear();
|
|
|
- util.layer.errorMsg('系统错误,请重新登录!');
|
|
|
- setTimeout(function() {
|
|
|
- window.location.href = 'login.html';
|
|
|
- }, 2000);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- postJSON: function(config) {
|
|
|
- config.type = 'POST';
|
|
|
- this.ajax(config);
|
|
|
- },
|
|
|
- getJSON: function(config) {
|
|
|
- config.type = 'GET';
|
|
|
- this.ajax(config);
|
|
|
- },
|
|
|
- ptAjax: function(config) {
|
|
|
- let index = layer.load(2);
|
|
|
- let obj = {
|
|
|
- type: config.type,
|
|
|
- url: config.url,
|
|
|
- dataType: 'json',
|
|
|
- data: config.data ? config.data : {},
|
|
|
- success: function(res) {
|
|
|
- if (config.success) {
|
|
|
- config.success(res);
|
|
|
- }
|
|
|
- layer.close(index);
|
|
|
- },
|
|
|
- error: function(err) {
|
|
|
- console.error('报错接口:', config.url, '报错内容:', err);
|
|
|
- layer.close(index);
|
|
|
- }
|
|
|
- };
|
|
|
- if (config.contentType) {
|
|
|
- obj.contentType = config.contentType;
|
|
|
- }
|
|
|
- $.ajax(obj);
|
|
|
- },
|
|
|
- get: function(config) {
|
|
|
- config.type = 'GET';
|
|
|
- this.ptAjax(config);
|
|
|
- },
|
|
|
- post: function(config) {
|
|
|
- config.type = 'POST';
|
|
|
- this.ptAjax(config);
|
|
|
- },
|
|
|
- htmlHeader: function(userName, signOut) {
|
|
|
- if (userName) {
|
|
|
- $(userName).text(sessionStorage.LOGIN_USERNAME ? sessionStorage.LOGIN_USERNAME : '未知用户');
|
|
|
- }
|
|
|
- $(signOut).on('click', function() {
|
|
|
- layer.confirm('是否确认退出?', {
|
|
|
- btn: ['确认','取消']
|
|
|
- }, function() {
|
|
|
- sessionStorage.clear();
|
|
|
- window.location.href = 'login.html';
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- getQueryVariable: function(variable) {
|
|
|
- let query = window.location.search.substring(1);
|
|
|
- let vars = query.split("&");
|
|
|
- for (let i = 0; i < vars.length; i++) {
|
|
|
- let pair = vars[i].split("=");
|
|
|
- if (pair[0] == variable) {
|
|
|
- return pair[1];
|
|
|
- }
|
|
|
- }
|
|
|
- return "";
|
|
|
- },
|
|
|
- HTMLDecode: function(text) {
|
|
|
- return text.replace(/</g,"<").replace(/ /g," ").replace(/>/g,">");
|
|
|
- },
|
|
|
- blank: {
|
|
|
- isNotNull: function(data) {
|
|
|
- return data && data != undefined && data != 'null';
|
|
|
- },
|
|
|
- isArrayNull: function(data) {
|
|
|
- return (!data) || data == null || data.length == 0;
|
|
|
- }
|
|
|
- },
|
|
|
- layer: {
|
|
|
- errorMsg: function(msg) {
|
|
|
- layer.msg(msg, {icon: 5});
|
|
|
- },
|
|
|
- okMsg: function(msg) {
|
|
|
- layer.msg(msg, {icon: 6});
|
|
|
- },
|
|
|
- openNoTitle: function(clazz,title) {
|
|
|
- return layer.open({
|
|
|
- type: 1,
|
|
|
- title: false,
|
|
|
- closeBtn: 1,
|
|
|
- title,
|
|
|
- shadeClose: true,
|
|
|
- skin: 'yourclass',
|
|
|
- content: $(clazz),
|
|
|
- success: function() {
|
|
|
- $(clazz).css('display', 'block');
|
|
|
- },
|
|
|
- end: function() {
|
|
|
- $(clazz).css('display', 'none');
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- // 缓存弹窗索引
|
|
|
- index: {}
|
|
|
- },
|
|
|
- click: {
|
|
|
- longPress: function(main, son, time, callback, tap) {
|
|
|
- let timeout;
|
|
|
- $(main).on('touchstart', son, function(e) {
|
|
|
- // 添加长按标识
|
|
|
- $(main + ' ' + son).attr('data-sign', null);
|
|
|
- $(this).attr('data-sign', 'longPress');
|
|
|
- timeout = setTimeout(callback, time);
|
|
|
- });
|
|
|
- $(main).on('touchmove', son, function(e) {
|
|
|
- clearTimeout(timeout);
|
|
|
- timeout = 0;
|
|
|
- // e.preventDefault();
|
|
|
- });
|
|
|
- $(main).on('touchend', son, function(e) {
|
|
|
- clearTimeout(timeout);
|
|
|
- if (timeout != 0) {
|
|
|
- tap();
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- swiper: {
|
|
|
- init: function(clazz) {
|
|
|
- util.labelInit('head', '<link rel="stylesheet" type="text/css" href="lib/swiper/swiper.min.css"/>');
|
|
|
- $.getScript('lib/swiper/swiper.min.js',function(){
|
|
|
- util.variable['swiper'] = new Swiper (clazz, {
|
|
|
- direction: 'horizontal',
|
|
|
- slidesPerview:'auto'
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- labelInit: function(name, txt) {
|
|
|
- let html = document.getElementsByTagName(name)[0].innerHTML;
|
|
|
- html += txt;
|
|
|
- document.getElementsByTagName(name)[0].innerHTML = html;
|
|
|
- },
|
|
|
- websocket: {
|
|
|
- init: function(json, initData) {
|
|
|
- $.getScript('js/websocket.js',function(){
|
|
|
- myWebsocket.initWebsocket(json);
|
|
|
- util.variable['websocket'] = myWebsocket.websocket;
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
- dragula: {
|
|
|
- init: function(id) {
|
|
|
- util.labelInit('head', '<link rel="stylesheet" type="text/css" href="lib/dragula-3.7.3/dragula.min.css"/>');
|
|
|
- $.getScript('lib/dragula-3.7.3/dragula.min.js',function() {
|
|
|
- util.variable['dragula'] = dragula([document.getElementById(id)]);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
+ // 变量池
|
|
|
+ variable: {},
|
|
|
+ link: function() {
|
|
|
+ util.labelInit('head', '<link rel="stylesheet" type="text/css" href="lib/layui/css/layui.css" />');
|
|
|
+ document.write('<script type="text/javascript" src="lib/layui/layui.js"></script>');
|
|
|
+ document.write('<script type="text/javascript" src="js/constant.js"></script>');
|
|
|
+ },
|
|
|
+ init: function(config, callback) {
|
|
|
+ this.link();
|
|
|
+ setTimeout(function() {
|
|
|
+ layui.config({
|
|
|
+ base: 'lib/encryption/'
|
|
|
+ }).use(config, function() {
|
|
|
+ let res = {};
|
|
|
+ for (let i = 0; i < config.length; i++) {
|
|
|
+ res[config[i]] = layui[config[i]];
|
|
|
+ }
|
|
|
+ callback(res);
|
|
|
+ });
|
|
|
+ }, 500);
|
|
|
+ },
|
|
|
+ ajax: function(config) {
|
|
|
+ let index = layer.load(2);
|
|
|
+ ly.ajax({
|
|
|
+ type: config.type,
|
|
|
+ url: config.url,
|
|
|
+ dataType: 'json',
|
|
|
+ data: config.data ? config.data : {},
|
|
|
+ success: function(res) {
|
|
|
+ if (config.success) {
|
|
|
+ config.success(res);
|
|
|
+ }
|
|
|
+ layer.close(index);
|
|
|
+ },
|
|
|
+ error: function(err) {
|
|
|
+ console.error('报错接口:', config.url, '报错内容:', err);
|
|
|
+ layer.close(index);
|
|
|
+ sessionStorage.clear();
|
|
|
+ util.layer.errorMsg('系统错误,请重新登录!');
|
|
|
+ setTimeout(function() {
|
|
|
+ const path = location.pathname.split("/")
|
|
|
+ let fileName = path[path.length - 1].split(".")
|
|
|
+ fileName = fileName[0].split("_")[1]
|
|
|
+ console.log(fileName)
|
|
|
+ window.location.href = 'login_' + fileName + '.html';
|
|
|
+ }, 2000);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ postJSON: function(config) {
|
|
|
+ config.type = 'POST';
|
|
|
+ this.ajax(config);
|
|
|
+ },
|
|
|
+ getJSON: function(config) {
|
|
|
+ config.type = 'GET';
|
|
|
+ this.ajax(config);
|
|
|
+ },
|
|
|
+ ptAjax: function(config) {
|
|
|
+ let index = layer.load(2);
|
|
|
+ let obj = {
|
|
|
+ type: config.type,
|
|
|
+ url: config.url,
|
|
|
+ dataType: 'json',
|
|
|
+ data: config.data ? config.data : {},
|
|
|
+ success: function(res) {
|
|
|
+ if (config.success) {
|
|
|
+ config.success(res);
|
|
|
+ }
|
|
|
+ layer.close(index);
|
|
|
+ },
|
|
|
+ error: function(err) {
|
|
|
+ console.error('报错接口:', config.url, '报错内容:', err);
|
|
|
+ layer.close(index);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ if (config.contentType) {
|
|
|
+ obj.contentType = config.contentType;
|
|
|
+ }
|
|
|
+ $.ajax(obj);
|
|
|
+ },
|
|
|
+ get: function(config) {
|
|
|
+ config.type = 'GET';
|
|
|
+ this.ptAjax(config);
|
|
|
+ },
|
|
|
+ post: function(config) {
|
|
|
+ config.type = 'POST';
|
|
|
+ this.ptAjax(config);
|
|
|
+ },
|
|
|
+ htmlHeader: function(userName, signOut) {
|
|
|
+ if (userName) {
|
|
|
+ $(userName).text(sessionStorage.LOGIN_USERNAME ? sessionStorage.LOGIN_USERNAME : '未知用户');
|
|
|
+ }
|
|
|
+ $(signOut).on('click', function() {
|
|
|
+ layer.confirm('是否确认退出?', {
|
|
|
+ btn: ['确认', '取消']
|
|
|
+ }, function() {
|
|
|
+ sessionStorage.clear();
|
|
|
+ window.location.href = 'login.html';
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getQueryVariable: function(variable) {
|
|
|
+ let query = window.location.search.substring(1);
|
|
|
+ let vars = query.split("&");
|
|
|
+ for (let i = 0; i < vars.length; i++) {
|
|
|
+ let pair = vars[i].split("=");
|
|
|
+ if (pair[0] == variable) {
|
|
|
+ return pair[1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ },
|
|
|
+ HTMLDecode: function(text) {
|
|
|
+ return text.replace(/</g, "<").replace(/ /g, " ").replace(/>/g, ">");
|
|
|
+ },
|
|
|
+ blank: {
|
|
|
+ isNotNull: function(data) {
|
|
|
+ return data && data != undefined && data != 'null';
|
|
|
+ },
|
|
|
+ isArrayNull: function(data) {
|
|
|
+ return (!data) || data == null || data.length == 0;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ layer: {
|
|
|
+ errorMsg: function(msg) {
|
|
|
+ layer.msg(msg, { icon: 5 });
|
|
|
+ },
|
|
|
+ okMsg: function(msg) {
|
|
|
+ layer.msg(msg, { icon: 6 });
|
|
|
+ },
|
|
|
+ openNoTitle: function(clazz, title) {
|
|
|
+ return layer.open({
|
|
|
+ type: 1,
|
|
|
+ title: false,
|
|
|
+ closeBtn: 1,
|
|
|
+ title,
|
|
|
+ shadeClose: true,
|
|
|
+ skin: 'yourclass',
|
|
|
+ content: $(clazz),
|
|
|
+ success: function() {
|
|
|
+ $(clazz).css('display', 'block');
|
|
|
+ },
|
|
|
+ end: function() {
|
|
|
+ $(clazz).css('display', 'none');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 缓存弹窗索引
|
|
|
+ index: {}
|
|
|
+ },
|
|
|
+ click: {
|
|
|
+ longPress: function(main, son, time, callback, tap) {
|
|
|
+ let timeout;
|
|
|
+ $(main).on('touchstart', son, function(e) {
|
|
|
+ // 添加长按标识
|
|
|
+ $(main + ' ' + son).attr('data-sign', null);
|
|
|
+ $(this).attr('data-sign', 'longPress');
|
|
|
+ timeout = setTimeout(callback, time);
|
|
|
+ });
|
|
|
+ $(main).on('touchmove', son, function(e) {
|
|
|
+ clearTimeout(timeout);
|
|
|
+ timeout = 0;
|
|
|
+ // e.preventDefault();
|
|
|
+ });
|
|
|
+ $(main).on('touchend', son, function(e) {
|
|
|
+ clearTimeout(timeout);
|
|
|
+ if (timeout != 0) {
|
|
|
+ tap();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ swiper: {
|
|
|
+ init: function(clazz) {
|
|
|
+ util.labelInit('head', '<link rel="stylesheet" type="text/css" href="lib/swiper/swiper.min.css"/>');
|
|
|
+ $.getScript('lib/swiper/swiper.min.js', function() {
|
|
|
+ util.variable['swiper'] = new Swiper(clazz, {
|
|
|
+ direction: 'horizontal',
|
|
|
+ slidesPerview: 'auto'
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ labelInit: function(name, txt) {
|
|
|
+ let html = document.getElementsByTagName(name)[0].innerHTML;
|
|
|
+ html += txt;
|
|
|
+ document.getElementsByTagName(name)[0].innerHTML = html;
|
|
|
+ },
|
|
|
+ websocket: {
|
|
|
+ init: function(json, initData) {
|
|
|
+ $.getScript('js/websocket.js', function() {
|
|
|
+ myWebsocket.initWebsocket(json);
|
|
|
+ util.variable['websocket'] = myWebsocket.websocket;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ dragula: {
|
|
|
+ init: function(id) {
|
|
|
+ util.labelInit('head', '<link rel="stylesheet" type="text/css" href="lib/dragula-3.7.3/dragula.min.css"/>');
|
|
|
+ $.getScript('lib/dragula-3.7.3/dragula.min.js', function() {
|
|
|
+ util.variable['dragula'] = dragula([document.getElementById(id)]);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|