From 29db17a9a41497ad50b633f65d216c9d977da147 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 6 Mar 2024 16:32:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B6=88=E6=81=AF=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E6=B6=88=E6=81=AF=E4=B8=AD=E5=BF=83=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/modules/message/index.ts | 2 + .../ms-message/MessageCenterDrawer.vue | 60 +++++++++---------- frontend/src/config/pathMap.ts | 6 ++ frontend/src/hooks/usePathMap.ts | 11 +++- frontend/src/utils/index.ts | 29 +++++++++ 5 files changed, 74 insertions(+), 34 deletions(-) diff --git a/frontend/src/api/modules/message/index.ts b/frontend/src/api/modules/message/index.ts index 44749ac27e..cce6095672 100644 --- a/frontend/src/api/modules/message/index.ts +++ b/frontend/src/api/modules/message/index.ts @@ -68,6 +68,8 @@ export interface MessageHistoryItem { resourceType: string; resourceName: string; content: string; + organizationId: string; + projectId: string; } export function queryMessageHistoryList(data: historyQueryParams) { diff --git a/frontend/src/components/business/ms-message/MessageCenterDrawer.vue b/frontend/src/components/business/ms-message/MessageCenterDrawer.vue index be7da5d6cc..52a631e14e 100644 --- a/frontend/src/components/business/ms-message/MessageCenterDrawer.vue +++ b/frontend/src/components/business/ms-message/MessageCenterDrawer.vue @@ -149,7 +149,7 @@ }>(); const { t } = useI18n(); - const { jumpRouteByMapKey } = usePathMap(); + const { jumpRouteByMapKey, getRouteMapByAlias } = usePathMap(); const innerVisible = useVModel(props, 'visible', emit); const position = ref('all'); const noMoreData = ref(false); @@ -163,11 +163,6 @@ current: 1, }); - // 全部标记为已读 - async function prepositionEdit() { - await getMessageReadAll(); - } - // 左側模塊列表加載 async function loadModuleList() { const list = await getMessageList({ projectId: projectId.value }); @@ -206,10 +201,11 @@ pageNation.value.total = res.total; } - // 加载总数count + // 加载未读count async function loadTotalCount(key: string) { const res = await queryMessageHistoryCount({ resourceType: key, + status: 'UNREAD', receiver: userStore.id, current: 1, pageSize: 10, @@ -226,17 +222,6 @@ } } - // 加载模块count - async function loadModuleCount(key: string) { - const res = await queryMessageHistoryCount({ - resourceType: key, - receiver: userStore.id, - current: 1, - pageSize: 10, - }); - return res; - } - // 切换左侧模块 function clickModule(key: string) { if (key === 'BUG_MANAGEMENT') { @@ -273,6 +258,7 @@ loadMessageHistoryList(position.value, currentResourceType.value); } + // 获取动态模块count function getModuleCount(type: string) { let count = '0'; if (type === 'BUG_MANAGEMENT') { @@ -308,21 +294,29 @@ // 点击名称跳转 function handleNameClick(item: MessageHistoryItem) { - console.log('开始跳转了', item); - /** - * const routeQuery: Record = { - * organizationId: item.organizationId, - * projectId: item.projectId, - * id: item.resourceId, - * }; - * if (item.organizationId === 'SYSTEM') { - * delete routeQuery.organizationId; - * } - * if (item.projectId === 'SYSTEM' || item.projectId === 'ORGANIZATION') { - * delete routeQuery.projectId; - * } - * jumpRouteByMapKey(item.module, routeQuery, true); - */ + const routeQuery: Record = { + organizationId: item.organizationId, + projectId: item.projectId, + id: item.resourceId, + }; + if (item.organizationId === 'SYSTEM') { + delete routeQuery.organizationId; + } + if (item.projectId === 'SYSTEM' || item.projectId === 'ORGANIZATION') { + delete routeQuery.projectId; + } + const routeMap = getRouteMapByAlias(item.resourceType); + jumpRouteByMapKey(routeMap?.key, routeQuery, true); + } + + // 全部标记为已读 + async function prepositionEdit() { + await getMessageReadAll(); + messageHistoryList.value = []; + pageNation.value.current = 1; + // 左侧消息总数 + await loadTotalCount(''); + await loadMessageHistoryList(position.value, currentResourceType.value); } watch( diff --git a/frontend/src/config/pathMap.ts b/frontend/src/config/pathMap.ts index 621c4ccb26..8411b0beba 100644 --- a/frontend/src/config/pathMap.ts +++ b/frontend/src/config/pathMap.ts @@ -14,6 +14,7 @@ export interface PathMapItem { level: (typeof MENU_LEVEL)[number]; // 系统设置里有系统级别也有组织级别,按最低权限级别配置 children?: PathMapItem[]; routeQuery?: Record; + alias?: string; // 别名:用于消息中心跳转映射 } /** @@ -79,6 +80,7 @@ export const pathMap: PathMapItem[] = [ route: RouteEnum.BUG_MANAGEMENT_INDEX, permission: [], level: MENU_LEVEL[2], + alias: 'BUG_SYNC_TASK', }, { key: 'BUG_MANAGEMENT_BUG_DETAIL', // 缺陷管理-缺陷详情 @@ -86,6 +88,7 @@ export const pathMap: PathMapItem[] = [ route: RouteEnum.BUG_MANAGEMENT_DETAIL, permission: [], level: MENU_LEVEL[2], + alias: 'BUG_TASK', }, { key: 'BUG_MANAGEMENT_BUG_recycle', // 缺陷管理-回收站 @@ -123,6 +126,7 @@ export const pathMap: PathMapItem[] = [ route: RouteEnum.CASE_MANAGEMENT_CASE_DETAIL, permission: [], level: MENU_LEVEL[2], + alias: 'FUNCTIONAL_CASE_TASK', }, ], }, @@ -160,6 +164,7 @@ export const pathMap: PathMapItem[] = [ route: RouteEnum.CASE_MANAGEMENT_REVIEW_DETAIL, permission: [], level: MENU_LEVEL[2], + alias: 'CASE_REVIEW_TASK', children: [ { key: 'CASE_MANAGEMENT_REVIEW_DETAIL_CASE_DETAIL', // 功能测试-功能用例-评审详情-用例详情 @@ -688,6 +693,7 @@ export const pathMap: PathMapItem[] = [ route: RouteEnum.TEST_PLAN_INDEX, permission: [], level: MENU_LEVEL[2], + alias: 'TEST_PLAN_TASK', // 测试计划-消息中心跳转对应别名 }, ], }, diff --git a/frontend/src/hooks/usePathMap.ts b/frontend/src/hooks/usePathMap.ts index ebe3b92032..0c6c822743 100644 --- a/frontend/src/hooks/usePathMap.ts +++ b/frontend/src/hooks/usePathMap.ts @@ -1,6 +1,6 @@ import { MENU_LEVEL, pathMap, PathMapItem, PathMapRoute } from '@/config/pathMap'; import router from '@/router'; -import { findNodeByKey, mapTree, TreeNode } from '@/utils'; +import { findNodeByAlias, findNodeByKey, mapTree, TreeNode } from '@/utils'; export default function usePathMap() { /** @@ -58,6 +58,14 @@ export default function usePathMap() { } }; + /** + * 根据 Alias 获取路由 + * @param alias 路由的 alias + */ + const getRouteMapByAlias = (alias: string) => { + return findNodeByAlias(pathMap, alias as unknown as string); + }; + /** * 通过路由的 name 来获取它的菜单级别 * @param name 路由的 name @@ -102,5 +110,6 @@ export default function usePathMap() { jumpRouteByMapKey, getRouteLevelByKey, findLocalePath, + getRouteMapByAlias, }; } diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 8b4ed31986..248450a27e 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -273,6 +273,35 @@ export function findNodeByKey(trees: TreeNode[], targetKey: string, custom return null; // 如果在整个树形数组中都没有找到匹配的节点,则返回 null } +/** + * 根据属性 alias 查找树形数组中匹配的某个节点 + * @param trees 属性数组 + * @param targetKey 需要匹配的属性值 + * @param customKey 默认为 key,可自定义需要匹配的属性名 + * @returns 匹配的节点/null + */ +export function findNodeByAlias( + trees: TreeNode[], + targetKey: string, + customKey = 'alias' +): TreeNode | T | null { + for (let i = 0; i < trees.length; i++) { + const node = trees[i]; + if (node[customKey] === targetKey) { + return node; // 如果当前节点的 key 与目标 key 匹配,则返回当前节点 + } + + if (Array.isArray(node.children) && node.children.length > 0) { + const _node = findNodeByAlias(node.children, targetKey, customKey); // 递归在子节点中查找 + if (_node) { + return _node; // 如果在子节点中找到了匹配的节点,则返回该节点 + } + } + } + + return null; // 如果在整个树形数组中都没有找到匹配的节点,则返回 null +} + /** * 根据 key 遍历树,并返回找到的节点路径和节点 */