ruankao/app/admin/view/yunzeradmin/contentpush.php
2025-07-14 14:55:25 +08:00

231 lines
6.9 KiB
PHP

{include file="public/header" /}
<div class="config-container">
<!-- 页面头部样式 -->
<div class="config-header" style="display: flex;flex-direction: column;flex-wrap: wrap;align-items: flex-start;">
<div class="maintitle">
<i class="layui-icon layui-icon-notice"></i>
<span>内容推送列表</span>
</div>
<div style="display: flex;align-items: flex-start;flex-direction: column;gap: 15px;margin-bottom: 10px;">
<div>
<!-- <button class="layui-btn layui-bg-blue" onclick="add()">
<i class="layui-icon layui-icon-add-1"></i>添加推送
</button> -->
<button class="layui-btn layui-bg-blue" onclick="setting()">
<i class="layui-icon layui-icon-set-fill"></i>推送配置
</button>
<button type="button" class="layui-btn layui-btn-primary layui-border-green" onclick="pushSelected()">
<i class="layui-icon layui-icon-release"></i>推送
</button>
<button type="button" class="layui-btn layui-btn-primary layui-border-blue" onclick="refresh()">
<i class="layui-icon layui-icon-refresh"></i>刷新
</button>
</div>
</div>
</div>
<table id="contentPushTable" lay-filter="contentPushTable"></table>
</div>
<script type="text/javascript">
layui.use(['table', 'layer'], function () {
var table = layui.table;
var layer = layui.layer;
var $ = layui.jquery;
// 初始化表格
table.render({
elem: '#contentPushTable',
url: '{$config["admin_route"]}yunzeradmin/contentpushlist',
page: true,
cols: [[
{ type: 'checkbox', fixed: 'left' }, // 多选全选
// {field: 'id', title: 'ID', width: 80, sort: true},
{
field: 'type', title: '类型', width: 80, templet: function (d) {
return d.type == 'article' ? '文章' : '资源';
}
},
{ field: 'title', title: '标题' },
{
field: 'url', title: '链接', templet: function (d) {
if (d.type == 'article') {
return '<a href="https://www.yunzer.cn/index/articles/detail?id=' + d.id + '" target="_blank">https://www.yunzer.cn/index/articles/detail?id=' + d.id + '</a>';
} else if (d.type == 'resource') {
return '<a href="https://www.yunzer.cn/index/resources/detail?id=' + d.id + '" target="_blank">https://www.yunzer.cn/index/resources/detail?id=' + d.id + '</a>';
} else {
return '';
}
}
},
{
field: 'push', title: '推送状态', width: 100, templet: function (d) {
return d.push == 1 ?
'<span class="layui-badge layui-bg-green">已推送</span>' :
'<span class="layui-badge">未推送</span>';
}
},
// {field: 'sort', title: '排序', width: 100, sort: true},
{ field: 'create_time', title: '创建时间', width: 180 },
// {title: '操作', width: 200, toolbar: '#tableBar', fixed: 'right'}
]],
limit: 10,
limits: [10, 20, 30, 50]
});
// 监听工具条
table.on('tool(contentPushTable)', function (obj) {
var data = obj.data;
if (obj.event === 'edit') {
edit(data.id);
} else if (obj.event === 'del') {
del(data.id);
} else if (obj.event === 'status') {
changeStatus(data.id, data.status);
}
});
});
// 添加
function add() {
layer.open({
type: 2,
title: '添加内容推送',
shade: 0.3,
area: ['800px', '600px'],
content: "{$config['admin_route']}yunzeradmin/contentpushadd"
});
}
// 编辑
function edit(id) {
layer.open({
type: 2,
title: '编辑内容推送',
shade: 0.3,
area: ['800px', '600px'],
content: "{$config['admin_route']}yunzeradmin/contentpushedit?id=" + id
});
}
// 删除
function del(id) {
layer.confirm('确定要删除这条推送吗?', {
icon: 3,
btn: ['确定', '取消']
}, function () {
$.post("{$config['admin_route']}yunzeradmin/contentpushdel", { 'id': id }, function (res) {
if (res.code > 0) {
layer.msg(res.msg, { icon: 2 });
} else {
layer.msg(res.msg, { icon: 1 });
layui.table.reload('contentPushTable');
}
}, 'json');
});
}
// 修改状态
function changeStatus(id, status) {
var newStatus = status == 1 ? 0 : 1;
$.post("{$config['admin_route']}yunzeradmin/contentpushstatus", {
'id': id,
'status': newStatus
}, function (res) {
if (res.code > 0) {
layer.msg(res.msg, { icon: 2 });
} else {
layer.msg(res.msg, { icon: 1 });
layui.table.reload('contentPushTable');
}
}, 'json');
}
//配置
function setting() {
layer.open({
type: 2,
title: '推送配置',
shade: 0.3,
area: ['1000px', '800px'],
content: "{$config['admin_route']}yunzeradmin/contentpushsetting"
});
}
//推送数据
function pushSelected() {
var checkStatus = layui.table.checkStatus('contentPushTable');
var data = checkStatus.data;
if (data.length === 0) {
layer.msg('请先选择要推送的数据', { icon: 2 });
return;
}
$.getJSON("{$config['admin_route']}yunzeradmin/contentpushsetting", function (res) {
if (res.code !== 0 || !res.data || res.data.length === 0) {
layer.msg('暂无可用推送平台');
return;
}
var html = '<div style="padding:10px;"><table class="layui-table"><thead><tr><th>ID</th><th>平台名称</th><th>类型标识</th></tr></thead><tbody>';
res.data.forEach(function (item) {
if (item.status == 1) {
html += '<tr style="cursor:pointer" data-type="' + item.platformType + '" data-title="' + item.title.replace(/'/g, "\\'") + '">';
html += '<td>' + item.id + '</td>';
html += '<td>' + item.title + '</td>';
html += '<td>' + item.platformType + '</td>';
html += '</tr>';
}
});
html += '</tbody></table></div>';
layer.open({
type: 1,
title: '选择推送平台',
area: ['500px', '350px'],
content: html,
success: function (layero, index) {
// 事件委托,避免全局变量
$(layero).find('tr[data-type]').on('click', function () {
var platformType = $(this).data('type');
var platformTitle = $(this).data('title');
layer.close(index);
var urls = [];
data.forEach(function (item) {
urls.push('https://www.yunzer.cn/index/' + (item.type === 'resource' ? 'resources' : 'articles') + '/detail?id=' + item.id);
});
$.ajax({
url: "{$config['admin_route']}yunzeradmin/gopush",
type: "POST",
contentType: "application/json",
data: JSON.stringify({
platformType: platformType,
urls: urls
}),
dataType: "json",
success: function (res) {
layer.msg(res.msg, { icon: res.code === 0 ? 1 : 2, time: 5000 });
layui.table.reload('contentPushTable');
}
});
});
}
});
});
}
// 刷新列表
function refresh() {
layui.table.reload('contentPushTable');
}
</script>
<!-- 表格操作列模板 -->
<!-- <script type="text/html" id="tableBar">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
</script> -->
{include file="public/tail" /}