UserDrawer.vue
7.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<template>
<BasicDrawer
v-bind="$attrs"
@register="registerDrawer"
:title="getTitle"
:width="adaptiveWidth"
@ok="handleSubmit"
:showFooter="showFooter"
destroyOnClose
>
<BasicForm @register="registerForm" />
</BasicDrawer>
</template>
<script lang="ts" setup>
import { defineComponent, ref, computed, unref, useAttrs } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './user.data';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import { saveOrUpdateUser, getUserRoles, getUserDepartList, getAllRolesListNoByTenant, getAllRolesList } from './user.api';
import { useDrawerAdaptiveWidth } from '/@/hooks/jeecg/useAdaptiveWidth';
import { getTenantId } from "/@/utils/auth";
// 声明Emits
const emit = defineEmits(['success', 'register']);
const attrs = useAttrs();
const isUpdate = ref(true);
const rowId = ref('');
const departOptions = ref([]);
let isFormDepartUser = false;
//表单配置
const [registerForm, { setProps, resetFields, setFieldsValue, validate, updateSchema }] = useForm({
labelWidth: 90,
schemas: formSchema,
showActionButtonGroup: false,
});
// TODO [VUEN-527] https://www.teambition.com/task/6239beb894b358003fe93626
const showFooter = ref(true);
//表单赋值
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
await resetFields();
showFooter.value = data?.showFooter ?? true;
setDrawerProps({ confirmLoading: false, showFooter: showFooter.value });
isUpdate.value = !!data?.isUpdate;
if (unref(isUpdate)) {
rowId.value = data.record.id;
//租户信息定义成数组
if (data.record.relTenantIds && !Array.isArray(data.record.relTenantIds)) {
data.record.relTenantIds = data.record.relTenantIds.split(',');
} else {
//【issues/I56C5I】用户管理中连续点两次编辑租户配置就丢失了
//data.record.relTenantIds = [];
}
//查角色/赋值/try catch 处理,不然编辑有问题
try {
const userRoles = await getUserRoles({ userid: data.record.id });
if (userRoles && userRoles.length > 0) {
data.record.selectedroles = userRoles;
}
} catch (error) {}
//查所属部门/赋值
const userDepart = await getUserDepartList({ userId: data.record.id });
if (userDepart && userDepart.length > 0) {
data.record.selecteddeparts = userDepart;
let selectDepartKeys = Array.from(userDepart, ({ key }) => key);
data.record.selecteddeparts = selectDepartKeys.join(',');
departOptions.value = userDepart.map((item) => {
return { label: item.title, value: item.key };
});
}
//负责部门/赋值
data.record.departIds && !Array.isArray(data.record.departIds) && (data.record.departIds = data.record.departIds.split(','));
//update-begin---author:zyf Date:20211210 for:避免空值显示异常------------
//update-begin---author:liusq Date:20231008 for:[issues/772]避免空值显示异常------------
data.record.departIds = (!data.record.departIds || data.record.departIds == '') ? [] : data.record.departIds;
//update-end-----author:liusq Date:20231008 for:[issues/772]避免空值显示异常------------
//update-begin---author:zyf Date:20211210 for:避免空值显示异常------------
}
//处理角色用户列表情况(和角色列表有关系)
data.selectedroles && (await setFieldsValue({ selectedroles: data.selectedroles }));
// -update-begin--author:liaozhiyang---date:20240702---for:【TV360X-1737】部门用户编辑接口,增加参数updateFromPage:"deptUsers"
isFormDepartUser = data?.departDisabled === true ? true : false;
// -update-end--author:liaozhiyang---date:20240702---for:【TV360X-1737】部门用户编辑接口,增加参数updateFromPage:"deptUsers"
//编辑时隐藏密码/角色列表隐藏角色信息/我的部门时隐藏所属部门
updateSchema([
{
field: 'password',
// 【QQYUN-8324】
ifShow: !unref(isUpdate),
},
{
field: 'confirmPassword',
ifShow: !unref(isUpdate),
},
{
field: 'selectedroles',
show: !data.isRole,
},
{
field: 'departIds',
componentProps: { options: departOptions },
},
{
field: 'selecteddeparts',
show: !data?.departDisabled,
},
{
field: 'selectedroles',
show: !data?.departDisabled,
//update-begin---author:wangshuai ---date:20230424 for:【issues/4844】多租户模式下,新增或编辑用户,选择角色一栏,角色选项没有做租户隔离------------
//判断是否为多租户模式
componentProps:{
api: data.tenantSaas?getAllRolesList:getAllRolesListNoByTenant
}
//update-end---author:wangshuai ---date:20230424 for:【issues/4844】多租户模式下,新增或编辑用户,选择角色一栏,角色选项没有做租户隔离------------
},
//update-begin---author:wangshuai ---date:20230522 for:【issues/4935】租户用户编辑界面中租户下拉框未过滤,显示当前系统所有的租户------------
{
field: 'relTenantIds',
componentProps:{
disabled: !!data.tenantSaas,
},
},
//update-end---author:wangshuai ---date:20230522 for:【issues/4935】租户用户编辑界面中租户下拉框未过滤,显示当前系统所有的租户------------
]);
//update-begin---author:wangshuai ---date:20230522 for:【issues/4935】租户用户编辑界面中租户下拉框未过滤,显示当前系统所有的租户------------
if(!unref(isUpdate) && data.tenantSaas){
await setFieldsValue({ relTenantIds: getTenantId().toString() })
}
//update-end---author:wangshuai ---date:20230522 for:【issues/4935】租户用户编辑界面中租户下拉框未过滤,显示当前系统所有的租户------------
// 无论新增还是编辑,都可以设置表单值
if (typeof data.record === 'object') {
setFieldsValue({
...data.record,
});
}
// 隐藏底部时禁用整个表单
//update-begin-author:taoyan date:2022-5-24 for: VUEN-1117【issue】0523周开源问题
setProps({ disabled: !showFooter.value });
//update-end-author:taoyan date:2022-5-24 for: VUEN-1117【issue】0523周开源问题
});
//获取标题
const getTitle = computed(() => {
// update-begin--author:liaozhiyang---date:20240306---for:【QQYUN-8389】系统用户详情抽屉title更改
if (!unref(isUpdate)) {
return '新增用户';
} else {
return unref(showFooter) ? '编辑用户' : '用户详情';
}
// update-end--author:liaozhiyang---date:20240306---for:【QQYUN-8389】系统用户详情抽屉title更改
});
const { adaptiveWidth } = useDrawerAdaptiveWidth();
//提交事件
async function handleSubmit() {
try {
let values = await validate();
setDrawerProps({ confirmLoading: true });
values.userIdentity === 1 && (values.departIds = '');
let isUpdateVal = unref(isUpdate);
// -update-begin--author:liaozhiyang---date:20240702---for:【TV360X-1737】部门用户编辑接口,增加参数updateFromPage:"deptUsers"
let params = values;
if (isFormDepartUser) {
params = { ...params, updateFromPage: 'deptUsers' };
}
// -update-end--author:liaozhiyang---date:20240702---for:【TV360X-1737】部门用户编辑接口,增加参数updateFromPage:"deptUsers"
//提交表单
await saveOrUpdateUser(params, isUpdateVal);
//关闭弹窗
closeDrawer();
//刷新列表
emit('success',{isUpdateVal ,values});
} finally {
setDrawerProps({ confirmLoading: false });
}
}
</script>