音乐模块调整

This commit is contained in:
zhongluofeng
2026-09-15 17:17:16 +08:00
parent 4f574cb5fa
commit 8f853f7ef3
31 changed files with 3819 additions and 936 deletions
+31 -5
View File
@@ -31,6 +31,17 @@ export const useModuleTabsStore = defineStore('moduleTabs', () => {
/** 待跳转 tab(搜索导航设置):{ moduleId, tab },模块挂载/已挂载时消费 */
const pendingTab = ref<{ moduleId: string; tab: string } | null>(null)
/**
* 各模块上次停留的 tab(内存记忆)。
*
* 模块被切走时组件卸载、`activeTab` 随之丢失,再切回来总是回到第一个 tab——
* 对「曲库 / 发现音乐 / 设置」这种三级结构的模块尤其别扭。
* 只做内存记忆(不落盘):tab 集合可能随版本变化,跨版本恢复旧值反而容易出错。
*/
const lastTabByModule = ref<Record<string, string>>({})
/** 当前已注册的模块 idunregister 时据此保存) */
let currentModuleId = ''
/** 设置待跳转 tab(搜索结果点击时调用) */
const setPendingTab = (moduleId: string, tab: string) => {
pendingTab.value = { moduleId, tab }
@@ -56,15 +67,30 @@ export const useModuleTabsStore = defineStore('moduleTabs', () => {
/** 是否显示保存按钮(当前在设置 tab 且注册了保存处理函数) */
const saveVisible = computed(() => saveHandler.value !== null && activeTab.value === 'settings')
/** 模块注册标签(onMounted 时调用) */
const registerTabs = (tabList: ModuleTab[], current: string) => {
/**
* 模块注册标签(onMounted 时调用)。
* 返回该模块**应当使用**的 tab:优先复用上次停留的(且在当前 tab 集合内),
* 否则用传入的初始值。调用方若拿到不同值,需同步自己的 activeTab。
*/
const registerTabs = (moduleId: string, tabList: ModuleTab[], current: string): string => {
currentModuleId = moduleId
tabs.value = tabList
activeTab.value = current
const remembered = lastTabByModule.value[moduleId]
const restored =
remembered && tabList.some((t) => t.value === remembered) ? remembered : current
activeTab.value = restored
floatingVisible.value = false
return restored
}
/** 模块注销标签(onUnmounted 时调用) */
const unregisterTabs = () => {
/**
* 模块注销标签(onUnmounted 时调用)。
* `moduleId` 缺省时用当前注册的模块(保留旧调用点的语义)。
*/
const unregisterTabs = (moduleId?: string) => {
const id = moduleId ?? currentModuleId
if (id && activeTab.value) lastTabByModule.value[id] = activeTab.value
currentModuleId = ''
tabs.value = []
activeTab.value = ''
floatingVisible.value = false