更新后端内容
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlelist.php";i:1746800071;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<?php /*a:2:{s:57:"E:\Demo\PHP\yunzer\app\admin\view\article\articlelist.php";i:1747323773;s:51:"E:\Demo\PHP\yunzer\app\admin\view\public\header.php";i:1746890051;}*/ ?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -95,8 +95,25 @@
|
||||
<body style="padding:10px; box-sizing: border-box;">
|
||||
<div class="config-container">
|
||||
<div class="config-header" style="display:flex;justify-content: space-between;">
|
||||
<div>
|
||||
<div style="display: flex; align-items: center;">
|
||||
<span>文章列表</span>
|
||||
<div class="shaixuan">
|
||||
<label>筛选:</label>
|
||||
<div class="layui-form">
|
||||
<div class="layui-input-inline">
|
||||
<select id="categoryFilter" lay-filter="categoryFilter" lay-verify="">
|
||||
<option value="">全部分类</option>
|
||||
<?php if(is_array($categories) || $categories instanceof \think\Collection || $categories instanceof \think\Paginator): $i = 0; $__LIST__ = $categories;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$category): $mod = ($i % 2 );++$i;?>
|
||||
<optgroup label="<?php echo htmlentities((string) $category['name']); ?>">
|
||||
<?php if(is_array($category['children']) || $category['children'] instanceof \think\Collection || $category['children'] instanceof \think\Paginator): $i = 0; $__LIST__ = $category['children'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$subCategory): $mod = ($i % 2 );++$i;?>
|
||||
<option value="<?php echo htmlentities((string) $subCategory['id']); ?>"><?php echo htmlentities((string) $subCategory['name']); ?></option>
|
||||
<?php endforeach; endif; else: echo "" ;endif; ?>
|
||||
</optgroup>
|
||||
<?php endforeach; endif; else: echo "" ;endif; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="add()">
|
||||
@@ -108,73 +125,119 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="layui-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="20">ID</th>
|
||||
<th>标题</th>
|
||||
<th>分类</th>
|
||||
<th>封面</th>
|
||||
<th>作者</th>
|
||||
<th>状态</th>
|
||||
<th>发布时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if(is_array($lists) || $lists instanceof \think\Collection || $lists instanceof \think\Paginator): $i = 0; $__LIST__ = $lists;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
|
||||
<tr>
|
||||
<td><?php echo htmlentities((string) $vo['id']); ?></td>
|
||||
<td><?php echo htmlentities((string) $vo['title']); ?></td>
|
||||
<td><?php echo htmlentities((string) $vo['cate']); ?></td>
|
||||
<td>
|
||||
<?php if($vo['image']): ?>
|
||||
<img src="<?php echo htmlentities((string) $vo['image']); ?>" style="max-width: 50px; max-height: 50px;">
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?php echo htmlentities((string) $vo['author']); ?></td>
|
||||
<td>
|
||||
<?php switch($vo['status']): case "0": ?><span style="color:red;">草稿</span><?php break; case "1": ?><span style="color:orange;">待审核</span><?php break; case "2": ?><span style="color:green;">已发布</span><?php break; case "3": ?><span style="color:gray;">隐藏</span><?php break; ?>
|
||||
<?php endswitch; ?>
|
||||
</td>
|
||||
<td><?php echo htmlentities((string) $vo['publishdate']); ?></td>
|
||||
<td>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" onclick="edit(<?php echo htmlentities((string) $vo['id']); ?>)">
|
||||
<i class="layui-icon layui-icon-edit"></i>编辑
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" onclick="del(<?php echo htmlentities((string) $vo['id']); ?>)">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; endif; else: echo "" ;endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<table id="articleTable" lay-filter="articleTable"></table>
|
||||
</div>
|
||||
|
||||
<script type="text/html" id="imageTemplate">
|
||||
{{# if(d.image){ }}
|
||||
<img src="{{ d.image }}" style="max-width: 50px; max-height: 50px;">
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="statusTemplate">
|
||||
{{# if(d.status === 0){ }}
|
||||
<span style="color:red;">草稿</span>
|
||||
{{# } else if(d.status === 1){ }}
|
||||
<span style="color:orange;">待审核</span>
|
||||
{{# } else if(d.status === 2){ }}
|
||||
<span style="color:green;">已发布</span>
|
||||
{{# } else if(d.status === 3){ }}
|
||||
<span style="color:gray;">隐藏</span>
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="operationBar">
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">
|
||||
<i class="layui-icon layui-icon-edit"></i>编辑
|
||||
</button>
|
||||
<button type="button" class="layui-btn layui-btn-primary layui-btn-xs" lay-event="del">
|
||||
<i class="layui-icon layui-icon-delete"></i>删除
|
||||
</button>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
layui.use(['layer'], function () {
|
||||
layer = layui.layer;
|
||||
$ = layui.jquery;
|
||||
layui.use(['layer', 'form', 'table'], function () {
|
||||
var layer = layui.layer;
|
||||
var $ = layui.jquery;
|
||||
var form = layui.form;
|
||||
var table = layui.table;
|
||||
|
||||
// 初始化表格
|
||||
table.render({
|
||||
elem: '#articleTable',
|
||||
url: '/admin/article/articlelist',
|
||||
method: 'post',
|
||||
cols: [[
|
||||
{field: 'id', title: 'ID', align:'center', width: 80},
|
||||
{field: 'title', title: '标题'},
|
||||
{field: 'cate', title: '分类', align:'center', width: 180},
|
||||
{field: 'image', title: '封面', templet: '#imageTemplate', align:'center', width: 180},
|
||||
{field: 'author', title: '作者', align:'center', width: 120},
|
||||
{field: 'status', title: '状态', templet: '#statusTemplate', align:'center', width: 80},
|
||||
{field: 'publishdate', title: '发布时间', align:'center', width: 180},
|
||||
{title: '操作', toolbar: '#operationBar', align:'center', width: 150}
|
||||
]],
|
||||
page: true,
|
||||
limit: 20,
|
||||
limits: [10, 20, 30, 50],
|
||||
//height: 'full-220'
|
||||
});
|
||||
|
||||
// 监听工具条事件
|
||||
table.on('tool(articleTable)', function(obj){
|
||||
var data = obj.data;
|
||||
if(obj.event === 'edit'){
|
||||
edit(data.id);
|
||||
} else if(obj.event === 'del'){
|
||||
del(data.id);
|
||||
}
|
||||
});
|
||||
|
||||
// 监听分类筛选变化
|
||||
form.on('select(categoryFilter)', function(data){
|
||||
filterByCategory(data.value);
|
||||
});
|
||||
});
|
||||
|
||||
function filterByCategory(categoryId) {
|
||||
if (!categoryId) {
|
||||
layui.table.reload('articleTable', {
|
||||
where: {},
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var categoryName = $('#categoryFilter option[value="' + categoryId + '"]').text();
|
||||
layui.table.reload('articleTable', {
|
||||
where: {
|
||||
category: categoryName
|
||||
},
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function add() {
|
||||
window.location.href = '<?php echo url("article/add"); ?>';
|
||||
window.location.href = '/admin/article/add';
|
||||
}
|
||||
|
||||
function edit(id) {
|
||||
window.location.href = '<?php echo url("article/edit"); ?>?id=' + id;
|
||||
window.location.href = '/admin/article/edit?id=' + id;
|
||||
}
|
||||
|
||||
function del(id) {
|
||||
layer.confirm('确定要删除该文章吗?', {
|
||||
btn: ['确定', '取消']
|
||||
}, function () {
|
||||
$.post('<?php echo url("article/delete"); ?>', { id: id }, function (res) {
|
||||
$.post('/admin/article/delete', { id: id }, function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, { icon: 1 });
|
||||
setTimeout(function () {
|
||||
window.location.reload();
|
||||
layui.table.reload('articleTable');
|
||||
}, 1000);
|
||||
} else {
|
||||
layer.msg(res.msg, { icon: 2 });
|
||||
@@ -184,6 +247,6 @@
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
window.location.reload();
|
||||
layui.table.reload('articleTable');
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user