7668d9bc by 赵千

定时任务前端编写

1 parent 3b051109
......@@ -6,15 +6,19 @@ class sjsbTask {
// 定时任务查询接口
async getTaskListByName (data) {
return request({
url: SERVER.SERVERAPI + '/sjsbTask/getTaskListByName',
method: 'post',
data
url: SERVER.SERVERAPI + '/rest/schedule/getScheduleList',
method: 'get',
params: {
jobName: data.jobName,
pageNo: data.currentPage,
pageSize: data.pageSize
}
})
}
// 定时任务新增接口
async sjsbTaskSave (data) {
return request({
url: SERVER.SERVERAPI + '/sjsbTask/save',
url: SERVER.SERVERAPI + '/rest/schedule/add',
method: 'post',
data
})
......@@ -22,7 +26,7 @@ class sjsbTask {
// 修改定时任务执行时间接口
async updateCron (data) {
return request({
url: SERVER.SERVERAPI + '/sjsbTask/updateCron',
url: SERVER.SERVERAPI + '/rest/schedule/update',
method: 'post',
data
})
......@@ -30,52 +34,32 @@ class sjsbTask {
// 定时任务删除接口
async sjsbTaskRemove (id) {
return request({
url: SERVER.SERVERAPI + '/sjsbTask/remove',
url: SERVER.SERVERAPI + '/rest/schedule/delete',
method: 'get',
params: {
id: id
}
})
}
// 暂停任务接口
async pauseJob (id) {
return request({
url: SERVER.SERVERAPI + '/sjsbTask/pauseJob',
method: 'get',
params: {
id: id
jobId: id
}
})
}
// 恢复任务接口
async resumeJob (id) {
async recover (id) {
return request({
url: SERVER.SERVERAPI + '/sjsbTask/resumeJob',
url: SERVER.SERVERAPI + '/rest/schedule/recover',
method: 'get',
params: {
id: id
jobId: id
}
})
}
// 激活任务接口
async activateJob (id) {
return request({
url: SERVER.SERVERAPI + '/sjsbTask/activateJob',
method: 'get',
params: {
id: id
}
})
}
// 手动测试
async sjsbTaskRun (id) {
async active (id) {
return request({
url: SERVER.SERVERAPI + '/sjsbTask/run',
url: SERVER.SERVERAPI + '/rest/schedule/active',
method: 'get',
params: {
id: id
jobId: id
}
})
}
}
export default new sjsbTask()
\ No newline at end of file
export default new sjsbTask()
......
......@@ -25,4 +25,10 @@ export default class filter {
return name
}
}
}
\ No newline at end of file
stateStatus(val) {
let index = val + 1;
// -1 : 不存在 ,0 : 待激活,1:正常,2:暂停,3 : 出错, 4:阻塞
let status = { 0: '不存在', 1: '待激活', 2: '正常', 3: '暂停', 4: '出错', 5: '阻塞' }
return status[index]
}
}
......
<template>
<!-- 编辑 -->
<dialogBox ref="addTask" width="60%" @submitForm="handleSubmit" :closed="true" @closeDialog="handleClose"
customClass="editValidRule" multiple title="新增定时任务">
<dialogBox ref="addTask" width="60%" @submitForm="handleSubmit" @closeDialog="handleClose" v-model="myValue"
customClass="editValidRule" title="新增定时任务">
<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="任务名" prop="job_name">
<el-input v-model="ruleForm.job_name" placeholder="任务名"></el-input>
<el-form-item label="任务名" prop="jobName">
<el-input v-model="ruleForm.jobName" placeholder="任务名"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="任务分组" prop="job_group">
<el-input v-model="ruleForm.job_group" placeholder="任务分组"></el-input>
<el-form-item label="类名" prop="beanName">
<el-input v-model="ruleForm.beanName" placeholder="类名"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="cron表达式" prop="cron_expression">
<el-input v-model="ruleForm.cron_expression" placeholder="cron表达式"></el-input>
<el-form-item label="cron表达式" prop="cronExpression">
<el-input v-model="ruleForm.cronExpression" placeholder="cron表达式"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="任务类名" prop="bean_class">
<el-input v-model="ruleForm.bean_class" placeholder="任务执行时调用哪个类的方法 包名+类名"></el-input>
<el-form-item label="方法名" prop="methodName">
<el-input v-model="ruleForm.methodName" placeholder="方法名"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="24">
<el-form-item label="任务描述" prop="description">
<el-input v-model="ruleForm.description" placeholder="任务描述"></el-input>
<el-form-item label="任务描述" prop="remark">
<el-input v-model="ruleForm.remark" placeholder="任务描述"></el-input>
</el-form-item>
</el-col>
</el-row>
......@@ -43,6 +43,7 @@
import sjsbTask from '@/api/sjsbTask.js'
export default {
props: {
value: { type: Boolean, default: false },
taskData: {
type: Object,
default: null
......@@ -50,42 +51,33 @@ export default {
},
data () {
return {
myValue: this.value,
ruleForm: {
job_name: '',
job_group: '',
cron_expression: '',
bean_class: '',
description: ''
jobName: '',
cronExpression: '',
beanName: '',
methodName: '',
methodParams: '',
remark: ''
},
rules: {
job_name: [
jobName: [
{ required: true, message: '任务名', trigger: 'blur' }
],
job_group: [
{ required: true, message: '分组', trigger: 'blur' }
],
cron_expression: [
cronExpression: [
{ required: true, message: 'cron表达式', trigger: 'blur' }
],
bean_class: [
beanName: [
{ required: true, message: '任务类名', trigger: 'blur' }
],
description: [
{ required: true, message: '任务描述', trigger: 'blur' }
],
methodName: [
{ required: true, message: '任务方法名', trigger: 'blur' }
]
},
message: ''
}
},
methods: {
isShow () {
this.$refs.addTask.isShow()
setTimeout(() => {
if (this.taskData) {
this.ruleForm = _.cloneDeep(this.taskData)
}
}, 0)
},
handleSubmit () {
let _this = this
this.$refs['ruleForm'].validate(async (valid) => {
......@@ -129,13 +121,49 @@ export default {
})
},
handleClose () {
this.$refs.addTask.isHide()
this.$refs['ruleForm'].resetFields()
this.$emit("input", false);
}
},
watch: {
value(val) {
this.myValue = val
},
taskData(val) {
if (val != null) {
this.ruleForm = val
} else {
this.ruleForm = {
jobName: '',
cronExpression: '',
beanName: '',
methodName: '',
methodParams: '',
remark: ''
}
}
}
}
}
</script>
<style rel="stylesheet/less" lang="less" scoped>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "~@/styles/public.scss";
.editDialogBox-box {
margin: 14px 18px 30px 18px !important
}
/deep/.el-form-item__label {
color: #fff;
}
/deep/.el-form-item {
color: #fff;
margin-bottom: 10px;
}
/deep/ .el-input__inner {
background-color: transparent;
border: 1px solid #458ACF;
}
</style>
......
......@@ -6,34 +6,35 @@ class data extends filter {
columns () {
return [
{
prop: "job_name",
prop: "jobName",
label: "任务名称",
width: 130
},
{
prop: "description",
prop: "remark",
label: "任务描述",
width: 300
},
{
prop: "cron_expression",
prop: "cronExpression",
label: "cron表达式"
},
{
prop: "bean_class",
prop: "beanName",
width: 260,
label: "任务类"
},
{
prop: "job_group",
label: "任务分组"
prop: "methodName",
label: "方法名称"
},
{
label: "状态",
prop: "jobStatus",
render: (h, scope) => {
return (
<div>
{ this.stateStatus(scope.row.job_status) }
{ this.stateStatus(scope.row.jobStatus) }
</div>
)
},
......
......@@ -8,11 +8,12 @@
<el-row>
<el-col :span="6">
<el-form-item label="搜索标题">
<el-input v-model="form.job_name" placeholder="标题"></el-input>
<el-input v-model="form.jobName" placeholder="标题"></el-input>
</el-form-item>
</el-col>
<el-col :span="18" class="btnColRight">
<btn nativeType="cx" @click="handleSearch">查询</btn>
<btn nativeType="cx" @click="handleSubmit">搜索</btn>
<btn nativeType="cx" @click="resetSe">重置</btn>
<btn nativeType="cx" @click="handleAdd">新增</btn>
</el-col>
</el-row>
......@@ -23,7 +24,7 @@
@size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns"
:data="tableData.data">
</lb-table>
<add-task ref="task" :taskData="taskData" />
<add-task ref="task" :taskData="taskData" v-model="isDialog"/>
</div>
</div>
</template>
......@@ -42,8 +43,9 @@ export default {
data () {
return {
taskData: null,
isDialog: false,
form: {
job_name: '',
jobName: '',
currentPage: 1
},
selectionList: [],
......@@ -60,37 +62,23 @@ export default {
render: (h, scope) => {
return (
<div>
<el-button type="text" size="mini" style="color: #67C23A"
v-show={scope.row.job_status !== '1' && scope.row.job_status !== '2'}
icon="el-icon-magic-stick"
onClick={() => { this.handleRecovery(scope.row) }}>激活
</el-button>
<el-button type="text" size="mini"
style="color: #67C23A;margin-left:0"
icon="el-icon-refresh-right"
v-show={scope.row.job_status === '2'}
onClick={() => { this.handleActivation(scope.row) }}>恢复
v-show={scope.row.jobStatus === 0}
icon="el-icon-video-pause"
onClick={() => { this.handleActive(scope.row) }}>激活
</el-button>
<el-button type="text" size="mini"
v-show={scope.row.job_status !== '1'}
icon="el-icon-stopwatch"
onClick={() => { this.handletest(scope.row) }}>手动测试
</el-button>
<el-button type="text" size="mini"
v-show={scope.row.job_status === '1'}
icon="el-icon-video-pause"
onClick={() => { this.handleSuspend(scope.row) }}>暂停
v-show={scope.row.jobStatus === -1}
icon="el-icon-video-pause"
onClick={() => { this.recover(scope.row) }}>恢复
</el-button>
<el-button type="text" size="mini"
icon="el-icon-edit"
v-show={scope.row.job_status === '2' || scope.row.job_status === '-1' || scope.row.job_status === '0'}
onClick={() => { this.handleEdit(scope.row) }}>编辑
</el-button>
<el-button type="text" size="mini"
icon="el-icon-delete" style="color:#F56C6C"
v-show={scope.row.job_status !== '1'}
v-show={scope.row.jobStatus !== -1}
onClick={() => { this.handleDel(scope.row) }}>删除
</el-button>
</div>
......@@ -110,37 +98,30 @@ export default {
methods: {
handleAdd () {
this.taskData = null
this.$refs.task.isShow()
this.isDialog = true
},
handleSearch () {
this.form.currentPage = 1
this.tableData.data = []
this.queryClick()
resetSe() {
this.form.jobName = ''
this.featchData()
},
async featchData () {
try {
this.form = Object.assign(this.form, this.formData)
let { result: { list, total, pages: pageSize, pageNum: current }
} = await sjsbTask.getTaskListByName(this.form)
this.tableData.data = list
this.pageData = {
pageSize,
current,
total
}
let { result } = await sjsbTask.getTaskListByName(this.form)
this.tableData.data = result.list
console.log(this.tableData.data, 'fffffffffffffffffff')
} catch (error) {
this.message = error
}
},
// 暂停
handleSuspend (row) {
this.$confirm('此操将进行暂停操作, 是否继续?', '提示', {
recover(row) {
this.$confirm('此操将进行恢复操作, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
sjsbTask.pauseJob(row.id)
sjsbTask.recover(row.jobId)
.then((res) => {
if ((res.code = 200)) {
this.$message({
......@@ -164,15 +145,15 @@ export default {
})
})
},
// 激活
handleRecovery (row) {
handleActive(row) {
this.$confirm('此操将进行激活操作, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
sjsbTask.activateJob(row.id)
sjsbTask.active(row.jobId)
.then((res) => {
if ((res.code = 200)) {
this.$message({
......@@ -196,15 +177,15 @@ export default {
})
})
},
// 恢复
handleActivation (row) {
this.$confirm('此操将进行恢复操作, 是否继续?', '提示', {
// 暂停
handleSuspend (row) {
this.$confirm('此操将进行暂停操作, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
sjsbTask.resumeJob(row.id)
sjsbTask.pauseJob(row.id)
.then((res) => {
if ((res.code = 200)) {
this.$message({
......@@ -228,41 +209,9 @@ export default {
})
})
},
// 手动测试
handletest (row) {
this.$confirm('此操将进行手动测试, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
sjsbTask.sjsbTaskRun(row.id)
.then((res) => {
if ((res.code = 200)) {
this.$alert(res.message, '提示', {
confirmButtonText: '确定',
type: 'success'
});
this.featchData()
}
})
.catch((error) => {
this.$alert(error, '提示', {
confirmButtonText: '确定',
type: 'error'
})
})
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消',
})
})
},
handleEdit (row) {
this.taskData = row
this.$refs.task.isShow()
this.isDialog = true
},
handleDel (row) {
this.$confirm('此操将进行删除操作, 是否继续?', '提示', {
......@@ -271,7 +220,7 @@ export default {
type: 'warning',
})
.then(() => {
sjsbTask.sjsbTaskRemove(row.id)
sjsbTask.sjsbTaskRemove(row.jobId)
.then((res) => {
if ((res.code = 200)) {
this.$message({
......