From 2e9ec4b50f7e8c25c97fecdef0ea71064f194249 Mon Sep 17 00:00:00 2001 From: Lxq <19852720163@163.com> Date: Fri, 19 Dec 2025 14:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=83=A8=E9=97=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rc_autoplc_front/src/api/user.ts | 8 ++++ .../src/views/department/index.vue | 43 +++++++++++++------ rc_autoplc_front/src/views/user/index.vue | 6 +-- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/rc_autoplc_front/src/api/user.ts b/rc_autoplc_front/src/api/user.ts index 6a3ea39..9c032ef 100644 --- a/rc_autoplc_front/src/api/user.ts +++ b/rc_autoplc_front/src/api/user.ts @@ -31,6 +31,14 @@ export function userlist(data: any) { }) } +export function userselect(data: any) { + return request({ + url: '/user/list', + method: 'get', + params: data, + }) +} + export function userbyid(id: string | number) { return request({ url: `/user/getById/${id}`, diff --git a/rc_autoplc_front/src/views/department/index.vue b/rc_autoplc_front/src/views/department/index.vue index 6cec064..a19370f 100644 --- a/rc_autoplc_front/src/views/department/index.vue +++ b/rc_autoplc_front/src/views/department/index.vue @@ -88,10 +88,10 @@ :formatter="formatCell" /> @@ -160,13 +160,13 @@ v-model="form.leaderId" filterable clearable - placeholder="请选择部门领导(可选)" + placeholder="请选择部门领导" style="width: 100%" > @@ -206,6 +206,7 @@ import { departmentdel, departtree, } from '@/api/department' +import { userselect } from '@/api/user' interface DeptItem { id?: number | string @@ -227,6 +228,7 @@ interface UserItem { username?: string realName?: string nickName?: string + nicke?: string name?: string } @@ -285,6 +287,18 @@ const formatCell = (_row: any, _column: any, value: any) => { return value === undefined || value === null || value === '' ? '暂无' : value } +// 根据leaderId获取用户的nicke字段 +const getLeaderNicke = (leaderId: number | string | null | undefined): string => { + if (!leaderId) return '暂无' + const user = userOptions.value.find(u => u.id == leaderId) + return user?.nicke || user?.realName || user?.nickName || user?.username || user?.name || '暂无' +} + +// 部门领导列的formatter +const formatLeaderCell = (_row: any, _column: any, _value: any) => { + return getLeaderNicke(_row.leaderId) +} + // 构建树形选择器的选项 const treeOptions = computed(() => { const buildOptions = (nodes: DeptItem[], excludeId?: number | string): any[] => { @@ -347,15 +361,14 @@ const handleTreeReset = () => { // 加载用户列表(用于选择部门领导) const loadUsers = async () => { try { - // 这里需要根据实际API调整,暂时使用空数组 - // 如果有用户列表API,可以在这里调用 - // const res: any = await userlist({ pageNum: 1, pageSize: 9999 }) - // const data = res?.data ?? res ?? {} - // const records = data.records || data.list || data.rows || data.items || [] - // userOptions.value = Array.isArray(records) ? records : [] - userOptions.value = [] + const res: any = await userselect({}) + // 兼容多种返回格式:res.data 或 res 本身 + const data = Array.isArray(res?.data) ? res.data : Array.isArray(res) ? res : [] + userOptions.value = data } catch (error) { console.error('load user list error', error) + ElMessage.error('加载用户列表失败') + userOptions.value = [] } } @@ -363,6 +376,11 @@ const loadUsers = async () => { const loadList = async () => { loading.value = true try { + // 确保用户列表已加载(用于显示部门领导名称) + if (userOptions.value.length === 0) { + await loadUsers() + } + // 构建查询参数,过滤空字符串 const params: any = { pageNum: pagination.pageNum, @@ -652,3 +670,4 @@ onMounted(() => { } + diff --git a/rc_autoplc_front/src/views/user/index.vue b/rc_autoplc_front/src/views/user/index.vue index 62b39fa..279a665 100644 --- a/rc_autoplc_front/src/views/user/index.vue +++ b/rc_autoplc_front/src/views/user/index.vue @@ -6,7 +6,7 @@ @@ -172,7 +172,7 @@ :data="deptTreeOptions" :props="{ value: 'id', label: 'deptName', children: 'children' }" check-strictly - placeholder="请选择部门(可选)" + placeholder="请选择部门" clearable style="width: 100%" /> @@ -182,7 +182,7 @@ v-model="form.posId" filterable clearable - placeholder="请选择职位(可选)" + placeholder="请选择职位" style="width: 100%" >