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

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

@@ -76,8 +76,15 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
auth: 'edit', auth: 'edit',
class: 'layui-btn layui-btn-xs layui-btn-success', class: 'layui-btn layui-btn-xs layui-btn-success',
extend: 'data-full="true"', 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), ]], init),
@@ -99,6 +106,25 @@ define(["jquery", "easy-admin", "treetable", "iconPickerFa", "autocomplete"], fu
renderTable(); 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 () { $('body').on('click', '[data-treetable-delete]', function () {
var tableId = $(this).attr('data-treetable-delete'), var tableId = $(this).attr('data-treetable-delete'),
url = $(this).attr('data-url'); url = $(this).attr('data-url');

View File

@@ -718,7 +718,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
return html; return html;
}, },
buildOperatHtml: function (operat) { buildOperatHtml: function (operat, data) {
var html = ''; var html = '';
operat.class = operat.class || ''; operat.class = operat.class || '';
operat.icon = operat.icon || ''; operat.icon = operat.icon || '';
@@ -727,6 +727,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
operat.extend = operat.extend || ''; operat.extend = operat.extend || '';
operat.method = operat.method || 'open'; operat.method = operat.method || 'open';
operat.field = operat.field || 'id'; operat.field = operat.field || 'id';
operat.data = operat.data || ['id'];
operat.title = operat.title || operat.text; operat.title = operat.title || operat.text;
operat.text = operat.text || operat.title; operat.text = operat.text || operat.title;
@@ -742,7 +743,13 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
} else { } else {
formatOperat.method = formatOperat.method !== '' ? 'data-request="' + formatOperat.url + '" data-title="' + formatOperat.title + '" ' : ''; 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; return html;
}, },
@@ -862,7 +869,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
}; };
operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data); operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data);
if (admin.checkAuth(operat.auth, elem)) { if (admin.checkAuth(operat.auth, elem)) {
html += admin.table.buildOperatHtml(operat); html += admin.table.buildOperatHtml(operat, data);
} }
break; break;
case 'delete': case 'delete':
@@ -879,7 +886,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
}; };
operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data); operat.url = admin.table.toolSpliceUrl(operat.url, operat.field, data);
if (admin.checkAuth(operat.auth, elem)) { if (admin.checkAuth(operat.auth, elem)) {
html += admin.table.buildOperatHtml(operat); html += admin.table.buildOperatHtml(operat, data);
} }
break; break;
} }
@@ -909,7 +916,7 @@ define(["jquery", "tableSelect", "ckeditor", 'miniTheme', 'tableData', 'citypick
} }
if (admin.checkAuth(operat.auth, elem)) { if (admin.checkAuth(operat.auth, elem)) {
html += admin.table.buildOperatHtml(operat); html += admin.table.buildOperatHtml(operat, data);
} }
}); });
} }