Files
YwxAppThink/public/static/backend/modules/category.js
T

95 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
layui.define(['http', 'auth', 'table', 'layer'], function (exports) {
var table = layui.table,
layer = layui.layer,
auth = layui.auth,
http = layui.http;
// 权限控制器前缀:与后端 BackendPower.namearticles:backend:category:add 等)对齐
auth.setController('articles:backend:category');
auth.render();
var MODULE = 'articles/backend.category',
FUNC = {
index: MODULE + '/index',
delete: MODULE + '/delete'
};
var obj = {
init: function () {
this.render();
this.events();
},
render: function () {
table.render({
elem: '#table',
url: FUNC.index,
toolbar: '#toolbar',
defaultToolbar: ['filter', 'print', 'exports'],
method: 'get',
cols: [[
{field: 'id', title: 'ID', width: 70, sort: true},
{field: 'name', title: '名称', width: 150},
{field: 'alias', title: '别名', width: 150},
{field: 'description', title: '描述'},
{field: 'sort', title: '排序', width: 80, sort: true},
{field: 'status', title: '状态', width: 90, templet: '#statusTpl'},
{field: 'create_at', title: '创建时间', width: 170, templet: function (d) {
return d.create_at ? layui.util.toDateString(d.create_at * 1000, 'yyyy-MM-dd HH:mm:ss') : '';
}},
{title: '操作', width: 130, templet: '#action', fixed: 'right'}
]],
page: true,
limit: 10,
limits: [10, 20, 50, 100],
response: {statusCode: 0},
parseData: function (res) {
return {
code: res.code,
msg: res.msg,
count: res.count,
data: res.data
};
}
});
},
events: function () {
// 顶部工具条
table.on('toolbar(table)', function (obj) {
var event = obj.event;
if (event === 'add') {
if (!auth.has('add')) return layer.msg('无权限', {icon: 2});
window.location.href = '/articles/backend.category/edit';
}
});
// 行内操作
table.on('tool(table)', function (obj) {
var data = obj.data,
event = obj.event;
if (event === 'edit') {
if (!auth.has('edit')) return layer.msg('无权限', {icon: 2});
window.location.href = '/articles/backend.category/edit/id/' + data.id;
} else if (event === 'del') {
if (!auth.has('delete')) return layer.msg('无权限', {icon: 2});
layer.confirm('确定删除该分类吗?', {title: '提示'}, function (index) {
http.delete(FUNC.delete, {id: data.id}, function (res) {
if (res.code === 0) {
layer.msg(res.msg || '删除成功', {icon: 1});
table.reload('table');
} else {
layer.msg(res.msg || '删除失败', {icon: 2});
}
});
layer.close(index);
});
}
});
}
};
obj.init();
exports('category', obj);
});