fix(用户管理): 修复编辑用户时部门显示问题并增加员工密码初始化
在编辑用户时,后端返回的部门ID可能与前端选项中的ID类型不匹配,导致无法正确显示已选部门。新增getMatchedDeptId函数进行深度匹配查找,确保部门选择正确显示。
同时在员工新增表单中添加默认初始化密码字段,默认值为"123456",并添加相应的表单验证规则。
| | |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col v-if="operationType === 'add'" :span="10"> |
| | | <el-form-item label="默认初始化密码" prop="defaultPassword"> |
| | | <el-input |
| | | v-model="form.defaultPassword" |
| | | type="text" |
| | | placeholder="请输入" |
| | | clearable |
| | | maxlength="50" |
| | | show-word-limit |
| | | /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-card> |
| | | </template> |
| | |
| | | margin-right: 4px; |
| | | } |
| | | </style> |
| | | |
| | |
| | | staffEmergencyContactList: [createEmptyEmergency()], |
| | | // 角色(单选) |
| | | roleId: undefined, |
| | | defaultPassword: "123456", |
| | | }); |
| | | |
| | | const state = reactive({ |
| | |
| | | { required: true, message: "请选择部门", trigger: "change" }, |
| | | ], |
| | | roleId: [{ required: true, message: "请选择角色", trigger: "change" }], |
| | | defaultPassword: [ |
| | | { |
| | | validator: (_, value, callback) => { |
| | | if (operationType.value !== "add") { |
| | | callback(); |
| | | return; |
| | | } |
| | | if (value == null || String(value).trim() === "") { |
| | | callback(new Error("请输入默认初始化密码")); |
| | | return; |
| | | } |
| | | callback(); |
| | | }, |
| | | trigger: "blur", |
| | | }, |
| | | ], |
| | | }, |
| | | postOptions: [], |
| | | deptOptions: [], |
| | |
| | | const userId = row.userId || ids.value
|
| | | getUser(userId).then(response => {
|
| | | form.value = response.data
|
| | | form.value.deptId = getMatchedDeptId(
|
| | | response.deptId ?? response.data?.deptId ?? response.data?.dept?.id
|
| | | )
|
| | | postOptions.value = response.posts
|
| | | roleOptions.value = response.roles
|
| | | form.value.postIds = response.postIds
|
| | |
| | | })
|
| | | }
|
| | |
|
| | | function getMatchedDeptId(rawDeptId) {
|
| | | if (rawDeptId === undefined || rawDeptId === null || !Array.isArray(enabledDeptOptions.value)) {
|
| | | return rawDeptId
|
| | | }
|
| | | const target = String(rawDeptId)
|
| | | const stack = [...enabledDeptOptions.value]
|
| | | while (stack.length) {
|
| | | const node = stack.shift()
|
| | | if (!node) {
|
| | | continue
|
| | | }
|
| | | if (String(node.id) === target) {
|
| | | return node.id
|
| | | }
|
| | | if (Array.isArray(node.children) && node.children.length) {
|
| | | stack.push(...node.children)
|
| | | }
|
| | | }
|
| | | return rawDeptId
|
| | | }
|
| | |
|
| | | /** 提交按钮 */
|
| | | function submitForm() {
|
| | | proxy.$refs["userRef"].validate(valid => {
|