diff --git a/src/views/system/UserDetail.vue b/src/views/system/UserDetail.vue index 57e433a..7d0c30f 100644 --- a/src/views/system/UserDetail.vue +++ b/src/views/system/UserDetail.vue @@ -255,7 +255,9 @@ const profileFormColumns = computed(() => c.type !== 'divider' && c.type !== 'html' && c.field !== 'EmployeeProfileUUID' && - c.field !== 'UserUUID', + c.field !== 'UserUUID' && + // 部门员工关联:按本页员工自动带出后隐藏(查不到时才显示让用户手动选) + !(profilePickerHidden.value && c.field === 'UserRoleDepartmentUUID'), ), ) @@ -329,21 +331,68 @@ async function loadProfile(): Promise { } } -/** 「点击填写」:新建档案(UserUUID 由本页上下文注入,表单内不出现该字段) */ -function openProfileCreate(): void { +/** 本页员工的「部门员工关联」(UserRoleDepartment):档案归属自动带出,取值即落库 */ +const profileDeptEmployee = ref<{ uuid: string; label: string } | null>(null) + +/** 表单里是否隐藏「部门员工关联」:已按本页员工自动带出时无需用户再选 */ +const profilePickerHidden = computed(() => !!profileDeptEmployee.value) + +/** + * 拉取该员工的主「部门员工关联」:档案归属由本页员工决定,无需用户在表单里再选。 + * 查不到(该员工尚未挂靠任何部门)时返回 null —— 此时表单仍显示选择器让用户手动选。 + */ +async function loadProfileDeptEmployee(): Promise { + profileDeptEmployee.value = null + if (!userUUID.value) return + try { + const res = await formApi.list>('UserRoleDepartment', { + UserUUID: userUUID.value, + page: 1, + pageSize: 1, + }) + const list = Array.isArray(res) + ? res + : ((res as { records?: Record[]; list?: Record[] })?.records + ?? (res as { list?: Record[] })?.list + ?? []) + const row = list[0] + if (!row?.UserRoleDepartmentUUID) return + const dept = String(row.DeptUUID_label ?? '') + const user = String(row.UserUUID_label ?? '') + profileDeptEmployee.value = { + uuid: String(row.UserRoleDepartmentUUID), + label: dept && user ? `${dept} · ${user}` : dept || user || String(row.UserRoleDepartmentUUID), + } + } catch { + // 查询失败不阻塞填写:表单里的「部门员工关联」选择器仍在,用户可手动选 + } +} + +/** 「点击填写」:新建档案(UserUUID 由本页上下文注入;部门员工关联自动带出后隐藏) */ +async function openProfileCreate(): Promise { if (!canEditProfile.value) return Object.keys(profileForm).forEach((k) => delete profileForm[k]) profileForm.UserUUID = userUUID.value + await loadProfileDeptEmployee() + if (profileDeptEmployee.value) { + profileForm.UserRoleDepartmentUUID = profileDeptEmployee.value.uuid + profileForm.UserRoleDepartmentUUID_label = profileDeptEmployee.value.label + } profileIsEdit.value = false profileDialogVisible.value = true } -/** 「编辑」:回填现有档案 */ -function openProfileEdit(): void { +/** 「编辑」:回填现有档案(同样自动带出部门员工关联并隐藏该字段) */ +async function openProfileEdit(): Promise { if (!canEditProfile.value || !profileRecord.value) return Object.keys(profileForm).forEach((k) => delete profileForm[k]) Object.assign(profileForm, profileRecord.value) profileForm.UserUUID = userUUID.value + await loadProfileDeptEmployee() + if (profileDeptEmployee.value && !profileForm.UserRoleDepartmentUUID) { + profileForm.UserRoleDepartmentUUID = profileDeptEmployee.value.uuid + profileForm.UserRoleDepartmentUUID_label = profileDeptEmployee.value.label + } profileIsEdit.value = true profileDialogVisible.value = true }