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