TaoLer/app/admin/view/content/cate/index.html

237 lines
7.2 KiB
HTML
Raw Normal View History

2023-03-16 22:40:15 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>分类管理</title>
<link rel="stylesheet" href="/static/component/pear/css/pear.css" />
</head>
<body class="pear-container">
<div class="layui-card">
<div class="layui-card-body">
<table id="cate-table" lay-filter="cate-table"></table>
</div>
</div>
<script type="text/html" id="cate-toolbar">
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
<i class="layui-icon layui-icon-add-1"></i>
新增
</button>
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
<i class="layui-icon layui-icon-delete"></i>
删除
</button>
<button class="pear-btn pear-btn-success pear-btn-md" lay-event="expandAll">
<i class="layui-icon layui-icon-spread-left"></i>
展开
</button>
<button class="pear-btn pear-btn-success pear-btn-md" lay-event="foldAll">
<i class="layui-icon layui-icon-shrink-right"></i>
折叠
</button>
</script>
<script type="text/html" id="cate-bar">
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" data-href="{:url('cate/edit')}"><i class="layui-icon layui-icon-edit"></i></button>
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
</script>
<script type="text/html" id="cate-enable">
<input type="checkbox" name="is_hot" value="{{d.id}}" lay-skin="primary" lay-filter="cate-enable" {{ d.is_hot == 1 ? 'checked' : '' }} />
</script>
<script type="text/html" id="icon">
<i class="layui-icon {{d.icon}}"></i>
</script>
<script src="/static/component/layui/layui.js"></script>
<script src="/static/component/pear/pear.js"></script>
<script>
const CATE = "{:url('content.cate/list')}";
const DELETE = "{:url('content.cate/delete')}";
const ENABLE = "{:url('content.cate/hot')}";
layui.use(['table','form','jquery','treetable'],function () {
let $ = layui.jquery;
let table = layui.table;
let form = layui.form;
let treetable = layui.treetable;
let MODULE_PATH = "operate/";
let cols = [
[
{type: 'checkbox'}
,{field: 'catename', title: '分类名', width: 150}
,{field: 'appname', title: '所属应用', width: 90}
,{field: 'ename', title: 'EN别名', width: 100}
,{field: 'detpl',title: '模板', align: 'center',width: 100}
,{field: 'icon', title: '图标', align: 'center',width: 50, templet: '<p><i class="layui-icon {{d.icon}}"></i></p>'}
,{field: 'is_hot', title: '热门', align: 'center',width: 50, templet: '#cate-enable'}
,{field: 'desc', title: '描述', minWidth: 200}
,{field: 'id', title: 'ID',width: 60}
,{field: 'sort', title: '排序', width: 80, sort: true}
,{title: '操作', width: 120, align: 'center', toolbar: '#cate-bar'}
]
];
window.render = function(){
treetable.render({
treeColIndex: 1,
treeSpid: 0,
treeIdName: 'id',
treePidName: 'pid',
skin:'line',
treeDefaultClose: true,
toolbar:'#cate-toolbar',
elem: '#cate-table',
url: CATE,
page: false,
cols: cols
});
}
render();
table.on('tool(cate-table)',function(obj){
if (obj.event === 'remove') {
window.remove(obj);
} else if (obj.event === 'edit') {
window.edit(obj);
}
})
table.on('toolbar(cate-table)', function(obj){
if(obj.event === 'add'){
window.add();
} else if(obj.event === 'refresh'){
window.refresh();
} else if(obj.event === 'batchRemove'){
window.batchRemove(obj);
} else if(obj.event === 'expandAll'){
treetable.expandAll("#cate-table");
} else if(obj.event === 'foldAll'){
treetable.foldAll("#cate-table");
}
});
form.on('checkbox(cate-enable)', function(obj) {
layer.tips(this.value + ' ' + this.name + '' + obj.elem.checked, obj.othis);
var status = obj.elem.checked ? 1 : 0;
//执行用户审核
$.ajax({
type:'post',
url: ENABLE,
data:{"id":this.value,"is_hot":status},
dataType:'json',
success:function(res){
if(res.code === 0){
layer.msg(res.msg,{
icon:res.icon,
time:2000
}
//,function(){location.reload();}
);
} else {
layer.open({
title:'审核失败',
content:res.msg,
icon:5,
adim:6
})
}
}
});
return false;
});
window.add = function(){
layer.open({
type: 2,
title: '新增',
shade: 0.1,
area: ['450px', '500px'],
content: 'add.html'
});
}
window.edit = function(obj){
layer.open({
type: 2,
title: '修改',
shade: 0.1,
area: ['450px', '500px'],
content: 'edit.html?id=' + obj.data.id
});
}
window.remove = function(obj){
layer.confirm('确定要删除该权限', {icon: 3, title:'提示'}, function(index){
layer.close(index);
let loading = layer.load();
$.ajax({
url: DELETE+"?id="+obj.data['id'],
dataType:'json',
type:'delete',
success:function(result){
layer.close(loading);
if(result.code === 0){
layer.msg(result.msg,{icon:1,time:1000},function(){
obj.del();
});
}else{
layer.msg(result.msg,{icon:2,time:1000});
}
}
})
});
}
window.batchRemove = function(obj) {
let data = table.checkStatus(obj.config.id).data;
if (data.length === 0) {
layer.msg("未选中数据", {
icon: 3,
time: 1000
});
return false;
}
let ids = "";
for (let i = 0; i < data.length; i++) {
ids += data[i].id + ",";
}
ids = ids.substr(0, ids.length - 1);
layer.confirm('确定要删除这些权限', {
icon: 3,
title: '提示'
}, function(index) {
layer.close(index);
let loading = layer.load();
$.ajax({
url: DELETE + "?id=" + ids,
dataType: 'json',
type: 'delete',
success: function(result) {
layer.close(loading);
if (result.success) {
layer.msg(result.msg, {
icon: 1,
time: 1000
}, function() {
table.reload('user-table');
});
} else {
layer.msg(result.msg, {
icon: 2,
time: 1000
});
}
}
})
});
}
})
</script>
</body>
</html>