From a72aaafdfbb752f7b855b8ad621ba3058e59cb1a Mon Sep 17 00:00:00 2001 From: Maple <869445424@qq.com> Date: Mon, 4 Aug 2025 14:50:06 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E5=B2=97=E4=BD=8D=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E4=BA=86=E9=80=9A=E8=BF=87=E5=B2=97=E4=BD=8D=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=88=B0=E8=AF=A5=E5=B2=97=E4=BD=8D=E7=9A=84=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/system/post.ts | 7 ++ src/views/system/post/index.vue | 190 +++++++++++++++++++++++++++++++- 2 files changed, 195 insertions(+), 2 deletions(-) diff --git a/src/apis/system/post.ts b/src/apis/system/post.ts index f5954a4..bb69a1b 100644 --- a/src/apis/system/post.ts +++ b/src/apis/system/post.ts @@ -43,4 +43,11 @@ export function updatePost(postId: string, data: T.PostUpdateReq) { */ export function deletePost(postId: string) { return http.del(`${BASE_URL}/${postId}`); +} + +/** + * 查询岗位下的用户信息 + */ +export function getPostUsers(postId: string) { + return http.get(`${BASE_URL}/${postId}/user`); } \ No newline at end of file diff --git a/src/views/system/post/index.vue b/src/views/system/post/index.vue index 64cff0a..928c744 100644 --- a/src/views/system/post/index.vue +++ b/src/views/system/post/index.vue @@ -24,6 +24,50 @@ {{ Number(record.status) === 1 ? '正常' : '停用' }} + @@ -49,8 +94,10 @@ import type { TableColumnData } from '@arco-design/web-vue' import PostAddModal from './PostAddModal.vue' import PostDetailDrawer from './PostDetailDrawer.vue' -import { deletePost, listPost } from '@/apis/system/post' +import UserDetailDrawer from '../user/UserDetailDrawer.vue' +import { deletePost, listPost, getPostUsers } from '@/apis/system/post' import type { PostVO } from '@/apis/system/type' +import type { UserNewResp } from '@/apis/system/type' import { useResetReactive, useTable } from '@/hooks' import { isMobile } from '@/utils' import has from '@/utils/has' @@ -98,6 +145,10 @@ const { ...queryForm, }), { immediate: true }) +// 岗位用户数据 +const postUsersMap = ref>({}) +const userLoadingMap = ref>({}) + const tableColumns = ref([ { title: '序号', @@ -109,6 +160,7 @@ const tableColumns = ref([ { title: '岗位名称', dataIndex: 'postName', + slotName: 'postName', minWidth: 140, ellipsis: true, tooltip: true, @@ -169,8 +221,66 @@ const onDelete = (record: PostVO) => { }) } + + +// 下拉框显示状态变化时自动加载数据 +const onDropdownVisibleChange = async (visible: boolean, record: PostVO) => { + if (visible && !postUsersMap.value[record.postId] && !userLoadingMap.value[record.postId]) { + // 设置加载状态 + userLoadingMap.value[record.postId] = true + + try { + const response = await getPostUsers(record.postId) + + if (response.success && response.data) { + postUsersMap.value[record.postId] = response.data + } else { + postUsersMap.value[record.postId] = [] + } + } catch (error) { + console.error('获取岗位用户信息失败:', error) + postUsersMap.value[record.postId] = [] + } finally { + userLoadingMap.value[record.postId] = false + } + } +} + +// 点击岗位名称触发用户查询 +const onPostClick = async (record: PostVO) => { + // 如果已经加载过该岗位的用户数据,直接返回 + if (postUsersMap.value[record.postId]) { + return + } + + // 设置加载状态 + userLoadingMap.value[record.postId] = true + + try { + const response = await getPostUsers(record.postId) + + if (response.success && response.data) { + postUsersMap.value[record.postId] = response.data + } else { + postUsersMap.value[record.postId] = [] + } + } catch (error) { + console.error('获取岗位用户信息失败:', error) + postUsersMap.value[record.postId] = [] + } finally { + userLoadingMap.value[record.postId] = false + } +} + +// 点击用户详情 +const onUserClick = (user: UserNewResp) => { + UserDetailDrawerRef.value?.onOpen(user.userId) +} + + const PostAddModalRef = ref>() const PostDetailDrawerRef = ref>() +const UserDetailDrawerRef = ref>() // 新增 const onAdd = () => { @@ -188,4 +298,80 @@ const onDetail = (record: PostVO) => { } - +