2022-03-02 23:10:24 +08:00

126 lines
6.3 KiB
PHP

{extend name='table'}
{block name="button"}
<!--{if isset($super) and $super}-->
<a class="layui-btn layui-btn-sm layui-btn-primary" data-queue="{:url('admin/api.plugs/optimize')}">优化数据库</a>
{if $iswin}
<button data-load='{:url("admin/api.queue/start")}' class='layui-btn layui-btn-sm layui-btn-primary'>开启后台服务</button>
<button data-load='{:url("admin/api.queue/stop")}' class='layui-btn layui-btn-sm layui-btn-primary'>关闭后台服务</button>
{/if}
<!--{/if}-->
<!--{if auth("clean")}-->
<button data-queue='{:url("clean")}' class='layui-btn layui-btn-sm layui-btn-primary'>定时清理数据</button>
<!--{/if}-->
<!--{if auth("remove")}-->
<button data-action='{:url("remove")}' data-rule="id#{id}" data-table-id="QueueData" data-confirm="确定批量删除记录吗?" class='layui-btn layui-btn-sm layui-btn-primary'>批量删除任务</button>
<!--{/if}-->
{/block}
{block name="content"}
<div class="think-box-notify">
<!--{if isset($super) and $super}-->
<b>服务状态:</b><b class="margin-right-5" data-queue-message><span class="color-desc">检查中</span></b>
<b data-tips-text="点击可复制【任务服务启动指令】" class="layui-icon pointer margin-right-20" data-copy="{$command|default=''}">&#xe60e;</b>
<script>$('[data-queue-message]').load('{:sysuri("admin/api.queue/status")}')</script>
<!--{/if}-->
<b>任务统计:</b>待处理 <b class="color-text">{$total.pre|default=0}</b> 个任务,处理中 <b class="color-blue">{$total.dos|default=0}</b> 个任务,已完成 <b class="color-green">{$total.oks|default=0}</b> 个任务,已失败 <b class="color-red">{$total.ers|default=0}</b> 个任务。
</div>
<div class="think-box-shadow">
{include file='queue/index_search'}
<table id="QueueData" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
</div>
{/block}
{block name='script'}
<style>
#QueueData + div tbody .layui-table-cell {
height: 42px;
line-height: 22px;
}
#QueueData + div tbody .layui-table-cell .layui-btn {
margin-top: 8px;
}
#QueueData + div tbody .layui-table-cell.laytable-cell-checkbox {
line-height: 42px;
}
</style>
<script>
$(function () {
$('#QueueData').layTable({
height: 'full',
even: true, sort: {field: 'loops_time desc,id', type: 'desc'},
cols: [[
{checkbox: true, fixed: 'left'},
{
field: 'id', title: '任务名称', minWidth: 230, sort: true, templet: function (d) {
if (d.loops_time > 0) {
d.one = '<span class="layui-badge think-bg-blue">循</span>';
} else {
d.one = '<span class="layui-badge think-bg-red">次</span>';
}
if (d.rscript === 1) {
d.two = '<span class="layui-badge layui-bg-green">复</span>';
} else {
d.two = '<span class="layui-badge think-bg-violet">单</span>';
}
return laytpl('{{d.one}}任务编号:<b>{{d.code}}</b><br>{{d.two}}任务名称:{{d.title}}').render(d);
}
},
{
field: 'exec_time', title: '任务计划', minWidth: 300, templet: function (d) {
d.html = '执行指令:' + d.command + '<br>计划执行:' + d.exec_time;
if (d.loops_time > 0) {
return d.html + ' ( 每 <b class="color-blue">' + d.loops_time + '</b> 秒 ) ';
} else {
return d.html + ' <span class="color-desc">( 单次任务 )</span> ';
}
}
},
{
field: 'loops_time', title: '执行状态', width: 400, templet: function (d) {
d.html = [
'<span class="layui-badge layui-badge-middle layui-bg-gray pull-left" style="width:2em">未知</span>',
'<span class="layui-badge layui-badge-middle layui-bg-black pull-left" style="width:2em">等待</span>',
'<span class="layui-badge layui-badge-middle layui-bg-blue pull-left" style="width:2em">执行</span>',
'<span class="layui-badge layui-badge-middle layui-bg-green pull-left" style="width:2em">完成</span>',
'<span class="layui-badge layui-badge-middle layui-bg-red pull-left" style="width:2em">失败</span>',
][d.status] || '';
d.html += '执行时间:';
d.enter_time = d.enter_time || '', d.outer_time = d.outer_time || '0.0000';
if (d.enter_time.length > 12) {
d.html += d.enter_time.substring(12) + '<span class="color-desc"> ( 耗时 ' + d.outer_time + ' )</span>';
d.html += ',已执行 <b>' + (d.attempts || 0) + '</b> 次';
} else {
d.html += '<span class="color-desc">任务未执行</span>'
}
return d.html + '<br>执行结果:<span class="color-blue">' + (d.exec_desc || '<span class="color-desc">未获取到执行结果</span>') + '</span>';
}
},
{toolbar: '#toolbar', title: '操作面板', align: 'center', minWidth: 200}
]]
});
});
</script>
<script type="text/html" id="toolbar">
<!--{if auth('redo')}-->
{{# if(d.status===4||d.status===3){ }}
<a class="layui-btn layui-btn-sm" data-confirm="确定要重置该任务吗?" data-queue="{:url('redo')}?code={{d.code}}"> </a>
{{# }else{ }}
<a class="layui-btn layui-btn-sm layui-btn-disabled"> </a>
{{# } }}
<!--{/if}-->
<!--{if auth('remove')}-->
<a class='layui-btn layui-btn-sm layui-btn-danger' data-confirm="确定要删除该任务吗?" data-action='{:url("remove")}' data-value="id#{{d.id}}"> </a>
<!--{/if}-->
<a class='layui-btn layui-btn-sm layui-btn-normal' onclick="$.loadQueue('{{d.code}}',false,this)"> </a>
</script>
{/block}