QQBot/web/jianrTask.html

123 lines
4.1 KiB
HTML
Raw Normal View History

2022-07-25 12:35:50 +08:00
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
2022-07-25 12:39:03 +08:00
<title>舰R脚本管理器</title>
2022-07-25 12:35:50 +08:00
<link rel="stylesheet" href="layui/css/layui.css">
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
</head>
<body>
<div class="myDiy">
<blockquote class="layui-elem-quote">舰R脚本管理器<span id="taskStatus"></span><br/><br/><span id="taskName">当前无任务</span><br/><br/><span id="runIndex"></span><br/><br/><span id="log"></span>
</blockquote>
<button class="layui-btn layui-btn-lg layui-btn-normal" onclick="createTask()">创建任务</button>
<br/><br/><br/>
<div class="layui-bg-gray layui-row layui-col-space15" id="card" style="padding: 30px;">
</div>
</div>
</body>
<script src="layui/layui.js"></script>
<script src="layui/jquery-3.2.1.js"></script>
<script>
function createCard(name) {
let html = '<div class="layui-card layui-col-md3 layui-col-lg-offset1"><div class="layui-card-header">' + name + '</div><div class="layui-card-body"><button class="layui-btn layui-btn-radius layui-btn-normal" onclick="runTask(\'' + name + '\')"><i class="layui-icon">&#xe652;</i>运行</button><br/><br/><button class="layui-btn layui-btn-radius layui-btn-warm" onclick="stopTask()"><i class="layui-icon">&#xe651;</i>停止</button><br/><br/><button class="layui-btn layui-btn-radius layui-btn-danger" onclick="removeTask(\'' + name + '\')"><i class="layui-icon">&#xe64d;</i>删除</button></div></div>';
$('#card').append(html)
}
function createTask() {
layer.prompt({
formType: 2,
value: '{\n' +
' "name": "",\n' +
' "device": "192.168.31.46:6666",\n' +
' "run": [\n' +
' {\n' +
' "name": "",\n' +
' "nextWaitTime": 0,\n' +
' "randomNextWaitTime": 0,\n' +
' "model": "click",\n' +
' "x": 0,\n' +
' "y": 0,\n' +
' "rx": 0,\n' +
' "ry": 0\n' +
' }\n' +
' ]\n' +
'}',
title: '创建任务',
maxlength: 99999,
area: ['800px', '350px'] //自定义文本域宽高
}, function (value, index, elem) {
2022-07-25 12:42:55 +08:00
$.post("/jianr/task/add.do", {task: value}, function (json) {
2022-07-25 12:35:50 +08:00
layer.msg(json.msg)
})
layer.close(index);
});
}
function runTask(name) {
2022-07-25 12:42:55 +08:00
$.post("/jianr/run.do", {task: name}, function (json) {
2022-07-25 12:35:50 +08:00
layer.msg(json.msg)
})
}
function stopTask() {
2022-07-25 12:42:55 +08:00
$.post("/jianr/stop.do", function (json) {
2022-07-25 12:35:50 +08:00
layer.msg(json.msg)
})
}
function removeTask(name) {
2022-07-25 12:42:55 +08:00
$.post("/jianr/task/remove.do", {task: name}, function (json) {
2022-07-25 12:35:50 +08:00
layer.msg(json.msg)
})
}
function getStatus() {
2022-07-25 12:42:55 +08:00
$.post("/jianr/status.do", function (json) {
2022-07-25 12:35:50 +08:00
if(json.data.status){
$('#taskStatus')[0].innerHTML="运行"
$('#taskStatus').css('color','#5C962C')
$('#taskName')[0].innerHTML='执行次数: '+json.data.runIndex;
$('#runIndex')[0].innerHTML='当前正在执行: '+json.data.taskName;
$('#log')[0].innerHTML=json.data.log
}else{
$('#taskStatus')[0].innerHTML="停止"
$('#taskStatus').css('color','#FF5722')
}
getStatus()
})
}
window.onload = function init() {
2022-07-25 12:42:55 +08:00
$.get("/jianr/task/list.do", function (json) {
2022-07-25 12:35:50 +08:00
json.data.forEach(function (item) {
createCard(item)
}
)
})
getStatus()
}
</script>
<style>
.myDiy {
width: 40%;
height: 300px;
margin-top: 10px;
margin-left: 25%;
}
.button {
width: 100px;
height: 100px;
font-size: 1em;
}
</style>
</html>