新增defaultValue特性;

This commit is contained in:
2022-06-06 18:37:04 +08:00
parent ca75ce8602
commit 64b66627a1
2 changed files with 65 additions and 97 deletions

View File

@@ -12,9 +12,9 @@ define(["jquery", "easy-admin"], function ($, ea) {
password_url: 'system.admin/password', password_url: 'system.admin/password',
}; };
var authList = ea.getDataBrage('auth_list',[]); var authList = ea.getDataBrage('auth_list', []);
var count = ea.getDataBrage('count',0); var count = ea.getDataBrage('count', 0);
var tips = ea.getDataBrage('tips',''); var tips = ea.getDataBrage('tips', '');
console.log(authList); console.log(authList);
console.log(count); console.log(count);
@@ -27,20 +27,20 @@ define(["jquery", "easy-admin"], function ($, ea) {
ea.table.render({ ea.table.render({
init: init, init: init,
cols: [[ cols: [[
{type: "checkbox"}, { type: "checkbox" },
{field: 'id', width: 80, title: 'ID'}, { field: 'id', width: 80, title: 'ID' },
{field: 'sort', width: 80, title: '排序', edit: 'text'}, { field: 'sort', width: 80, title: '排序', edit: 'text' },
{field: 'username', minWidth: 80, title: '登录账户'}, { field: 'username', minWidth: 80, title: '登录账户' },
{field: 'head_img', minWidth: 80, title: '头像', search: false, templet: ea.table.image}, { field: 'head_img', minWidth: 80, title: '头像', search: false, templet: ea.table.image },
{field: 'phone', minWidth: 80, title: '手机'}, { field: 'phone', minWidth: 80, title: '手机' },
{field: 'login_num', minWidth: 80, title: '登录次数'}, { field: 'login_num', minWidth: 80, title: '登录次数' },
{field: 'remark', minWidth: 80, title: '备注信息'}, { field: 'remark', minWidth: 80, title: '备注信息', defaultValue: '无' },
{field: 'status', title: '状态', width: 85, search: 'select', selectList: {0: '禁用', 1: '启用'}, templet: ea.table.switch}, { field: 'status', title: '状态', width: 85, search: 'select', selectList: { 0: '禁用', 1: '启用' }, templet: ea.table.switch },
{field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'}, { field: 'create_time', minWidth: 80, title: '创建时间', search: 'range' },
{ {
width: 250, width: 250,
title: '操作', title: '操作',
fixed:'right', fixed: 'right',
templet: ea.table.tool, templet: ea.table.tool,
operat: [ operat: [
'edit', 'edit',

View File

@@ -66,16 +66,7 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
headers: function () { headers: function () {
return { 'X-CSRF-TOKEN': window.CONFIG.CSRF_TOKEN }; return { 'X-CSRF-TOKEN': window.CONFIG.CSRF_TOKEN };
}, },
//js版empty判断变量是否为空
empty: function (r) {
var n, t, e, f = [void 0, null, !1, 0, "", "0"];
for (t = 0, e = f.length; t < e; t++) if (r === f[t]) return !0;
if ("object" == typeof r) {
for (n in r) if (r.hasOwnProperty(n)) return !1;
return !0
}
return !1
},
checkAuth: function (node, elem) { checkAuth: function (node, elem) {
if (CONFIG.IS_SUPER_ADMIN) { if (CONFIG.IS_SUPER_ADMIN) {
return true; return true;
@@ -730,6 +721,11 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
} }
} }
// 如果未定义则默认使用value
if (val.templet === undefined) {
cols[i][index]['templet'] = admin.table.value;
}
if (val.fieldFormat == undefined) { if (val.fieldFormat == undefined) {
switch (val.templet) { switch (val.templet) {
@@ -840,12 +836,8 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
list: function (data) { list: function (data) {
var option = data.LAY_COL; var option = data.LAY_COL;
option.selectList = option.selectList || {}; option.selectList = option.selectList || {};
var field = option.field;
try { var value = admin.table.returnColumnValue(data);
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
if (option.selectList[value] === undefined || option.selectList[value] === '' || option.selectList[value] === null) { if (option.selectList[value] === undefined || option.selectList[value] === '' || option.selectList[value] === null) {
return value; return value;
} else { } else {
@@ -853,19 +845,13 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
} }
}, },
filePreview: function (data) { filePreview: function (data) {
var option = data.LAY_COL;
var mimeName = data.mime_type.split('/')[0]; var mimeName = data.mime_type.split('/')[0];
var field = option.field;
if (mimeName == 'image') { if (mimeName == 'image') {
return admin.table.image(data); return admin.table.image(data);
} else { } else {
try { var value = admin.table.returnColumnValue(data);
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
var groupName = admin.getExtGroupName(data.file_ext); var groupName = admin.getExtGroupName(data.file_ext);
@@ -880,13 +866,8 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
option.imageSplit = option.imageSplit || '|'; option.imageSplit = option.imageSplit || '|';
option.imageJoin = option.imageJoin || '<br>'; option.imageJoin = option.imageJoin || '<br>';
option.title = option.title || option.field; option.title = option.title || option.field;
var field = option.field, var title = data[option.title];
title = data[option.title]; var value = admin.table.returnColumnValue(data);
try {
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
if (value === undefined || value === null) { if (value === undefined || value === null) {
return '<img style="max-width: ' + option.imageWidth + 'px; height: ' + option.imageHeight + 'px;" src="' + value + '" data-image="' + title + '">'; return '<img style="max-width: ' + option.imageWidth + 'px; height: ' + option.imageHeight + 'px;" src="' + value + '" data-image="' + title + '">';
} else { } else {
@@ -900,15 +881,10 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
}, },
url: function (data) { url: function (data) {
var option = data.LAY_COL; var option = data.LAY_COL;
var field = option.field;
var urlNameField = option.urlNameField || ''; var urlNameField = option.urlNameField || '';
try { var value = admin.table.returnColumnValue(data);
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
var urlName = value; var urlName = value;
if (urlNameField != '') { if (urlNameField != '') {
@@ -930,80 +906,62 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
}, },
switch: function (data) { switch: function (data) {
var option = data.LAY_COL; var option = data.LAY_COL;
var field = option.field;
option.filter = option.filter || option.field || null; option.filter = option.filter || option.field || null;
option.checked = option.checked || 1; option.checked = option.checked || 1;
option.tips = option.tips || '|'; option.tips = option.tips || '|';
try { var value = admin.table.returnColumnValue(data);
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
var checked = value === option.checked ? 'checked' : ''; var checked = value === option.checked ? 'checked' : '';
return laytpl('<input type="checkbox" name="' + option.field + '" value="' + data.id + '" lay-skin="switch" lay-text="' + option.tips + '" lay-filter="' + option.filter + '" ' + checked + ' >').render(data); return laytpl('<input type="checkbox" name="' + option.field + '" value="' + data.id + '" lay-skin="switch" lay-text="' + option.tips + '" lay-filter="' + option.filter + '" ' + checked + ' >').render(data);
}, },
price: function (data) { price: function (data) {
var option = data.LAY_COL; var value = admin.table.returnColumnValue(data);
var field = option.field;
try {
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
return '<span>' + value + '</span>'; return '<span>' + value + '</span>';
}, },
percent: function (data) { percent: function (data) {
var option = data.LAY_COL; var value = admin.table.returnColumnValue(data);
var field = option.field;
try {
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
return '<span>' + value + '%</span>'; return '<span>' + value + '%</span>';
}, },
icon: function (data) { icon: function (data) {
var option = data.LAY_COL; var value = admin.table.returnColumnValue(data);
var field = option.field;
try {
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
return '<i class="' + value + '"></i>'; return '<i class="' + value + '"></i>';
}, },
text: function (data) { text: function (data) {
var option = data.LAY_COL; var value = admin.table.returnColumnValue(data);
var field = option.field;
try {
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
return '<span class="line-limit-length">' + value + '</span>'; return '<span class="line-limit-length">' + value + '</span>';
}, },
value: function (data) { value: function (data) {
var option = data.LAY_COL; var value = admin.table.returnColumnValue(data);
var field = option.field;
try {
var value = eval("data." + field);
} catch (e) {
var value = undefined;
}
return '<span>' + value + '</span>'; return '<span>' + value + '</span>';
}, },
//时间戳转日期 //时间戳转日期
date: function (data) { date: function (data) {
var option = data.LAY_COL; var option = data.LAY_COL;
var field = option.field, value = '';
try { value = admin.table.returnColumnValue(data);
value = eval("data." + field);
} catch (e) { }
if (!admin.empty(value)) { if (!admin.empty(value)) {
value = util.toDateString(value * 1000, option.format || 'yyyy-MM-dd HH:mm:ss'); value = util.toDateString(value * 1000, option.format || 'yyyy-MM-dd HH:mm:ss');
} }
return '<span>' + value + '</span>'; return '<span>' + value + '</span>';
}, },
// 统一列返回数据处理
returnColumnValue(data) {
var option = data.LAY_COL;
var field = option.field;
var defaultValue = option.defaultValue;
var value = defaultValue;
try {
value = eval("data." + field);
} catch (e) {
value = undefined;
}
if (defaultValue != undefined && admin.empty(value)) {
value = defaultValue;
}
return value;
},
listenTableSearch: function (tableId) { listenTableSearch: function (tableId) {
form.on('submit(' + tableId + '_filter)', function (data) { form.on('submit(' + tableId + '_filter)', function (data) {
var dataField = data.field; var dataField = data.field;
@@ -1957,7 +1915,17 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
} }
return groupName; return groupName;
} },
//js版empty判断变量是否为空
empty: function (r) {
var n, t, e, f = [void 0, null, !1, 0, "", "0"];
for (t = 0, e = f.length; t < e; t++) if (r === f[t]) return !0;
if ("object" == typeof r) {
for (n in r) if (r.hasOwnProperty(n)) return !1;
return !0
}
return !1
},
}; };
return admin; return admin;