完成菜单删除自动刷新;给自定义按钮增加绑定字段值设置项;

This commit is contained in:
2022-07-11 14:59:51 +08:00
parent a538ac1dce
commit aa511ea824
2 changed files with 48 additions and 15 deletions

View File

@@ -35,10 +35,10 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
// @todo 不直接使用ea.table.render(); 进行表格初始化, 需要使用 ea.table.formatCols(); 方法格式化`cols`列数据
cols: ea.table.formatCols([[
{type: 'checkbox'},
{field: 'title', width: 250, title: '菜单名称', align: 'left'},
{field: 'icon', width: 80, title: '图标', templet: ea.table.icon},
{field: 'href', minWidth: 120, title: '菜单链接'},
{ type: 'checkbox' },
{ field: 'title', width: 250, title: '菜单名称', align: 'left' },
{ field: 'icon', width: 80, title: '图标', templet: ea.table.icon },
{ field: 'href', minWidth: 120, title: '菜单链接' },
{
field: 'is_home',
width: 80,
@@ -54,8 +54,8 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
}
}
},
{field: 'status', title: '状态', width: 85, templet: ea.table.switch},
{field: 'sort', width: 80, title: '排序', edit: 'text'},
{ field: 'status', title: '状态', width: 85, templet: ea.table.switch },
{ field: 'sort', width: 80, title: '排序', edit: 'text' },
{
width: 220,
title: '操作',
@@ -76,8 +76,15 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
auth: 'edit',
class: 'layui-btn layui-btn-xs layui-btn-success',
extend: 'data-full="true"',
}],
'delete'
}, {
text: '删除',
method: 'none',
auth: 'delete',
class: 'layui-btn layui-btn-xs layui-btn-danger',
extend: 'data-treetable-delete-item="1" data-url="'+init.delete_url+'"',
data: ['id', 'title']
},],
]
}
]], init),
@@ -99,6 +106,25 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
renderTable();
});
$('body').on('click', '[data-treetable-delete-item]', function () {
var id = $(this).data('id');
var url = $(this).attr('data-url');
url = url != undefined ? ea.url(url) : window.location.href;
ea.msg.confirm('确定删除?', function () {
ea.request.post({
url: url,
data: {
id: id
},
}, function (res) {
ea.msg.success(res.msg, function () {
renderTable();
});
});
});
return false;
})
$('body').on('click', '[data-treetable-delete]', function () {
var tableId = $(this).attr('data-treetable-delete'),
url = $(this).attr('data-url');
@@ -129,7 +155,7 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
return false;
});
ea.table.listenSwitch({filter: 'status', url: init.modify_url});
ea.table.listenSwitch({ filter: 'status', url: init.modify_url });
ea.table.listenEdit(init, 'currentTable', init.table_render_id, true);

View File

@@ -1,4 +1,4 @@
define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypicker','tagInput'], function ($, tableSelect, undefined, miniTheme, tableData,citypicker,tagInput) {
define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypicker', 'tagInput'], function ($, tableSelect, undefined, miniTheme, tableData, citypicker, tagInput) {
window.onInitElemStyle = function () {
miniTheme.renderElemStyle()
@@ -718,7 +718,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
return html;
},
buildOperatHtml: function (operat) {
buildOperatHtml: function (operat, data) {
var html = '';
operat.class = operat.class || '';
operat.icon = operat.icon || '';
@@ -727,6 +727,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
operat.extend = operat.extend || '';
operat.method = operat.method || 'open';
operat.field = operat.field || 'id';
operat.data = operat.data || ['id'];
operat.title = operat.title || operat.text;
operat.text = operat.text || operat.title;
@@ -742,7 +743,13 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
} else {
formatOperat.method = formatOperat.method !== '' ? 'data-request="' + formatOperat.url + '" data-title="' + formatOperat.title + '" ' : '';
}
html = '<a ' + formatOperat.class + formatOperat.method + formatOperat.extend + '>' + formatOperat.icon + formatOperat.text + '</a>';
formatOperat.dataBind = ' ';
operat.data.forEach((item, index) => {
formatOperat.dataBind += 'data-' + item + '="' + data[item] + '" '
});
html = '<a ' + formatOperat.class + formatOperat.method + formatOperat.extend + formatOperat.dataBind + '>' + formatOperat.icon + formatOperat.text + '</a>';
return html;
},
@@ -862,7 +869,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
};
operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data);
if (admin.checkAuth(operat.auth, elem)) {
html += admin.table.buildOperatHtml(operat);
html += admin.table.buildOperatHtml(operat, data);
}
break;
case 'delete':
@@ -879,7 +886,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
};
operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data);
if (admin.checkAuth(operat.auth, elem)) {
html += admin.table.buildOperatHtml(operat);
html += admin.table.buildOperatHtml(operat, data);
}
break;
}
@@ -909,7 +916,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
}
if (admin.checkAuth(operat.auth, elem)) {
html += admin.table.buildOperatHtml(operat);
html += admin.table.buildOperatHtml(operat, data);
}
});
}