提交 | 用户 | 时间
|
7462da
|
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-row> |
|
11 |
<el-col :span="24"> |
|
12 |
<el-form-item label="名称" prop="itemtypename"> |
|
13 |
<el-input v-model="formData.itemtypename" placeholder="请输入名称"/> |
|
14 |
</el-form-item> |
|
15 |
</el-col> |
|
16 |
</el-row> |
|
17 |
<el-row> |
|
18 |
<el-col :span="24"> |
|
19 |
<el-form-item label="类名" prop="itemclasstype"> |
|
20 |
<el-input v-model="formData.itemclasstype" placeholder="请输入类名"/> |
|
21 |
</el-form-item> |
|
22 |
</el-col> |
|
23 |
</el-row> |
|
24 |
<el-row> |
|
25 |
<el-col :span="24"> |
|
26 |
<el-form-item label="程序集" prop="assemblyname"> |
|
27 |
<el-input v-model="formData.assemblyname" placeholder="请输入程序集"/> |
|
28 |
</el-form-item> |
|
29 |
</el-col> |
|
30 |
</el-row> |
|
31 |
</el-form> |
|
32 |
<template #footer> |
|
33 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
34 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
35 |
</template> |
|
36 |
</Dialog> |
|
37 |
</template> |
|
38 |
<script lang="ts" setup> |
|
39 |
import * as MmItemType from '@/api/model/pre/item' |
|
40 |
|
|
41 |
defineOptions({name: 'DataMmItemTypeForm'}) |
|
42 |
|
|
43 |
const {t} = useI18n() // 国际化 |
|
44 |
const message = useMessage() // 消息弹窗 |
|
45 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
46 |
const dialogTitle = ref('') // 弹窗的标题 |
|
47 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
48 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
49 |
const formData = ref({ |
|
50 |
id: undefined, |
|
51 |
itemtypename: undefined, |
|
52 |
itemclasstype: undefined, |
|
53 |
assemblyname: undefined, |
|
54 |
}) |
|
55 |
const formRules = reactive({ |
|
56 |
itemtypename: [{required: true, message: '名称不能为空', trigger: 'blur'}], |
|
57 |
itemclasstype: [{required: true, message: '类名不能为空', trigger: 'blur'}], |
|
58 |
}) |
|
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 MmItemType.getMmItemType(id) |
|
72 |
} finally { |
|
73 |
formLoading.value = false |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
defineExpose({open}) // 提供 open 方法,用于打开弹窗 |
|
78 |
|
|
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 MmItemType.MmItemTypeVO |
|
90 |
if (formType.value === 'create') { |
|
91 |
await MmItemType.createMmItemType(data) |
|
92 |
message.success(t('common.createSuccess')) |
|
93 |
} else { |
|
94 |
await MmItemType.updateMmItemType(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 |
itemtypename: undefined, |
|
110 |
itemclasstype: undefined, |
|
111 |
assemblyname: undefined, |
|
112 |
} |
|
113 |
formRef.value?.resetFields() |
|
114 |
} |
|
115 |
</script> |