定时任务

This commit is contained in:
陈红丽 2024-07-29 09:08:37 +08:00
parent 09421c59bf
commit 184ca551ce
3 changed files with 86 additions and 59 deletions

View File

@ -74,6 +74,16 @@ export function getJobRunOnce(id) {
method: 'get',
});
}
/**
* @description:
*/
export function setJobStatus(data:any) {
return http.request({
url: '/job/status',
method: 'post',
data
});
}
/**
* @description:
*/

View File

@ -23,26 +23,31 @@ export const columns = [
},
{
label: '状态',
prop: 'status',
render(record) {
let typeText = ''
switch (record.row.status) {
case 0:
typeText='未发布'
break;
case 1:
typeText='运行中'
break;
case 2:
typeText='暂停'
break;
case 3:
typeText='删除'
break;
default:
break;
}
return h('span', typeText || '-');
},
isSlot:true,
value:'status'
},
// {
// label: '状态',
// prop: 'status',
// render(record) {
// let typeText = ''
// switch (record.row.status) {
// case 0:
// typeText='未发布'
// break;
// case 1:
// typeText='运行中'
// break;
// case 2:
// typeText='暂停'
// break;
// case 3:
// typeText='删除'
// break;
// default:
// break;
// }
// return h('span', typeText || '-');
// },
// },
];

View File

@ -13,7 +13,7 @@
@selection-change="onSelectionChange"
>
<template #tableTitle>
<el-button type="primary" @click="handleAdd">
<el-button type="primary" @click="handleAdd" v-perm="['sys:job:add']">
<template #icon>
<el-icon class="el-input__icon">
<PlusOutlined />
@ -21,7 +21,7 @@
</template>
添加任务
</el-button>
<el-button type="danger" @click="handleDelete()" :disabled="!selectionData.length">
<el-button type="danger" @click="handleDelete()" :disabled="!selectionData.length" v-perm="['sys:job:batchDelete']">
<template #icon>
<el-icon class="el-input__icon">
<Delete />
@ -30,9 +30,9 @@
删除
</el-button>
</template>
<!-- <template #status="{ scope }">
<el-switch v-model="scope.row.status" :active-value="1" :inactive-value="0" @change="handelChangeStatus(scope.row)" />
</template> -->
<template #status="{ scope }">
<el-switch v-model="scope.row.realStatus" @change="handelSetStatus(scope.row)" />
</template>
</BasicTable>
</el-card>
@ -57,7 +57,7 @@
import { schemas } from './querySchemas';
import { useForm } from '@/components/Form/index';
import { TableAction } from '@/components/Table';
import { getJobList,jobDelete,jobBatchDelete,getJobRunOnce,getJobPause,getJobResume } from '@/api/monitor/job';
import { getJobList,jobDelete,jobBatchDelete,getJobRunOnce,setJobStatus,getJobPause,getJobResume } from '@/api/monitor/job';
import { columns } from './columns';
import { PlusOutlined } from '@vicons/antd';
import {message,confirm} from "@/utils/auth";
@ -87,56 +87,57 @@ const selectionData = ref([])
return h(TableAction, {
style: 'button',
actions: [
{
label: '编辑',
type: 'warning',
onClick: handleEdit.bind(null, record),
ifShow: () => {
return true;
},
// auth: ['basic_list'],
},
{
label: '删除',
type: 'danger',
onClick: handleDelete.bind(null, record),
// isShow auth
ifShow: () => {
return true;
},
// :
// auth: ['basic_list'],
},
],
dropDownActions: [
{
{
label: '启动',
key: 'resume',
type: 'success',
onClick: handelChangeStatus.bind(null, record),
auth:['sys:job:resume'],
ifShow: () => {
return record.row.status==0 ||record.row.status==2;
},
},
{
label: '暂停',
key: 'pause',
type: 'warning',
onClick: handelChangeStatus.bind(null, record),
auth:['sys:job:pause'],
ifShow: () => {
return record.row.status==1;
},
},
{
label: '编辑',
type: 'warning',
onClick: handleEdit.bind(null, record),
disabled:record.row.status==1,
auth: ['sys:job:update'],
},
{
label: '删除',
type: 'danger',
onClick: handleDelete.bind(null, record),
// :
auth: ['sys:job:update'],
},
],
dropDownActions: [
{
label: '执行一次',
key: 'runOnce'
key: 'runOnce',
disabled:true,
auth: ['sys:job:runOnce'],
ifShow: () => {
return record.row.status==2;
},
},
{
label: '调度日志',
key: 'jobLog'
key: 'jobLog',
auth:['sys:job:jobLog']
},
],
select: (key) => {
if(key=='resume' || key=='pause') {
handelChangeStatus(record)
} else if(key=='runOnce') {
if(key=='runOnce') {
handelRunOnce(record)
} else if(key=='jobLog'){
handleJobLog(record)
@ -148,6 +149,13 @@ const selectionData = ref([])
const loadDataTable = async (res: any) => {
const result = await getJobList({ ...formParams, ...res });
result.records.map(item=>{
if(item.status==0) {
item.realStatus = false
} else {
item.realStatus = true
}
})
return result;
};
@ -179,7 +187,11 @@ const selectionData = ref([])
await nextTick();
editVisible.value=true
};
const handelSetStatus = async(row)=>{
await setJobStatus({id:row.id,status:row.realStatus?1:0})
message("设置成功");
reloadTable('noRefresh')
}
const handleEdit = async (record: Recordable) => {
jobId.value=record.row.id
await nextTick();