完成定时任务对接
This commit is contained in:
parent
f7a1b14500
commit
5c043df578
|
|
@ -14,3 +14,28 @@ export function systemLogLists(params: any) {
|
|||
export function systemCache() {
|
||||
return request.get({ url: '/monitor/cache' })
|
||||
}
|
||||
|
||||
// 定时任务列表
|
||||
export function crontabLists(params: any) {
|
||||
return request.get({ url: '/crontab/list', params })
|
||||
}
|
||||
|
||||
// 添加定时任务
|
||||
export function crontabAdd(params: any) {
|
||||
return request.post({ url: '/crontab/add', params })
|
||||
}
|
||||
|
||||
// 定时任务详情
|
||||
export function crontabDetail(params: any) {
|
||||
return request.get({ url: '/crontab/detail', params })
|
||||
}
|
||||
|
||||
// 编辑定时任务
|
||||
export function crontabEdit(params: any) {
|
||||
return request.post({ url: '/crontab/edit', params })
|
||||
}
|
||||
|
||||
// 删除定时任务
|
||||
export function crontabDel(params: any) {
|
||||
return request.post({ url: '/crontab/del', params })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,6 +235,13 @@ const open = (type = 'add') => {
|
|||
}
|
||||
|
||||
const setFormData = async (row: any) => {
|
||||
formRules.password = []
|
||||
formRules.passwordConfirm = [
|
||||
{
|
||||
validator: passwordConfirmValidator,
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
const data = await adminDetail({
|
||||
id: row.id
|
||||
})
|
||||
|
|
@ -244,13 +251,6 @@ const setFormData = async (row: any) => {
|
|||
formData[key] = data[key]
|
||||
}
|
||||
}
|
||||
formRules.password = []
|
||||
formRules.passwordConfirm = [
|
||||
{
|
||||
validator: passwordConfirmValidator,
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ const formData = reactive({
|
|||
//路由参数
|
||||
params: '',
|
||||
//是否缓存 0=否, 1=是
|
||||
isCache: 1,
|
||||
isCache: 0,
|
||||
//是否显示 0=否, 1=是
|
||||
isShow: 1,
|
||||
//是否禁用 0=否, 1=是
|
||||
|
|
|
|||
|
|
@ -0,0 +1,142 @@
|
|||
<template>
|
||||
<div class="article-edit">
|
||||
<el-card class="!border-none" shadow="never">
|
||||
<el-page-header :content="$route.meta.title" @back="$router.back()" />
|
||||
</el-card>
|
||||
<el-card class="mt-4 !border-none" shadow="never">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
class="ls-form"
|
||||
:model="formData"
|
||||
label-width="96px"
|
||||
:rules="rules"
|
||||
>
|
||||
<el-form-item label="任务名称" prop="name">
|
||||
<div class="w-80">
|
||||
<el-input
|
||||
v-model="formData.name"
|
||||
placeholder="请输入任务名称"
|
||||
maxlength="30"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="任务分组" prop="groups">
|
||||
<el-select
|
||||
class="w-80"
|
||||
v-model="formData.groups"
|
||||
clearable
|
||||
placeholder="请选择任务分组"
|
||||
>
|
||||
<el-option label="默认" value="default" />
|
||||
<el-option label="系统" value="system" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="调用方法" prop="command">
|
||||
<div class="w-80">
|
||||
<el-input
|
||||
v-model="formData.command"
|
||||
placeholder="请输入调用目标字符串"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="cron表达式" prop="rules">
|
||||
<div class="w-80">
|
||||
<el-input v-model="formData.rules" placeholder="请输入cron执行表达式" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<div class="w-80">
|
||||
<el-input
|
||||
v-model="formData.remark"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 3, maxRows: 6 }"
|
||||
:maxlength="200"
|
||||
show-word-limit
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="执行策略" prop="groups">
|
||||
<el-radio-group v-model="formData.strategy">
|
||||
<el-radio :label="1"> 立即执行 </el-radio>
|
||||
<el-radio :label="2"> 执行一次 </el-radio>
|
||||
<el-radio :label="3"> 放弃执行 </el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否并发" prop="concurrent">
|
||||
<el-radio-group v-model="formData.concurrent">
|
||||
<el-radio :label="1"> 允许 </el-radio>
|
||||
<el-radio :label="0"> 禁止 </el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-switch v-model="formData.status" :active-value="1" :inactive-value="2" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<footer-btns>
|
||||
<el-button type="primary" @click="handleSave">保存</el-button>
|
||||
</footer-btns>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="scheduledTaskEdit">
|
||||
import type { FormInstance } from 'element-plus'
|
||||
import { crontabAdd, crontabEdit, crontabDetail } from '@/api/setting/system'
|
||||
import useMultipleTabs from '@/hooks/useMultipleTabs'
|
||||
import feedback from '@/utils/feedback'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const formData = reactive({
|
||||
id: '',
|
||||
name: '',
|
||||
groups: '',
|
||||
command: '',
|
||||
rules: '',
|
||||
status: 1,
|
||||
strategy: 1,
|
||||
concurrent: 0,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
const { removeTab } = useMultipleTabs()
|
||||
const formRef = shallowRef<FormInstance>()
|
||||
const rules = reactive({
|
||||
name: [{ required: true, message: '请输入任务名称' }],
|
||||
command: [{ required: true, message: '请输入调用目标字符串' }],
|
||||
rules: [{ required: true, message: '请输入cron执行表达式' }]
|
||||
})
|
||||
|
||||
const getDetails = async () => {
|
||||
const data = await crontabDetail({
|
||||
id: route.query.id
|
||||
})
|
||||
Object.keys(formData).forEach((key) => {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key]
|
||||
})
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
await formRef.value?.validate()
|
||||
if (route.query.id) {
|
||||
await crontabEdit(formData)
|
||||
} else {
|
||||
await crontabAdd(formData)
|
||||
}
|
||||
feedback.msgSuccess('操作成功')
|
||||
removeTab()
|
||||
router.back()
|
||||
}
|
||||
onMounted(async () => {
|
||||
if (!route.query.id) {
|
||||
return
|
||||
}
|
||||
await getDetails()
|
||||
})
|
||||
</script>
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-card shadow="never" class="!border-none">
|
||||
<router-link
|
||||
v-perms="['crontab/add', 'crontab/add:edit']"
|
||||
:to="getRoutePath('crontab/add:edit')"
|
||||
>
|
||||
<el-button type="primary" class="mb-[16px]">
|
||||
<template #icon>
|
||||
<icon name="el-icon-Plus" />
|
||||
</template>
|
||||
新增
|
||||
</el-button>
|
||||
</router-link>
|
||||
|
||||
<el-table
|
||||
ref="paneTable"
|
||||
class="m-t-24"
|
||||
:data="pager.lists"
|
||||
v-loading="pager.loading"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column prop="name" label="名称" min-width="120" />
|
||||
<el-table-column prop="groups" label="分组" min-width="100">
|
||||
<template #default="{ row }">
|
||||
<dict-value
|
||||
:value="row.groups"
|
||||
:options="[
|
||||
{
|
||||
name: '默认',
|
||||
value: 'default'
|
||||
},
|
||||
{
|
||||
name: '系统',
|
||||
value: 'system'
|
||||
}
|
||||
]"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="command" label="调用目标字符串" min-width="100" />
|
||||
<el-table-column prop="rules" label="cron表达式" min-width="100" />
|
||||
<el-table-column prop="status" label="状态" min-width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.status == 1" type="success">运行中</el-tag>
|
||||
<el-tag v-if="row.status == 2" type="info">已停止</el-tag>
|
||||
<el-tag v-if="row.status == 3" type="danger">错误</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="error" label="错误信息" min-width="120" />
|
||||
<el-table-column prop="taskTime" label="执行耗时(ms)" min-width="100" />
|
||||
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<div class="flex">
|
||||
<el-button type="primary" link>
|
||||
<router-link
|
||||
v-perms="['crontab/edit', 'crontab/add:edit']"
|
||||
:to="{
|
||||
path: getRoutePath('crontab/add:edit'),
|
||||
query: {
|
||||
id: row.id
|
||||
}
|
||||
}"
|
||||
>
|
||||
<el-button type="primary" link> 编辑 </el-button>
|
||||
</router-link>
|
||||
</el-button>
|
||||
<el-button
|
||||
v-perms="['crontab/delete']"
|
||||
type="danger"
|
||||
link
|
||||
@click="handleDelete(row.id)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="flex justify-end mt-4">
|
||||
<pagination v-model="pager" @change="getLists" />
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup name="scheduledTask">
|
||||
import { crontabLists, crontabDel } from '@/api/setting/system'
|
||||
import { usePaging } from '@/hooks/usePaging'
|
||||
import { getRoutePath } from '@/router'
|
||||
import feedback from '@/utils/feedback'
|
||||
|
||||
const { pager, getLists } = usePaging({
|
||||
fetchFun: crontabLists,
|
||||
params: {}
|
||||
})
|
||||
|
||||
const handleDelete = async (id: number) => {
|
||||
await feedback.confirm('确定要删除?')
|
||||
await crontabDel({ id })
|
||||
feedback.msgSuccess('删除成功')
|
||||
getLists()
|
||||
}
|
||||
|
||||
getLists()
|
||||
</script>
|
||||
|
||||
<style lang="scss"></style>
|
||||
Loading…
Reference in New Issue