From 98a53588c381bdcdea111cb1deddc06f6c7f1c28 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期四, 09 四月 2026 14:12:09 +0800
Subject: [PATCH] fix(用户管理): 修复编辑用户时部门显示问题并增加员工密码初始化

---
 src/views/system/user/index.vue |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue
index 9d16126..cc52725 100644
--- a/src/views/system/user/index.vue
+++ b/src/views/system/user/index.vue
@@ -507,6 +507,9 @@
 	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
@@ -517,6 +520,27 @@
 	})
 }
 
+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 => {

--
Gitblit v1.9.3