修改ry-ui.js中判断是否为空函数,增加对undefined的判断,优化if判断

This commit is contained in:
杨玄 2019-01-09 08:09:45 +08:00
parent dc07b97cdb
commit 36ddf23f27
1 changed files with 576 additions and 550 deletions

View File

@ -2,7 +2,7 @@
* 通用js方法封装处理
* Copyright (c) 2018 ruoyi
*/
(function ($) {
(function($) {
$.extend({
_treeTable: {},
_tree: {},
@ -61,14 +61,20 @@
// 请求获取数据后处理回调函数
responseHandler: function(res) {
if (res.code == 0) {
return { rows: res.rows, total: res.total };
return {
rows: res.rows,
total: res.total
};
} else {
$.modal.alertWarning(res.msg);
return { rows: [], total: 0 };
return {
rows: [],
total: 0
};
}
},
// 序列号生成
serialNumber: function (index) {
serialNumber: function(index) {
var table = $('#bootstrap-table').bootstrapTable('getOptions');
var pageSize = table.pageSize;
var pageNumber = table.pageNumber;
@ -113,13 +119,13 @@
},
// 查询表格指定列值
selectColumns: function(column) {
return $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) {
return $.map($('#bootstrap-table').bootstrapTable('getSelections'), function(row) {
return row[column];
});
},
// 查询表格首列值
selectFirstColumns: function() {
return $.map($('#bootstrap-table').bootstrapTable('getSelections'), function (row) {
return $.map($('#bootstrap-table').bootstrapTable('getSelections'), function(row) {
return row[$.table._option.columns[1].field];
});
},
@ -205,7 +211,7 @@
// 获取选中下拉框项
selectSelects: function(name) {
var selects = "";
$('#' + name + ' option:selected').each(function (i) {
$('#' + name + ' option:selected').each(function(i) {
if (0 == i) {
selects = $(this).val();
} else {
@ -234,7 +240,11 @@
// 消息提示
msg: function(content, type) {
if (type != undefined) {
layer.msg(content, { icon: $.modal.icon(type), time: 1000, shift: 5 });
layer.msg(content, {
icon: $.modal.icon(type),
time: 1000,
shift: 5
});
} else {
layer.msg(content);
}
@ -284,24 +294,24 @@
$.modal.alert(content, modal_status.WARNING);
},
// 关闭窗体
close: function () {
close: function() {
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
},
// 确认窗体
confirm: function (content, callBack) {
confirm: function(content, callBack) {
layer.confirm(content, {
icon: 3,
title: "系统提示",
btn: ['确认', '取消'],
btnclass: ['btn btn-primary', 'btn btn-danger'],
}, function (index) {
}, function(index) {
layer.close(index);
callBack(true);
});
},
// 弹出层指定宽度
open: function (title, url, width, height) {
open: function(title, url, width, height) {
//如果是移动端,就使用自适应大小弹窗
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
width = 'auto';
@ -341,7 +351,7 @@
});
},
// 弹出层指定参数选项
openOptions: function (options) {
openOptions: function(options) {
var _url = $.common.isEmpty(options.url) ? "/404.html" : options.url;
var _title = $.common.isEmpty(options.title) ? "系统窗口" : options.title;
var _width = $.common.isEmpty(options.width) ? "800" : options.width;
@ -356,15 +366,16 @@
content: _url,
shadeClose: true,
btn: ['<i class="fa fa-check"></i> 确认', '<i class="fa fa-close"></i> 关闭'],
yes: function (index, layero) {
yes: function(index, layero) {
options.callBack(index, layero)
}, cancel: function () {
},
cancel: function() {
return true;
}
});
},
// 弹出层全屏
openFull: function (title, url, width, height) {
openFull: function(title, url, width, height) {
//如果是移动端,就使用自适应大小弹窗
if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
width = 'auto';
@ -405,17 +416,19 @@
layer.full(index);
},
// 打开遮罩层
loading: function (message) {
$.blockUI({ message: '<div class="loaderbox"><div class="loading-activity"></div> ' + message + '</div>' });
loading: function(message) {
$.blockUI({
message: '<div class="loaderbox"><div class="loading-activity"></div> ' + message + '</div>'
});
},
// 关闭遮罩层
closeLoading: function () {
setTimeout(function(){
closeLoading: function() {
setTimeout(function() {
$.unblockUI();
}, 50);
},
// 重新加载
reload: function () {
reload: function() {
parent.location.reload();
}
},
@ -466,7 +479,7 @@
// 弹层外区域关闭
shadeClose: true,
success: function(layer) {
layer[0].childNodes[3].childNodes[0].attributes[0].value='layui-layer-btn1';
layer[0].childNodes[3].childNodes[0].attributes[0].value = 'layui-layer-btn1';
},
btn1: function(index) {
layer.close(index);
@ -477,7 +490,9 @@
remove: function(id) {
$.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗?", function() {
var url = $.common.isEmpty(id) ? $.table._option.removeUrl : $.table._option.removeUrl.replace("{id}", id);
var data = { "ids": id };
var data = {
"ids": id
};
$.operate.submit(url, "post", "json", data);
});
},
@ -490,7 +505,9 @@
}
$.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
var url = $.table._option.removeUrl;
var data = { "ids": rows.join() };
var data = {
"ids": rows.join()
};
$.operate.submit(url, "post", "json", data);
});
},
@ -562,7 +579,7 @@
$.ajax(config)
},
// 保存结果弹出msg刷新table表格
ajaxSuccess: function (result) {
ajaxSuccess: function(result) {
if (result.code == web_status.SUCCESS) {
$.modal.msgSuccess(result.msg);
$.table.refresh();
@ -572,7 +589,7 @@
$.modal.closeLoading();
},
// 成功结果提示msg父窗体全局更新
saveSuccess: function (result) {
saveSuccess: function(result) {
if (result.code == web_status.SUCCESS) {
$.modal.msgReload("保存成功,正在刷新数据请稍后……", modal_status.SUCCESS);
} else {
@ -603,14 +620,14 @@
// 校验封装处理
validate: {
// 判断返回标识是否唯一 false 不存在 true 存在
unique: function (value) {
unique: function(value) {
if (value == "0") {
return true;
}
return false;
},
// 表单验证
form: function (formId) {
form: function(formId) {
var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
return $("#" + currentId).validate().form();
}
@ -629,9 +646,21 @@
// 树结构初始化加载
var setting = {
check: options.check,
view: { selectedMulti: false, nameIsHTML: true },
data: { key: { title: "title" }, simpleData: { enable: true } },
callback: { onClick: options.onClick }
view: {
selectedMulti: false,
nameIsHTML: true
},
data: {
key: {
title: "title"
},
simpleData: {
enable: true
}
},
callback: {
onClick: options.onClick
}
};
$.get(options.url, function(data) {
var treeName = $("#treeName").val();
@ -641,7 +670,7 @@
// 展开第一级节点
var nodes = tree.getNodesByParam("level", 0);
for (var i = 0; i < nodes.length; i++) {
if(_expandLevel > 0) {
if (_expandLevel > 0) {
tree.expandNode(nodes[i], true, false, false);
}
$.tree.selectByIdName(treeId, treeName, nodes[i]);
@ -649,7 +678,7 @@
// 展开第二级节点
nodes = tree.getNodesByParam("level", 1);
for (var i = 0; i < nodes.length; i++) {
if(_expandLevel > 1) {
if (_expandLevel > 1) {
tree.expandNode(nodes[i], true, false, false);
}
$.tree.selectByIdName(treeId, treeName, nodes[i]);
@ -657,7 +686,7 @@
// 展开第三级节点
nodes = tree.getNodesByParam("level", 2);
for (var i = 0; i < nodes.length; i++) {
if(_expandLevel > 2) {
if (_expandLevel > 2) {
tree.expandNode(nodes[i], true, false, false);
}
$.tree.selectByIdName(treeId, treeName, nodes[i]);
@ -744,7 +773,7 @@
getCheckedNodes: function(column) {
var _column = $.common.isEmpty(column) ? "id" : column;
var nodes = $._tree.getCheckedNodes(true);
return $.map(nodes, function (row) {
return $.map(nodes, function(row) {
return row[_column];
}).join();
},
@ -793,32 +822,29 @@
// 通用方法封装处理
common: {
// 判断字符串是否为空
isEmpty: function (value) {
if (value == null || this.trim(value) == "") {
return true;
}
return false;
isEmpty: function(value) {
return value == null || this.trim(value) === "" || typeof(value) == "undefined";
},
// 判断一个字符串是否为非空串
isNotEmpty: function (value) {
isNotEmpty: function(value) {
return !$.common.isEmpty(value);
},
// 是否显示数据 为空默认为显示
visible: function (value) {
visible: function(value) {
if ($.common.isEmpty(value) || value == true) {
return true;
}
return false;
},
// 空格截取
trim: function (value) {
trim: function(value) {
if (value == null) {
return "";
}
return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g, "");
},
// 指定随机数返回
random: function (min, max) {
random: function(min, max) {
return Math.floor((Math.random() * max) + min);
},
startWith: function(value, start) {