4545 </el-input >
4646 </el-form-item >
4747 <el-form-item :label =" $t('views.userManage.userForm.phone.label')" >
48- <el-input
49- v-model =" userForm.phone"
50- :placeholder =" $t('views.userManage.userForm.phone.placeholder')"
51- >
48+ <el-input v-model =" userForm.phone" :placeholder =" $t('views.userManage.userForm.phone.placeholder')" >
5249 </el-input >
5350 </el-form-item >
5451 <el-form-item label =" 默认密码" v-if =" !isEdit" >
55- <span >{{userForm.password}}</span >
52+ <span >{{ userForm.password }}</span >
5653 </el-form-item >
5754 </el-form >
55+ <h4 class =" title-decoration-1 mb-16 mt-8" >{{ $t('views.userManage.roleSetting') }}</h4 >
56+ <MemberFormContent ref =" memberFormContentRef" :models =" formItemModel" v-model:form =" list"
57+ v-loading =" memberFormContentLoading" />
5858 <template #footer >
5959 <el-button @click.prevent =" visible = false" > {{ $t('common.cancel') }}</el-button >
6060 <el-button type =" primary" @click =" submit(userFormRef)" :loading =" loading" >
6464 </el-drawer >
6565</template >
6666<script setup lang="ts">
67- import {ref , reactive , watch } from ' vue'
68- import type {FormInstance } from ' element-plus'
67+ import { ref , reactive , watch , onBeforeMount } from ' vue'
68+ import type { FormInstance } from ' element-plus'
6969import userManageApi from ' @/api/user/user-manage'
70- import {MsgSuccess } from ' @/utils/message'
71- import {t } from ' @/locales'
70+ import { MsgSuccess } from ' @/utils/message'
71+ import { t } from ' @/locales'
72+ import type { FormItemModel } from ' @/api/type/role'
73+ import WorkspaceApi from ' @/api/workspace/workspace'
74+ import MemberFormContent from ' @/views/role/component/MemberFormContent.vue'
75+ import { RoleTypeEnum } from ' @/enums/system'
7276
7377const props = defineProps ({
7478 title: String ,
@@ -85,6 +89,69 @@ const userForm = ref<any>({
8589 nick_name: ' ' ,
8690})
8791
92+ const list = ref <any []>([]);
93+ const memberFormContentLoading = ref (false );
94+ const formItemModel = ref <FormItemModel []>([]);
95+ const roleFormItem = ref <FormItemModel []>([]);
96+ const adminRoleList = ref <any []>([])
97+ const workspaceFormItem = ref <FormItemModel []>([])
98+
99+ async function getRoleFormItem() {
100+ try {
101+ const res = await WorkspaceApi .getWorkspaceRoleList (memberFormContentLoading );
102+ roleFormItem .value = [{
103+ path: ' role_id' ,
104+ label: t (' views.role.member.role' ),
105+ rules: [
106+ {
107+ required: true ,
108+ message: ` ${t (' common.selectPlaceholder' )}${t (' views.role.member.role' )} ` ,
109+ },
110+ ],
111+ selectProps: {
112+ options: res .data ?.map (item => ({
113+ label: item .name ,
114+ value: item .id
115+ })) || [],
116+ placeholder: ` ${t (' common.selectPlaceholder' )}${t (' views.role.member.role' )} ` ,
117+ multiple: false
118+ }
119+ }]
120+ adminRoleList .value = res .data .filter (item => item .type === RoleTypeEnum .ADMIN )
121+ } catch (e ) {
122+ console .error (e );
123+ }
124+ }
125+ async function getWorkspaceFormItem() {
126+ try {
127+ const res = await WorkspaceApi .getWorkspaceList (memberFormContentLoading )
128+ workspaceFormItem .value = [
129+ {
130+ path: ' workspace_ids' ,
131+ label: t (' views.role.member.workspace' ),
132+ hidden : (e ) => adminRoleList .value .find (item => item .id === e .role_id ),
133+ selectProps: {
134+ options:
135+ res .data ?.map ((item ) => ({
136+ label: item .name ,
137+ value: item .id ,
138+ })) || [],
139+ placeholder: ` ${t (' common.selectPlaceholder' )}${t (' views.role.member.workspace' )} ` ,
140+ },
141+ },
142+ ]
143+ } catch (e ) {
144+ console .error (e )
145+ }
146+ }
147+
148+ onBeforeMount (async () => {
149+ await getRoleFormItem ();
150+ await getWorkspaceFormItem ();
151+ formItemModel .value = [... roleFormItem .value , ... workspaceFormItem .value ]
152+ list .value = [{ role_id: ' ' , workspace_ids: [] }]
153+ })
154+
88155const rules = reactive ({
89156 username: [
90157 {
@@ -157,27 +224,36 @@ const open = (data: any) => {
157224 visible .value = true
158225}
159226
227+ const memberFormContentRef = ref <InstanceType <typeof MemberFormContent >>()
160228const submit = async (formEl : FormInstance | undefined ) => {
161229 if (! formEl ) return
162230 await formEl .validate ((valid , fields ) => {
163231 if (valid ) {
164- if (isEdit .value ) {
165- userManageApi .putUserManage (userForm .value .id , userForm .value , loading ).then ((res ) => {
166- emit (' refresh' )
167- MsgSuccess (t (' common.editSuccess' ))
168- visible .value = false
169- })
170- } else {
171- userManageApi .postUserManage (userForm .value , loading ).then ((res ) => {
172- emit (' refresh' )
173- MsgSuccess (t (' common.createSuccess' ))
174- visible .value = false
175- })
176- }
232+ memberFormContentRef .value ?.validate ().then (async (valid : any ) => {
233+ if (valid ) {
234+ const params = {
235+ ... userForm .value ,
236+ role_setting: list .value
237+ }
238+ if (isEdit .value ) {
239+ userManageApi .putUserManage (userForm .value .id , params , loading ).then ((res ) => {
240+ emit (' refresh' )
241+ MsgSuccess (t (' common.editSuccess' ))
242+ visible .value = false
243+ })
244+ } else {
245+ userManageApi .postUserManage (params , loading ).then ((res ) => {
246+ emit (' refresh' )
247+ MsgSuccess (t (' common.createSuccess' ))
248+ visible .value = false
249+ })
250+ }
251+ }
252+ })
177253 }
178254 })
179255}
180256
181- defineExpose ({open })
257+ defineExpose ({ open })
182258 </script >
183259<style lang="scss" scoped></style >
0 commit comments