From 17e9caf1d2420b3fdb176c5f2d726d04ed14254f Mon Sep 17 00:00:00 2001 From: glacier Date: Fri, 24 Feb 2023 14:55:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=20=E4=BF=AE=E6=94=B9=E5=BC=83=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95substr=E4=B8=BAsubstring=202.=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9dataType=20=E8=AE=BE=E7=BD=AE=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=88=A4=E6=96=AD=203.=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=B8=BA=20=3D=3D=3D=20=E6=88=96=E8=80=85=20?= =?UTF-8?q?!=3D=3D=204.=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/pear/module/common.js | 46 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/component/pear/module/common.js b/component/pear/module/common.js index ed7370e..bc7522e 100644 --- a/component/pear/module/common.js +++ b/component/pear/module/common.js @@ -10,7 +10,7 @@ layui.define(['jquery', 'element','table'], function(exports) { element = layui.element; var common = new function() { - + /** * 获取当前表格选中字段 * @param obj 表格回调参数 @@ -25,21 +25,18 @@ layui.define(['jquery', 'element','table'], function(exports) { for (let i = 0; i < data.length; i++) { ids += data[i][field] + ","; } - ids = ids.substr(0, ids.length - 1); + ids = ids.substring(0, ids.length - 1); return ids; } - + /** * 当前是否为与移动端 * */ this.isModile = function(){ - if ($(window).width() <= 768) { - return true; - } - return false; + return $(window).width() <= 768; } - - + + /** * 提交 json 数据 * @param href 必选 提交接口 @@ -52,14 +49,12 @@ layui.define(['jquery', 'element','table'], function(exports) { * @param is_cache 可选 浏览器是否缓存被请求页面。默认是 true * */ this.submit = function(href,data,ajaxtype,table,callback,dataType,is_async,is_cache){ - if(ajaxtype=='' || ajaxtype==undefined){ ajaxtype='get';} - if(data!==undefined){ $.ajaxSetup({data:JSON.stringify(data)}); }else { $.ajaxSetup({data:''}); } - if(is_cache!==undefined){ + if(dataType!==undefined){ $.ajaxSetup({dataType:dataType }); } if(is_async!==undefined){ @@ -71,40 +66,43 @@ layui.define(['jquery', 'element','table'], function(exports) { $.ajax({ url:href, contentType:'application/json', - type:ajaxtype, + type:ajaxtype || 'get', success:callback !=null?callback:function(result){ - if(result.code==1){ + if(result.code===1){ layer.msg(result.msg,{icon:1,time:1000},function(){ - if(parent.layer.getFrameIndex(window.name)!=undefined){ - parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页 - if(table!=null){parent.layui.table.reload(table);} - }else { - if(table!=null){layui.table.reload(table);} + let frameIndex = parent.layer.getFrameIndex(window.name); + if(frameIndex){ + parent.layer.close(frameIndex);//关闭当前页 } + table && parent.layui.table.reload(table); }); }else{ layer.msg(result.msg,{icon:2,time:1000}); } }, error:function(xhr){ - if(xhr.status==401) + if(xhr.status===401) { layer.msg('权限不足,您无法访问受限资源或数据',{icon: 5}); + return; } - if(xhr.status==404) + if(xhr.status===404) { layer.msg('请求url地址错误,请确认后刷新重试',{icon: 5}); + return; } - if(xhr.status==419) + if(xhr.status===419) { layer.msg('长时间未操作,自动刷新后重试!',{icon: 5}); setTimeout(function () { window.location.reload();}, 2000); + return; } - if(xhr.status==429) + if(xhr.status===429) { layer.msg('尝试次数太多,请一分钟后再试',{icon: 5}); + return; } - if(xhr.status==500) + if(xhr.status===500) { layer.msg(xhr.responseJSON.message,{icon: 5}); } -- Gitee From bc2056bf01358bd075d6e13ab30359edca7082a7 Mon Sep 17 00:00:00 2001 From: glacier Date: Fri, 24 Feb 2023 14:56:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/pear/module/common.js | 215 ++++++++++++++++---------------- 1 file changed, 106 insertions(+), 109 deletions(-) diff --git a/component/pear/module/common.js b/component/pear/module/common.js index bc7522e..50f2f15 100644 --- a/component/pear/module/common.js +++ b/component/pear/module/common.js @@ -1,117 +1,114 @@ -layui.define(['jquery', 'element','table'], function(exports) { - "use strict"; +layui.define(['jquery', 'element', 'table'], function (exports) { + "use strict"; - /** - * 常用封装类 - * */ - var MOD_NAME = 'common', - $ = layui.jquery, - table = layui.table, - element = layui.element; + /** + * 常用封装类 + * */ + var MOD_NAME = 'common', + $ = layui.jquery, + table = layui.table, + element = layui.element; - var common = new function() { + var common = new function () { - /** - * 获取当前表格选中字段 - * @param obj 表格回调参数 - * @param field 要获取的字段 - * */ - this.checkField = function(obj, field) { - let data = table.checkStatus(obj.config.id).data; - if (data.length === 0) { - return ""; - } - let ids = ""; - for (let i = 0; i < data.length; i++) { - ids += data[i][field] + ","; - } - ids = ids.substring(0, ids.length - 1); - return ids; - } + /** + * 获取当前表格选中字段 + * @param obj 表格回调参数 + * @param field 要获取的字段 + * */ + this.checkField = function (obj, field) { + let data = table.checkStatus(obj.config.id).data; + if (data.length === 0) { + return ""; + } + let ids = ""; + for (let i = 0; i < data.length; i++) { + ids += data[i][field] + ","; + } + ids = ids.substring(0, ids.length - 1); + return ids; + } - /** - * 当前是否为与移动端 - * */ - this.isModile = function(){ - return $(window).width() <= 768; - } + /** + * 当前是否为与移动端 + * */ + this.isModile = function () { + return $(window).width() <= 768; + } - /** - * 提交 json 数据 - * @param href 必选 提交接口 - * @param data 可选 提交数据 - * @param ajaxtype 可选 提交方式(默认为get) - * @param table 可选 刷新父级表 - * @param callback 可选 自定义回调函数 - * @param dataType 可选 返回数据类型 智能猜测(可以是xml, json, script, 或 html) - * @param is_async 可选 请求是否异步处理。默认是 true - * @param is_cache 可选 浏览器是否缓存被请求页面。默认是 true - * */ - this.submit = function(href,data,ajaxtype,table,callback,dataType,is_async,is_cache){ - if(data!==undefined){ - $.ajaxSetup({data:JSON.stringify(data)}); - }else { - $.ajaxSetup({data:''}); - } - if(dataType!==undefined){ - $.ajaxSetup({dataType:dataType }); - } - if(is_async!==undefined){ - $.ajaxSetup({async:is_async }); - } - if(is_cache!==undefined){ - $.ajaxSetup({cache:is_cache }); - } - $.ajax({ - url:href, - contentType:'application/json', - type:ajaxtype || 'get', - success:callback !=null?callback:function(result){ - if(result.code===1){ - layer.msg(result.msg,{icon:1,time:1000},function(){ - let frameIndex = parent.layer.getFrameIndex(window.name); - if(frameIndex){ - parent.layer.close(frameIndex);//关闭当前页 - } - table && parent.layui.table.reload(table); - }); - }else{ - layer.msg(result.msg,{icon:2,time:1000}); - } - }, - error:function(xhr){ - if(xhr.status===401) - { - layer.msg('权限不足,您无法访问受限资源或数据',{icon: 5}); - return; - } - if(xhr.status===404) - { - layer.msg('请求url地址错误,请确认后刷新重试',{icon: 5}); - return; - } - if(xhr.status===419) - { - layer.msg('长时间未操作,自动刷新后重试!',{icon: 5}); - setTimeout(function () { window.location.reload();}, 2000); - return; - } - if(xhr.status===429) - { - layer.msg('尝试次数太多,请一分钟后再试',{icon: 5}); - return; - } - if(xhr.status===500) - { - layer.msg(xhr.responseJSON.message,{icon: 5}); - } - } - ,complete:function (xhr,status){ + /** + * 提交 json 数据 + * @param href 必选 提交接口 + * @param data 可选 提交数据 + * @param ajaxtype 可选 提交方式(默认为get) + * @param table 可选 刷新父级表 + * @param callback 可选 自定义回调函数 + * @param dataType 可选 返回数据类型 智能猜测(可以是xml, json, script, 或 html) + * @param is_async 可选 请求是否异步处理。默认是 true + * @param is_cache 可选 浏览器是否缓存被请求页面。默认是 true + * */ + this.submit = function (href, data, ajaxtype, table, callback, dataType, is_async, is_cache) { + if (data !== undefined) { + $.ajaxSetup({data: JSON.stringify(data)}); + } else { + $.ajaxSetup({data: ''}); + } + if (dataType !== undefined) { + $.ajaxSetup({dataType: dataType}); + } + if (is_async !== undefined) { + $.ajaxSetup({async: is_async}); + } + if (is_cache !== undefined) { + $.ajaxSetup({cache: is_cache}); + } + $.ajax({ + url: href, + contentType: 'application/json', + type: ajaxtype || 'get', + success: callback != null ? callback : function (result) { + if (result.code === 1) { + layer.msg(result.msg, {icon: 1, time: 1000}, function () { + let frameIndex = parent.layer.getFrameIndex(window.name); + if (frameIndex) { + parent.layer.close(frameIndex);//关闭当前页 + } + table && parent.layui.table.reload(table); + }); + } else { + layer.msg(result.msg, {icon: 2, time: 1000}); + } + }, + error: function (xhr) { + if (xhr.status === 401) { + layer.msg('权限不足,您无法访问受限资源或数据', {icon: 5}); + return; + } + if (xhr.status === 404) { + layer.msg('请求url地址错误,请确认后刷新重试', {icon: 5}); + return; + } + if (xhr.status === 419) { + layer.msg('长时间未操作,自动刷新后重试!', {icon: 5}); + setTimeout(function () { + window.location.reload(); + }, 2000); + return; + } + if (xhr.status === 429) { + layer.msg('尝试次数太多,请一分钟后再试', {icon: 5}); + return; + } + if (xhr.status === 500) { + layer.msg(xhr.responseJSON.message, {icon: 5}); + } + } + , complete: function (xhr, status) { - } - }) - } - } - exports(MOD_NAME, common); + } + }) + } + } + exports(MOD_NAME, common); }); -- Gitee