refactor(消息管理): 消息中心资源跳转
This commit is contained in:
parent
c518e2b6ef
commit
29db17a9a4
|
@ -68,6 +68,8 @@ export interface MessageHistoryItem {
|
|||
resourceType: string;
|
||||
resourceName: string;
|
||||
content: string;
|
||||
organizationId: string;
|
||||
projectId: string;
|
||||
}
|
||||
|
||||
export function queryMessageHistoryList(data: historyQueryParams) {
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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', // 测试计划-消息中心跳转对应别名
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 遍历树,并返回找到的节点路径和节点
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue