提交 | 用户 | 时间
|
d09108
|
1 |
<template> |
2307f1
|
2 |
<Dialog v-model="dialogVisible" :close-on-click-modal="false" :title="dialogTitle" width="50%"> |
d09108
|
3 |
<el-form |
L |
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="120px" |
|
9 |
> |
|
10 |
<el-form-item label="bean名称" prop="beanName"> |
2307f1
|
11 |
<el-input v-model="formData.beanName" placeholder="请输入bean名称"/> |
d09108
|
12 |
</el-form-item> |
L |
13 |
<el-form-item label="参数" prop="params"> |
2307f1
|
14 |
<el-input v-model="formData.params" placeholder="请输入参数"/> |
d09108
|
15 |
</el-form-item> |
L |
16 |
<el-form-item label="cron表达式" prop="cronExpression"> |
2307f1
|
17 |
<el-popover ref="popoverRef" placement="bottom-start" trigger="click" width="600px"> |
D |
18 |
<vue3CronPlus @change="changeCron" @close="closeCron" max-height="600px" i18n="cn"/> |
|
19 |
<template #reference> |
|
20 |
<el-input v-model="formData.cronExpression" placeholder="请输入cron表达式"/> |
|
21 |
</template> |
|
22 |
</el-popover> |
d09108
|
23 |
</el-form-item> |
L |
24 |
<el-form-item label="备注" prop="remark"> |
2307f1
|
25 |
<el-input v-model="formData.remark" placeholder="请输入备注" type="textarea"/> |
d09108
|
26 |
</el-form-item> |
L |
27 |
</el-form> |
|
28 |
<template #footer> |
|
29 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
30 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
31 |
</template> |
|
32 |
</Dialog> |
|
33 |
</template> |
|
34 |
<script lang="ts" setup> |
2307f1
|
35 |
import * as ScheduleJobApi from '@/api/job' |
D |
36 |
import {vue3CronPlus} from 'vue3-cron-plus' |
|
37 |
import 'vue3-cron-plus/dist/index.css' |
d09108
|
38 |
|
2307f1
|
39 |
defineOptions({name: 'DataScheduleJobForm'}) |
d09108
|
40 |
|
2307f1
|
41 |
const {t} = useI18n() // 国际化 |
d09108
|
42 |
const message = useMessage() // 消息弹窗 |
L |
43 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
44 |
const dialogTitle = ref('') // 弹窗的标题 |
|
45 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
46 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
47 |
const formData = ref({ |
|
48 |
id: undefined, |
|
49 |
beanName: undefined, |
|
50 |
params: undefined, |
|
51 |
cronExpression: undefined, |
|
52 |
remark: undefined, |
|
53 |
status: 0 |
|
54 |
}) |
|
55 |
const formRules = reactive({ |
2307f1
|
56 |
beanName: [{required: true, message: 'bean名称不能为空', trigger: 'blur'}], |
D |
57 |
cronExpression: [{required: true, message: 'cron表达式不能为空', trigger: 'blur'}] |
d09108
|
58 |
}) |
L |
59 |
const formRef = ref() // 表单 Ref |
|
60 |
|
|
61 |
/** 打开弹窗 */ |
|
62 |
const open = async (type: string, id?: number) => { |
|
63 |
dialogVisible.value = true |
|
64 |
dialogTitle.value = t('action.' + type) |
|
65 |
formType.value = type |
|
66 |
resetForm() |
|
67 |
// 修改时,设置数据 |
|
68 |
if (id) { |
|
69 |
formLoading.value = true |
|
70 |
try { |
|
71 |
formData.value = await ScheduleJobApi.getScheduleJob(id) |
|
72 |
} finally { |
|
73 |
formLoading.value = false |
|
74 |
} |
|
75 |
} |
|
76 |
} |
2307f1
|
77 |
defineExpose({open}) // 提供 open 方法,用于打开弹窗 |
d09108
|
78 |
|
L |
79 |
/** 提交表单 */ |
|
80 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
81 |
const submitForm = async () => { |
|
82 |
// 校验表单 |
|
83 |
if (!formRef) return |
|
84 |
const valid = await formRef.value.validate() |
|
85 |
if (!valid) return |
|
86 |
// 提交请求 |
|
87 |
formLoading.value = true |
|
88 |
try { |
|
89 |
const data = formData.value as unknown as ScheduleJobApi.ScheduleJobVO |
|
90 |
if (formType.value === 'create') { |
|
91 |
await ScheduleJobApi.createScheduleJob(data) |
|
92 |
message.success(t('common.createSuccess')) |
|
93 |
} else { |
|
94 |
await ScheduleJobApi.updateScheduleJob(data) |
|
95 |
message.success(t('common.updateSuccess')) |
|
96 |
} |
|
97 |
dialogVisible.value = false |
|
98 |
// 发送操作成功的事件 |
|
99 |
emit('success') |
|
100 |
} finally { |
|
101 |
formLoading.value = false |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
/** 重置表单 */ |
|
106 |
const resetForm = () => { |
|
107 |
formData.value = { |
|
108 |
id: undefined, |
|
109 |
beanName: undefined, |
|
110 |
params: undefined, |
|
111 |
cronExpression: undefined, |
|
112 |
remark: undefined, |
|
113 |
status: 0 |
|
114 |
} |
|
115 |
formRef.value?.resetFields() |
|
116 |
} |
2307f1
|
117 |
|
D |
118 |
const changeCron = (cronValue) => { |
|
119 |
if (typeof (cronValue) == "string") { |
|
120 |
formData.value.cronExpression = cronValue; |
|
121 |
} |
|
122 |
} |
|
123 |
const popoverRef = ref() |
|
124 |
const closeCron = () => { |
|
125 |
popoverRef.value.hide() |
|
126 |
} |
d09108
|
127 |
</script> |