定时任务
This commit is contained in:
parent
7c0f166bbd
commit
0adff62071
73
src/views/monitor/job/columns.ts
Normal file
73
src/views/monitor/job/columns.ts
Normal file
@ -0,0 +1,73 @@
|
||||
import { h } from 'vue';
|
||||
import { NTag } from 'naive-ui';
|
||||
|
||||
export const columns = [
|
||||
{
|
||||
type: 'selection',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: 'ID',
|
||||
key: 'id',
|
||||
fixed: 'left',
|
||||
width: 50,
|
||||
},
|
||||
{
|
||||
title: '任务名称',
|
||||
key: 'jobName',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '任务分组',
|
||||
key: 'jobGroup',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '任务触发器',
|
||||
key: 'jobTrigger',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '执行表达式',
|
||||
key: 'cronExpression',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '执行策略',
|
||||
key: 'executePolicyText',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '同步任务',
|
||||
key: 'isSync',
|
||||
width: 100,
|
||||
render(record) {
|
||||
return h(
|
||||
NTag,
|
||||
{
|
||||
color: record.isSync == 1 ? 'success' : 'info',
|
||||
},
|
||||
{
|
||||
default: () => (record.isSync == 1 ? '同步' : '异步'),
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'URL',
|
||||
key: 'url',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
key: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
key: 'note',
|
||||
width: 200,
|
||||
},
|
||||
];
|
236
src/views/monitor/job/edit.vue
Normal file
236
src/views/monitor/job/edit.vue
Normal file
@ -0,0 +1,236 @@
|
||||
<template>
|
||||
<basicModal
|
||||
@register="modalRegister"
|
||||
ref="modalRef"
|
||||
class="basicModal basicFormModal"
|
||||
@on-ok="handleSubmit"
|
||||
@on-close="handleClose"
|
||||
>
|
||||
<template #default>
|
||||
<n-form
|
||||
class="ls-form"
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
label-placement="left"
|
||||
label-width="110px"
|
||||
>
|
||||
<n-form-item
|
||||
label="任务名称"
|
||||
path="jobName"
|
||||
:rule="{ required: true, message: '请输入任务名称', trigger: 'blur' }"
|
||||
>
|
||||
<n-input
|
||||
class="ls-input"
|
||||
v-model:value="formData.jobName"
|
||||
placeholder="请输入任务名称"
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="任务别名"
|
||||
path="jobAlias"
|
||||
:rule="{ required: true, message: '请输入任务别名', trigger: 'blur' }"
|
||||
>
|
||||
<n-input
|
||||
class="ls-input"
|
||||
v-model:value="formData.jobAlias"
|
||||
placeholder="请输入任务别名"
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="任务分组"
|
||||
path="jobGroup"
|
||||
:rule="{ required: true, message: '请选择任务分组', trigger: 'change' }"
|
||||
>
|
||||
<n-select
|
||||
v-model:value="formData.jobGroup"
|
||||
placeholder="请选择任务分组"
|
||||
:options="jobGroupList"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="任务触发器"
|
||||
path="jobTrigger"
|
||||
:rule="{ required: true, message: '请输入任务触发器', trigger: 'blur' }"
|
||||
>
|
||||
<n-input
|
||||
class="ls-input"
|
||||
v-model:value="formData.jobTrigger"
|
||||
placeholder="请输入任务触发器"
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="任务状态"
|
||||
path="status"
|
||||
:rule="{ type: 'number', required: true, message: '请选择任务状态', trigger: 'change' }"
|
||||
>
|
||||
<n-select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择任务状态"
|
||||
:options="statusList"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="正则表达式"
|
||||
path="cronExpression"
|
||||
:rule="{ required: true, message: '请输入正则表达式', trigger: 'blur' }"
|
||||
>
|
||||
<n-input
|
||||
class="ls-input"
|
||||
v-model:value="formData.cronExpression"
|
||||
placeholder="请输入正则表达式"
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="执行策略"
|
||||
path="executePolicy"
|
||||
:rule="{ type: 'number', required: true, message: '请选择执行策略', trigger: 'change' }"
|
||||
>
|
||||
<n-select
|
||||
v-model:value="formData.executePolicy"
|
||||
placeholder="请选择执行策略"
|
||||
:options="executePolicyList"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item label="是否同步任务" path="isSync" class="flex-1">
|
||||
<n-radio-group v-model:value="formData.isSync" name="isSync">
|
||||
<n-radio :value="1">是</n-radio>
|
||||
<n-radio :value="0">否</n-radio>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="任务URL"
|
||||
path="url"
|
||||
:rule="{ required: true, message: '请输入任务URL', trigger: 'blur' }"
|
||||
>
|
||||
<n-input
|
||||
class="ls-input"
|
||||
v-model:value="formData.url"
|
||||
placeholder="请输入任务URL"
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="任务备注"
|
||||
path="note"
|
||||
:rule="{ required: true, message: '请输入任务备注', trigger: 'blur' }"
|
||||
>
|
||||
<n-input v-model:value="formData.note" type="textarea" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</template>
|
||||
</basicModal>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { getJobDetail, jobAdd, jobUpdate } from '@/api/monitor/job';
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { useModal } from '@/components/Modal';
|
||||
|
||||
const emit = defineEmits(['success', 'update:visible']);
|
||||
const formRef = ref();
|
||||
|
||||
/**
|
||||
* 定义表单参数
|
||||
*/
|
||||
const message = useMessage();
|
||||
const formData = reactive({
|
||||
id: '',
|
||||
jobName: '',
|
||||
jobAlias: '',
|
||||
jobGroup: undefined,
|
||||
jobTrigger: '',
|
||||
status: undefined,
|
||||
cronExpression: '',
|
||||
executePolicy: undefined,
|
||||
isSync: 0,
|
||||
url: '',
|
||||
note: '',
|
||||
});
|
||||
|
||||
/**
|
||||
* 定义接收的参数
|
||||
*/
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
jobId: {
|
||||
type: Number,
|
||||
required: true,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
const [modalRegister, { openModal, setSubLoading }] = useModal({
|
||||
title: props.jobId ? '编辑任务' : '添加任务',
|
||||
subBtuText: '确定',
|
||||
width: 600,
|
||||
});
|
||||
const jobGroupList = [{ label: 'DEFAULT', value: 'DEFAULT' }];
|
||||
const statusList = [
|
||||
{ label: '未发布', value: 0 },
|
||||
{ label: '运行中', value: 1 },
|
||||
{ label: '暂停', value: 2 },
|
||||
{ label: '删除', value: 3 },
|
||||
];
|
||||
const executePolicyList = [
|
||||
{ label: '立即执行', value: 1 },
|
||||
{ label: '执行一次', value: 2 },
|
||||
{ label: '放弃执行', value: 3 },
|
||||
];
|
||||
/**
|
||||
* 执行提交
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
formRef.value
|
||||
.validate()
|
||||
.then(async () => {
|
||||
props.jobId ? await jobUpdate(formData) : await jobAdd(formData);
|
||||
message.success('操作成功');
|
||||
setSubLoading(false);
|
||||
emit('update:visible', false);
|
||||
emit('success');
|
||||
})
|
||||
.catch((error) => {
|
||||
setSubLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭窗体
|
||||
*/
|
||||
const handleClose = () => {
|
||||
emit('update:visible', false);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置表单数据
|
||||
*/
|
||||
const setFormData = async () => {
|
||||
const data = await getJobDetail(props.jobId);
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 钩子函数
|
||||
*/
|
||||
onMounted(() => {
|
||||
if (props.jobId) {
|
||||
setFormData();
|
||||
}
|
||||
});
|
||||
//导出方法
|
||||
defineExpose({
|
||||
openModal,
|
||||
});
|
||||
</script>
|
291
src/views/monitor/job/index.vue
Normal file
291
src/views/monitor/job/index.vue
Normal file
@ -0,0 +1,291 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
|
||||
<template #statusSlot="{ model, field }">
|
||||
<n-input v-model:value="model[field]" />
|
||||
</template>
|
||||
</BasicForm>
|
||||
</n-card>
|
||||
<n-card :bordered="false" class="proCard">
|
||||
<BasicTable
|
||||
:columns="columns"
|
||||
:request="loadDataTable"
|
||||
:row-key="(row) => row.id"
|
||||
ref="basicTableRef"
|
||||
:actionColumn="actionColumn"
|
||||
@update:checked-row-keys="onCheckedRow"
|
||||
:autoScrollX="true"
|
||||
>
|
||||
<template #tableTitle>
|
||||
<n-space>
|
||||
<n-button type="primary" @click="handleAdd" v-perm="['sys:job:add']">
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<PlusOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
新建
|
||||
</n-button>
|
||||
|
||||
<n-button
|
||||
type="error"
|
||||
@click="handleDelete"
|
||||
:disabled="!rowKeys.length"
|
||||
v-perm="['sys:job:batchDelete']"
|
||||
>
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<DeleteOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
删除
|
||||
</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
</n-card>
|
||||
<editDialog
|
||||
ref="createModalRef"
|
||||
:jobId="jobId"
|
||||
v-if="editVisible"
|
||||
v-model:visible="editVisible"
|
||||
@success="reloadTable('noRefresh')"
|
||||
/>
|
||||
<jobLog v-if="editLogVisible" :jobId="jobId" v-model:visible="editLogVisible" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { h, nextTick, reactive, ref, unref } from 'vue';
|
||||
import { useMessage, useDialog } from 'naive-ui';
|
||||
import { TableAction } from '@/components/Table';
|
||||
import { BasicForm, useForm } from '@/components/Form/index';
|
||||
import {
|
||||
getJobList,
|
||||
jobDelete,
|
||||
jobBatchDelete,
|
||||
getJobRunOnce,
|
||||
setJobStatus,
|
||||
getJobPause,
|
||||
getJobResume,
|
||||
} from '@/api/monitor/job';
|
||||
import { columns } from './columns';
|
||||
import { PlusOutlined, DeleteOutlined, FormOutlined, FieldTimeOutlined } from '@vicons/antd';
|
||||
import CreateModal from './CreateModal.vue';
|
||||
import editDialog from './edit.vue';
|
||||
import jobLog from './log/index.vue';
|
||||
import { basicModal, useModal } from '@/components/Modal';
|
||||
import { schemas } from './querySchemas';
|
||||
import { renderIcon } from '@/utils';
|
||||
|
||||
const message = useMessage();
|
||||
const dialog = useDialog();
|
||||
const basicTableRef = ref();
|
||||
const createModalRef = ref();
|
||||
const editVisible = ref(false);
|
||||
const editLogVisible = ref(false);
|
||||
const jobId = ref(0);
|
||||
const rowKeys = ref([]);
|
||||
const exportLoading = ref(false);
|
||||
|
||||
const showModal = ref(false);
|
||||
const formParams = reactive({
|
||||
jobName: '',
|
||||
status: '',
|
||||
});
|
||||
|
||||
const actionColumn = reactive({
|
||||
width: 350,
|
||||
title: '操作',
|
||||
align: 'center',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render(record) {
|
||||
return h(TableAction as any, {
|
||||
style: 'button',
|
||||
actions: [
|
||||
{
|
||||
label: '启动',
|
||||
type: 'success',
|
||||
icon: renderIcon(FieldTimeOutlined),
|
||||
onClick: handelChangeStatus.bind(null, record),
|
||||
auth: ['sys:job:resume'],
|
||||
ifShow: () => {
|
||||
return record.status == 0 || record.status == 2;
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '暂停',
|
||||
type: 'warning',
|
||||
icon: renderIcon(FieldTimeOutlined),
|
||||
onClick: handelChangeStatus.bind(null, record),
|
||||
auth: ['sys:job:pause'],
|
||||
ifShow: () => {
|
||||
return record.status == 1;
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '编辑',
|
||||
icon: renderIcon(FormOutlined),
|
||||
type: 'info',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
auth: ['sys:job:update'],
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
icon: renderIcon(DeleteOutlined),
|
||||
type: 'error',
|
||||
onClick: handleDelete.bind(null, record),
|
||||
auth: ['sys:job:delete'],
|
||||
},
|
||||
],
|
||||
dropDownActions: [
|
||||
{
|
||||
label: '执行一次',
|
||||
key: 'runOnce',
|
||||
auth: ['sys:job:runOnce'],
|
||||
ifShow: () => {
|
||||
return record.status == 2;
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '调度日志',
|
||||
key: 'jobLog',
|
||||
auth: ['sys:job:jobLog'],
|
||||
},
|
||||
],
|
||||
select: (key) => {
|
||||
if (key == 'runOnce') {
|
||||
handelRunOnce(record);
|
||||
} else if (key == 'jobLog') {
|
||||
handleJobLog(record);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
function addTable() {
|
||||
showModal.value = true;
|
||||
}
|
||||
|
||||
const loadDataTable = async (res) => {
|
||||
rowKeys.value = [];
|
||||
const result = await getJobList({ ...formParams, ...res });
|
||||
return result;
|
||||
};
|
||||
|
||||
function onCheckedRow(keys) {
|
||||
rowKeys.value = keys;
|
||||
}
|
||||
|
||||
function reloadTable(noRefresh = '') {
|
||||
basicTableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
||||
}
|
||||
|
||||
function handleSubmit(values: Recordable) {
|
||||
for (const key in formParams) {
|
||||
formParams[key] = '';
|
||||
}
|
||||
for (const key in values) {
|
||||
formParams[key] = values[key];
|
||||
}
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
function handleReset(values: Recordable) {
|
||||
for (const key in formParams) {
|
||||
formParams[key] = '';
|
||||
}
|
||||
for (const key in values) {
|
||||
formParams[key] = values[key];
|
||||
}
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
const [register, {}] = useForm({
|
||||
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
||||
labelWidth: 110,
|
||||
schemas,
|
||||
});
|
||||
|
||||
/**
|
||||
* 执行添加
|
||||
*/
|
||||
const handleAdd = async () => {
|
||||
jobId.value = 0;
|
||||
editVisible.value = true;
|
||||
await nextTick();
|
||||
createModalRef.value.openModal();
|
||||
};
|
||||
/**
|
||||
* 执行编辑
|
||||
*/
|
||||
async function handleEdit(record: Recordable) {
|
||||
jobId.value = record.id;
|
||||
editVisible.value = true;
|
||||
await nextTick();
|
||||
createModalRef.value.openModal();
|
||||
}
|
||||
/**
|
||||
* 执行变更状态
|
||||
* @param record 参数
|
||||
*/
|
||||
const handelChangeStatus = async (record) => {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: `确定要${record.status == 1 ? '暂停' : '启动'}`,
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
record.status == 1 ? await getJobPause(record.id) : await getJobResume(record.id);
|
||||
reloadTable('noRefresh');
|
||||
},
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 执行一次
|
||||
*/
|
||||
const handelRunOnce = async (record) => {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: '确定要执行一次?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
await getJobRunOnce(record.id);
|
||||
message('执行成功');
|
||||
},
|
||||
});
|
||||
};
|
||||
/**
|
||||
* 执行查看日志
|
||||
* @param record 参数
|
||||
*/
|
||||
const handleJobLog = (record) => {
|
||||
console.log(record);
|
||||
// router.push({path:'/monitorJob/log'})
|
||||
editLogVisible.value = true;
|
||||
jobId.value = record.id;
|
||||
};
|
||||
/**
|
||||
* 执行删除
|
||||
* @param id 参数
|
||||
*/
|
||||
async function handleDelete(record) {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: '确定要删除?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
record.id ? await jobDelete(record.id) : await jobBatchDelete(rowKeys.value);
|
||||
message.success('删除成功');
|
||||
reloadTable();
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
58
src/views/monitor/job/log/columns.ts
Normal file
58
src/views/monitor/job/log/columns.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { h } from 'vue';
|
||||
|
||||
export const columns = [
|
||||
{
|
||||
type: 'selection',
|
||||
width: 50,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: 'ID',
|
||||
key: 'id',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '任务名称',
|
||||
key: 'jobName',
|
||||
},
|
||||
{
|
||||
title: '任务组名',
|
||||
key: 'jobGroup',
|
||||
},
|
||||
{
|
||||
title: '任务触发器',
|
||||
key: 'jobTrigger',
|
||||
},
|
||||
{
|
||||
title: '任务信息',
|
||||
key: 'jobMessage',
|
||||
},
|
||||
{
|
||||
title: '执行状态',
|
||||
key: 'status',
|
||||
render(record) {
|
||||
let typeText = '';
|
||||
switch (record.status) {
|
||||
case 0:
|
||||
typeText = '未发布';
|
||||
break;
|
||||
case 1:
|
||||
typeText = '运行中';
|
||||
break;
|
||||
case 2:
|
||||
typeText = '暂停';
|
||||
break;
|
||||
case 3:
|
||||
typeText = '删除';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return h('span', typeText || '-');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '执行时间',
|
||||
key: 'startTime',
|
||||
},
|
||||
];
|
94
src/views/monitor/job/log/edit.vue
Normal file
94
src/views/monitor/job/log/edit.vue
Normal file
@ -0,0 +1,94 @@
|
||||
<template>
|
||||
<basicModal @register="modalRegister" ref="modalRef" class="basicModal basicFormModal">
|
||||
<template #default>
|
||||
<n-descriptions :column="2" bordered label-placement="left" :labelStyle="{ width: '130px' }">
|
||||
<n-descriptions-item label="任务名称:">{{ formData.jobName }}</n-descriptions-item>
|
||||
<n-descriptions-item label="任务组名:">{{ formData.jobGroup }}</n-descriptions-item>
|
||||
<n-descriptions-item label="任务触发器:">{{ formData.jobTrigger }}</n-descriptions-item>
|
||||
<n-descriptions-item label="任务信息:">{{ formData.jobMessage }}</n-descriptions-item>
|
||||
<n-descriptions-item label="cron执行表达式:">{{
|
||||
formData.cronExpression
|
||||
}}</n-descriptions-item>
|
||||
<n-descriptions-item label="任务开始时间:">{{ formData.startTime }}</n-descriptions-item>
|
||||
<n-descriptions-item label="任务结束时间:">{{ formData.endTime }}</n-descriptions-item>
|
||||
</n-descriptions>
|
||||
</template>
|
||||
<template #action>
|
||||
<n-button @click="handleClose">取消</n-button>
|
||||
</template>
|
||||
</basicModal>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { getJobLogDetail } from '@/api/monitor/job';
|
||||
import { onMounted, reactive, shallowRef } from 'vue';
|
||||
import { useModal } from '@/components/Modal';
|
||||
|
||||
/**
|
||||
* 定义表单参数
|
||||
*/
|
||||
const formData = reactive({
|
||||
id: '',
|
||||
jobName: '',
|
||||
jobGroup: '',
|
||||
jobTrigger: '',
|
||||
jobMessage: '',
|
||||
cronExpression: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
});
|
||||
|
||||
const [modalRegister, { openModal, setSubLoading }] = useModal({
|
||||
title: '日志详情',
|
||||
width: 800,
|
||||
});
|
||||
const emit = defineEmits(['update:visible']);
|
||||
|
||||
/**
|
||||
* 定义接收的参数
|
||||
*/
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
logId: {
|
||||
type: Number,
|
||||
required: true,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* 关闭窗体
|
||||
*/
|
||||
const handleClose = () => {
|
||||
emit('update:visible', false);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置表单数据
|
||||
*/
|
||||
const setFormData = async () => {
|
||||
const data = await getJobLogDetail(props.logId);
|
||||
for (const key in formData) {
|
||||
if (data[key] != null && data[key] != undefined) {
|
||||
//@ts-ignore
|
||||
formData[key] = data[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 钩子函数
|
||||
*/
|
||||
onMounted(() => {
|
||||
if (props.logId) {
|
||||
setFormData();
|
||||
}
|
||||
});
|
||||
//导出方法
|
||||
defineExpose({
|
||||
openModal,
|
||||
});
|
||||
</script>
|
199
src/views/monitor/job/log/index.vue
Normal file
199
src/views/monitor/job/log/index.vue
Normal file
@ -0,0 +1,199 @@
|
||||
<template>
|
||||
<n-drawer v-model:show="props.visible" @after-leave="handleClose" :width="size">
|
||||
<n-drawer-content title="调度日志">
|
||||
<template #default>
|
||||
<n-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
|
||||
<template #statusSlot="{ model, field }">
|
||||
<n-input v-model:value="model[field]" />
|
||||
</template>
|
||||
</BasicForm>
|
||||
</n-card>
|
||||
<n-card :bordered="false" class="proCard">
|
||||
<BasicTable
|
||||
:columns="columns"
|
||||
:request="loadDataTable"
|
||||
:row-key="(row) => row.id"
|
||||
ref="basicTableRef"
|
||||
:actionColumn="actionColumn"
|
||||
@update:checked-row-keys="onCheckedRow"
|
||||
:autoScrollX="true"
|
||||
>
|
||||
<template #tableTitle>
|
||||
<n-space>
|
||||
<n-button type="error" @click="handleDelete" :disabled="!rowKeys.length">
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<DeleteOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
删除
|
||||
</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</BasicTable>
|
||||
</n-card>
|
||||
</template>
|
||||
<template #footer>
|
||||
<span class="dialog-footer">
|
||||
<n-button @click="handleClose">取消</n-button>
|
||||
</span>
|
||||
</template>
|
||||
</n-drawer-content>
|
||||
<editDialog
|
||||
ref="createModalRef"
|
||||
:logId="logId"
|
||||
v-if="editVisible"
|
||||
v-model:visible="editVisible"
|
||||
@success="reloadTable('noRefresh')"
|
||||
/>
|
||||
</n-drawer>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { h, nextTick, reactive, ref, unref } from 'vue';
|
||||
import { useMessage, useDialog } from 'naive-ui';
|
||||
import { TableAction } from '@/components/Table';
|
||||
import { BasicForm, useForm } from '@/components/Form/index';
|
||||
import { getJobLogList, jobLogDelete, jobLogBatchDelete } from '@/api/monitor/job';
|
||||
import { columns } from './columns';
|
||||
import { PlusOutlined, DeleteOutlined, EyeOutlined } from '@vicons/antd';
|
||||
import CreateModal from './CreateModal.vue';
|
||||
import editDialog from './edit.vue';
|
||||
import { basicModal, useModal } from '@/components/Modal';
|
||||
import { schemas } from './querySchemas';
|
||||
import { renderIcon } from '@/utils';
|
||||
|
||||
const message = useMessage();
|
||||
const dialog = useDialog();
|
||||
const basicTableRef = ref();
|
||||
const createModalRef = ref();
|
||||
const editVisible = ref(false);
|
||||
const logId = ref(0);
|
||||
const size = document.body.clientWidth - 500;
|
||||
const rowKeys = ref([]);
|
||||
const exportLoading = ref(false);
|
||||
|
||||
const showModal = ref(false);
|
||||
const formParams = reactive({
|
||||
name: '',
|
||||
dbType: '',
|
||||
});
|
||||
const emit = defineEmits(['update:visible']);
|
||||
/**
|
||||
* 定义接收的参数
|
||||
*/
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
default: false,
|
||||
},
|
||||
jobId: {
|
||||
type: Number,
|
||||
required: true,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
const actionColumn = reactive({
|
||||
width: 200,
|
||||
title: '操作',
|
||||
align: 'center',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render(record) {
|
||||
return h(TableAction as any, {
|
||||
style: 'button',
|
||||
actions: [
|
||||
{
|
||||
label: '详情',
|
||||
icon: renderIcon(EyeOutlined),
|
||||
type: 'info',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
icon: renderIcon(DeleteOutlined),
|
||||
type: 'error',
|
||||
onClick: handleDelete.bind(null, record),
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
function addTable() {
|
||||
showModal.value = true;
|
||||
}
|
||||
|
||||
const loadDataTable = async (res) => {
|
||||
rowKeys.value = [];
|
||||
const result = await getJobLogList({ ...formParams, jobId: props.jobId, ...res });
|
||||
return result;
|
||||
};
|
||||
|
||||
function onCheckedRow(keys) {
|
||||
rowKeys.value = keys;
|
||||
}
|
||||
|
||||
function reloadTable(noRefresh = '') {
|
||||
basicTableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
||||
}
|
||||
|
||||
function handleSubmit(values: Recordable) {
|
||||
for (const key in formParams) {
|
||||
formParams[key] = '';
|
||||
}
|
||||
for (const key in values) {
|
||||
formParams[key] = values[key];
|
||||
}
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
function handleReset(values: Recordable) {
|
||||
for (const key in formParams) {
|
||||
formParams[key] = '';
|
||||
}
|
||||
for (const key in values) {
|
||||
formParams[key] = values[key];
|
||||
}
|
||||
reloadTable();
|
||||
}
|
||||
|
||||
const [register, {}] = useForm({
|
||||
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
||||
labelWidth: 110,
|
||||
schemas,
|
||||
});
|
||||
const handleClose = () => {
|
||||
emit('update:visible', false);
|
||||
};
|
||||
/**
|
||||
* 执行编辑
|
||||
*/
|
||||
async function handleEdit(record: Recordable) {
|
||||
logId.value = record.id;
|
||||
editVisible.value = true;
|
||||
await nextTick();
|
||||
createModalRef.value.openModal();
|
||||
}
|
||||
/**
|
||||
* 执行删除
|
||||
* @param id 参数
|
||||
*/
|
||||
async function handleDelete(record) {
|
||||
dialog.warning({
|
||||
title: '提示',
|
||||
content: '确定要删除?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: async () => {
|
||||
record.id ? await jobLogDelete(record.id) : await jobLogBatchDelete(rowKeys.value);
|
||||
message.success('删除成功');
|
||||
reloadTable();
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
30
src/views/monitor/job/log/querySchemas.ts
Normal file
30
src/views/monitor/job/log/querySchemas.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { FormSchema } from '@/components/Form/index';
|
||||
export const schemas: FormSchema[] = [
|
||||
{
|
||||
field: 'jobName',
|
||||
component: 'NInput',
|
||||
label: '任务名称',
|
||||
componentProps: {
|
||||
placeholder: '请输入数据源名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
component: 'NSelect',
|
||||
label: '任务状态',
|
||||
componentProps: {
|
||||
placeholder: '请选择任务状态',
|
||||
clearable: true,
|
||||
options: [
|
||||
{
|
||||
label: '正常',
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
label: '失败',
|
||||
value: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
38
src/views/monitor/job/querySchemas.ts
Normal file
38
src/views/monitor/job/querySchemas.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { FormSchema } from '@/components/Form/index';
|
||||
export const schemas: FormSchema[] = [
|
||||
{
|
||||
field: 'jobName',
|
||||
component: 'NInput',
|
||||
label: '任务名称',
|
||||
componentProps: {
|
||||
placeholder: '请输入任务名称',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
component: 'NSelect',
|
||||
label: '任务状态',
|
||||
componentProps: {
|
||||
placeholder: '请选择任务状态',
|
||||
clearable: true,
|
||||
options: [
|
||||
{
|
||||
label: '未发布',
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
label: '运行中',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: '暂停',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
Loading…
Reference in New Issue
Block a user