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