Skip to content

Commit 69e85de

Browse files
committed
✨ feat: 优化菜单路由名称处理逻辑
1 parent 5205d6e commit 69e85de

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

electron/main/services/CacheService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ export class CacheService {
213213
/**
214214
* 读取缓存
215215
*/
216-
public async get(type: CacheResourceType, key: string): Promise<Buffer> {
216+
public async get(type: CacheResourceType, key: string): Promise<Buffer | null> {
217217
await this.init();
218218
const { target } = this.resolveSafePath(type, key);
219+
if (!existsSync(target)) return null;
219220
return await readFile(target);
220221
}
221222

src/components/Layout/Menu.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,17 +310,18 @@ const checkMenuItem = () => {
310310
(router.currentRoute.value.matched?.[0]?.name as string) ||
311311
(router.currentRoute.value?.name as string);
312312
if (!routerName) return;
313-
// 处理本地歌曲子路由
314-
if (routerName.startsWith("local-")) {
315-
routerName = "local";
316-
}
317-
// 处理收藏子路由
318-
if (routerName.startsWith("like-") && routerName !== "like-songs") {
319-
routerName = "like";
320-
}
321-
// 处理下载子路由
322-
if (routerName.startsWith("download-")) {
323-
routerName = "download";
313+
// 处理路由名称
314+
const prefixMap = [
315+
{ prefix: "discover-", name: "discover" },
316+
{ prefix: "local-", name: "local" },
317+
{ prefix: "like-", name: "like", exclude: "like-songs" },
318+
{ prefix: "download-", name: "download" },
319+
];
320+
for (const item of prefixMap) {
321+
if (routerName.startsWith(item.prefix) && (!item.exclude || routerName !== item.exclude)) {
322+
routerName = item.name;
323+
break;
324+
}
324325
}
325326
// 显示菜单
326327
menuRef.value?.showOption(routerName);
@@ -341,6 +342,7 @@ const checkMenuItem = () => {
341342
menuActiveKey.value = routerName;
342343
break;
343344
}
345+
console.log(menuActiveKey.value);
344346
};
345347
346348
// 开启心动模式

0 commit comments

Comments
 (0)