refactor(消息管理): 消息中心资源跳转

This commit is contained in:
WangXu10 2024-03-06 16:32:33 +08:00 committed by 刘瑞斌
parent c518e2b6ef
commit 29db17a9a4
5 changed files with 74 additions and 34 deletions

View File

@ -68,6 +68,8 @@ export interface MessageHistoryItem {
resourceType: string;
resourceName: string;
content: string;
organizationId: string;
projectId: string;
}
export function queryMessageHistoryList(data: historyQueryParams) {

View File

@ -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<boolean>(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<string, any> = {
* 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<string, any> = {
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(

View File

@ -14,6 +14,7 @@ export interface PathMapItem {
level: (typeof MENU_LEVEL)[number]; // 系统设置里有系统级别也有组织级别,按最低权限级别配置
children?: PathMapItem[];
routeQuery?: Record<string, any>;
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', // 测试计划-消息中心跳转对应别名
},
],
},

View File

@ -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<PathMapItem>(pathMap, alias as unknown as string);
};
/**
* name
* @param name name
@ -102,5 +110,6 @@ export default function usePathMap() {
jumpRouteByMapKey,
getRouteLevelByKey,
findLocalePath,
getRouteMapByAlias,
};
}

View File

@ -273,6 +273,35 @@ export function findNodeByKey<T>(trees: TreeNode<T>[], targetKey: string, custom
return null; // 如果在整个树形数组中都没有找到匹配的节点,则返回 null
}
/**
* alias
* @param trees
* @param targetKey
* @param customKey key
* @returns /null
*/
export function findNodeByAlias<T>(
trees: TreeNode<T>[],
targetKey: string,
customKey = 'alias'
): TreeNode<T> | 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
*/