245 lines
9.7 KiB
HTML
245 lines
9.7 KiB
HTML
{include file="Public:header3"/}
|
|
<div class="layui-fluid">
|
|
<div class="layui-card">
|
|
<div class="layui-card-header">资讯管理</div>
|
|
<div class="layui-card-body">
|
|
<div class="layui-form toolbar">
|
|
<div class="layui-form-item">
|
|
<div class="layui-inline">
|
|
<input type="text" id="searchTitle" placeholder="请输入标题关键词" class="layui-input">
|
|
</div>
|
|
<div class="layui-inline">
|
|
<select id="searchStatus">
|
|
<option value="">全部状态</option>
|
|
<option value="0">草稿</option>
|
|
<option value="1">已发布</option>
|
|
</select>
|
|
</div>
|
|
<div class="layui-inline">
|
|
<button class="layui-btn layui-btn-sm" id="btnSearch"><i
|
|
class="layui-icon"></i>搜索</button>
|
|
<button class="layui-btn layui-btn-sm" id="btnAdd"><i class="layui-icon"></i>添加</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<table id="tableList" lay-filter="tableList"></table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 表格操作列 -->
|
|
<script type="text/html" id="tableBar">
|
|
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
|
|
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
|
{{# if(d.status == 0){ }}
|
|
<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="publish">发布</a>
|
|
{{# }else{ }}
|
|
<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="draft">下架</a>
|
|
{{# } }}
|
|
{{# if(d.is_hot == 0){ }}
|
|
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="setHot">设为热榜</a>
|
|
{{# }else{ }}
|
|
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="cancelHot">取消热榜</a>
|
|
{{# } }}
|
|
{{# if(d.is_featured == 0){ }}
|
|
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="setFeatured">设为精选</a>
|
|
{{# }else{ }}
|
|
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="cancelFeatured">取消精选</a>
|
|
{{# } }}
|
|
</script>
|
|
|
|
<!-- 状态模板 -->
|
|
<script type="text/html" id="statusTpl">
|
|
{{# if(d.status == 1){ }}
|
|
<span class="layui-badge layui-bg-green">已发布</span>
|
|
{{# }else{ }}
|
|
<span class="layui-badge">草稿</span>
|
|
{{# } }}
|
|
</script>
|
|
|
|
<!-- 热榜模板 -->
|
|
<script type="text/html" id="hotTpl">
|
|
{{# if(d.is_hot == 1){ }}
|
|
<span class="layui-badge layui-bg-orange">是</span>
|
|
{{# }else{ }}
|
|
<span>否</span>
|
|
{{# } }}
|
|
</script>
|
|
|
|
<!-- 精选模板 -->
|
|
<script type="text/html" id="featuredTpl">
|
|
{{# if(d.is_featured == 1){ }}
|
|
<span class="layui-badge layui-bg-blue">是</span>
|
|
{{# }else{ }}
|
|
<span>否</span>
|
|
{{# } }}
|
|
</script>
|
|
|
|
{include file="Public/footer3" /}
|
|
<script>
|
|
layui.use(['table', 'form', 'jquery', 'layer', 'laydate'], function () {
|
|
var $ = layui.jquery;
|
|
var table = layui.table;
|
|
var form = layui.form;
|
|
var layer = layui.layer;
|
|
var laydate = layui.laydate;
|
|
|
|
// 渲染表格
|
|
var tableIns = table.render({
|
|
elem: '#tableList',
|
|
url: '{:url("/admin/news")}',
|
|
page: true,
|
|
cols: [[
|
|
{ type: 'numbers', title: '序号', width: 60 },
|
|
{ field: 'title', title: '标题', width: 200 },
|
|
{
|
|
field: 'cover_image', title: '封面图', width: 100, templet: function (d) {
|
|
return d.cover_image ? '<img src="' + d.cover_image + '" style="max-height: 50px;">' : '';
|
|
}
|
|
},
|
|
{ field: 'author_name', title: '作者', width: 100 },
|
|
{
|
|
field: 'publish_time', title: '发布时间', width: 160, templet: function (d) {
|
|
return d.publish_time ? layui.util.toDateString(new Date(d.publish_time).getTime(), 'yyyy-MM-dd HH:mm:ss') : '';
|
|
}
|
|
},
|
|
{ field: 'is_hot', title: '热榜', width: 80, templet: '#hotTpl' },
|
|
{ field: 'is_featured', title: '精选', width: 80, templet: '#featuredTpl' },
|
|
{ field: 'status', title: '状态', width: 80, templet: '#statusTpl' },
|
|
{
|
|
field: 'create_time', title: '创建时间', width: 160, templet: function (d) {
|
|
return layui.util.toDateString(new Date(d.create_time).getTime(), 'yyyy-MM-dd HH:mm:ss');
|
|
}
|
|
},
|
|
{ title: '操作', toolbar: '#tableBar', width: 380 }
|
|
]],
|
|
limits: [10, 15, 20, 25, 50, 100],
|
|
limit: 15,
|
|
text: {
|
|
none: '暂无相关数据'
|
|
}
|
|
});
|
|
|
|
// 搜索按钮点击事件
|
|
$('#btnSearch').click(function () {
|
|
tableIns.reload({
|
|
where: {
|
|
title: $('#searchTitle').val(),
|
|
status: $('#searchStatus').val()
|
|
},
|
|
page: {
|
|
curr: 1
|
|
}
|
|
});
|
|
});
|
|
|
|
// 添加按钮点击事件
|
|
$('#btnAdd').click(function () {
|
|
layer.open({
|
|
type: 2,
|
|
title: '添加资讯',
|
|
area: ['90%', '90%'],
|
|
shade: 0.4,
|
|
shadeClose: true,
|
|
content: '{:url("/admin/news_add")}'
|
|
});
|
|
});
|
|
|
|
// 表格工具条点击事件
|
|
table.on('tool(tableList)', function (obj) {
|
|
var data = obj.data;
|
|
var layEvent = obj.event;
|
|
|
|
if (layEvent === 'edit') {
|
|
layer.open({
|
|
type: 2,
|
|
title: '编辑资讯',
|
|
area: ['90%', '90%'],
|
|
shade: 0.4,
|
|
shadeClose: true,
|
|
content: '{:url("/admin/news_edit")}?id=' + data.id
|
|
});
|
|
} else if (layEvent === 'del') {
|
|
layer.confirm('确定要删除该资讯吗?', function (i) {
|
|
layer.close(i);
|
|
layer.load(2);
|
|
$.post('{:url("/admin/news_del")}', { id: data.id }, function (res) {
|
|
layer.closeAll('loading');
|
|
if (res.status) {
|
|
layer.msg(res.msg, { icon: 1 });
|
|
tableIns.reload();
|
|
} else {
|
|
layer.msg(res.msg, { icon: 2 });
|
|
}
|
|
}, 'json');
|
|
});
|
|
} else if (layEvent === 'publish') {
|
|
layer.load(2);
|
|
$.post('{:url("/admin/news_status")}', { id: data.id, status: 1 }, function (res) {
|
|
layer.closeAll('loading');
|
|
if (res.status) {
|
|
layer.msg(res.msg, { icon: 1 });
|
|
tableIns.reload();
|
|
} else {
|
|
layer.msg(res.msg, { icon: 2 });
|
|
}
|
|
}, 'json');
|
|
} else if (layEvent === 'draft') {
|
|
layer.load(2);
|
|
$.post('{:url("/admin/news_status")}', { id: data.id, status: 0 }, function (res) {
|
|
layer.closeAll('loading');
|
|
if (res.status) {
|
|
layer.msg(res.msg, { icon: 1 });
|
|
tableIns.reload();
|
|
} else {
|
|
layer.msg(res.msg, { icon: 2 });
|
|
}
|
|
}, 'json');
|
|
} else if (layEvent === 'setHot') {
|
|
layer.load(2);
|
|
$.post('{:url("/admin/news_hot")}', { id: data.id, is_hot: 1 }, function (res) {
|
|
layer.closeAll('loading');
|
|
if (res.status) {
|
|
layer.msg(res.msg, { icon: 1 });
|
|
tableIns.reload();
|
|
} else {
|
|
layer.msg(res.msg, { icon: 2 });
|
|
}
|
|
}, 'json');
|
|
} else if (layEvent === 'cancelHot') {
|
|
layer.load(2);
|
|
$.post('{:url("/admin/news_hot")}', { id: data.id, is_hot: 0 }, function (res) {
|
|
layer.closeAll('loading');
|
|
if (res.status) {
|
|
layer.msg(res.msg, { icon: 1 });
|
|
tableIns.reload();
|
|
} else {
|
|
layer.msg(res.msg, { icon: 2 });
|
|
}
|
|
}, 'json');
|
|
} else if (layEvent === 'setFeatured') {
|
|
layer.load(2);
|
|
$.post('{:url("/admin/news_featured")}', { id: data.id, is_featured: 1 }, function (res) {
|
|
layer.closeAll('loading');
|
|
if (res.status) {
|
|
layer.msg(res.msg, { icon: 1 });
|
|
tableIns.reload();
|
|
} else {
|
|
layer.msg(res.msg, { icon: 2 });
|
|
}
|
|
}, 'json');
|
|
} else if (layEvent === 'cancelFeatured') {
|
|
layer.load(2);
|
|
$.post('{:url("/admin/news_featured")}', { id: data.id, is_featured: 0 }, function (res) {
|
|
layer.closeAll('loading');
|
|
if (res.status) {
|
|
layer.msg(res.msg, { icon: 1 });
|
|
tableIns.reload();
|
|
} else {
|
|
layer.msg(res.msg, { icon: 2 });
|
|
}
|
|
}, 'json');
|
|
}
|
|
});
|
|
});
|
|
</script> |