提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<Dialog :title="dialogTitle" v-model="dialogVisible"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
:model="formData" |
|
6 |
:rules="formRules" |
|
7 |
label-width="100px" |
|
8 |
v-loading="formLoading" |
|
9 |
> |
|
10 |
<el-form-item label="分类名" prop="name"> |
|
11 |
<el-input v-model="formData.name" placeholder="请输入分类名" /> |
|
12 |
</el-form-item> |
|
13 |
<el-form-item label="分类标志" prop="code"> |
|
14 |
<el-input v-model="formData.code" placeholder="请输入分类标志" /> |
|
15 |
</el-form-item> |
|
16 |
<el-form-item label="分类状态" prop="status"> |
|
17 |
<el-radio-group v-model="formData.status"> |
|
18 |
<el-radio |
|
19 |
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" |
|
20 |
:key="dict.value" |
3e359e
|
21 |
:value="dict.value" |
820397
|
22 |
> |
H |
23 |
{{ dict.label }} |
|
24 |
</el-radio> |
|
25 |
</el-radio-group> |
|
26 |
</el-form-item> |
|
27 |
<el-form-item label="分类排序" prop="sort"> |
|
28 |
<el-input-number |
|
29 |
v-model="formData.sort" |
|
30 |
placeholder="请输入分类排序" |
|
31 |
class="!w-1/1" |
|
32 |
:precision="0" |
|
33 |
/> |
|
34 |
</el-form-item> |
|
35 |
</el-form> |
|
36 |
<template #footer> |
|
37 |
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button> |
|
38 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
39 |
</template> |
|
40 |
</Dialog> |
|
41 |
</template> |
|
42 |
<script setup lang="ts"> |
|
43 |
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict' |
|
44 |
import { CategoryApi, CategoryVO } from '@/api/bpm/category' |
3e359e
|
45 |
import { CommonStatusEnum } from '@/utils/constants' |
820397
|
46 |
|
H |
47 |
/** BPM 流程分类 表单 */ |
|
48 |
defineOptions({ name: 'CategoryForm' }) |
|
49 |
|
|
50 |
const { t } = useI18n() // 国际化 |
|
51 |
const message = useMessage() // 消息弹窗 |
|
52 |
|
|
53 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
54 |
const dialogTitle = ref('') // 弹窗的标题 |
|
55 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
56 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
57 |
const formData = ref({ |
|
58 |
id: undefined, |
|
59 |
name: undefined, |
|
60 |
code: undefined, |
3e359e
|
61 |
status: CommonStatusEnum.ENABLE, |
820397
|
62 |
sort: undefined |
H |
63 |
}) |
|
64 |
const formRules = reactive({ |
|
65 |
name: [{ required: true, message: '分类名不能为空', trigger: 'blur' }], |
|
66 |
code: [{ required: true, message: '分类标志不能为空', trigger: 'blur' }], |
|
67 |
status: [{ required: true, message: '分类状态不能为空', trigger: 'blur' }], |
|
68 |
sort: [{ required: true, message: '分类排序不能为空', trigger: 'blur' }] |
|
69 |
}) |
|
70 |
const formRef = ref() // 表单 Ref |
|
71 |
|
|
72 |
/** 打开弹窗 */ |
|
73 |
const open = async (type: string, id?: number) => { |
|
74 |
dialogVisible.value = true |
|
75 |
dialogTitle.value = t('action.' + type) |
|
76 |
formType.value = type |
|
77 |
resetForm() |
|
78 |
// 修改时,设置数据 |
|
79 |
if (id) { |
|
80 |
formLoading.value = true |
|
81 |
try { |
|
82 |
formData.value = await CategoryApi.getCategory(id) |
|
83 |
} finally { |
|
84 |
formLoading.value = false |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
89 |
|
|
90 |
/** 提交表单 */ |
|
91 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
92 |
const submitForm = async () => { |
|
93 |
// 校验表单 |
|
94 |
await formRef.value.validate() |
|
95 |
// 提交请求 |
|
96 |
formLoading.value = true |
|
97 |
try { |
|
98 |
const data = formData.value as unknown as CategoryVO |
|
99 |
if (formType.value === 'create') { |
|
100 |
await CategoryApi.createCategory(data) |
|
101 |
message.success(t('common.createSuccess')) |
|
102 |
} else { |
|
103 |
await CategoryApi.updateCategory(data) |
|
104 |
message.success(t('common.updateSuccess')) |
|
105 |
} |
|
106 |
dialogVisible.value = false |
|
107 |
// 发送操作成功的事件 |
|
108 |
emit('success') |
|
109 |
} finally { |
|
110 |
formLoading.value = false |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
/** 重置表单 */ |
|
115 |
const resetForm = () => { |
|
116 |
formData.value = { |
|
117 |
id: undefined, |
|
118 |
name: undefined, |
|
119 |
code: undefined, |
3e359e
|
120 |
status: CommonStatusEnum.ENABLE, |
820397
|
121 |
sort: undefined |
H |
122 |
} |
|
123 |
formRef.value?.resetFields() |
|
124 |
} |
|
125 |
</script> |