feat: 更新组件以支持新的功能和优化用户体验

- 在components.d.ts中添加NSwitch组件声明
- 在ManageLayout.vue中新增收藏功能相关的存储逻辑
- 在DashboardView.vue和SettingsManageView.vue中使用useRouteQuery自动同步URL查询参数
- 在SongListManageView.vue中移除不必要的按钮样式
This commit is contained in:
Megghy
2025-07-08 00:21:24 +08:00
parent 3fad3f277d
commit ca575a623e
5 changed files with 15 additions and 12 deletions

1
src/components.d.ts vendored
View File

@@ -35,6 +35,7 @@ declare module 'vue' {
NPopconfirm: typeof import('naive-ui')['NPopconfirm'] NPopconfirm: typeof import('naive-ui')['NPopconfirm']
NScrollbar: typeof import('naive-ui')['NScrollbar'] NScrollbar: typeof import('naive-ui')['NScrollbar']
NSpace: typeof import('naive-ui')['NSpace'] NSpace: typeof import('naive-ui')['NSpace']
NSwitch: typeof import('naive-ui')['NSwitch']
NTag: typeof import('naive-ui')['NTag'] NTag: typeof import('naive-ui')['NTag']
NText: typeof import('naive-ui')['NText'] NText: typeof import('naive-ui')['NText']
NTime: typeof import('naive-ui')['NTime'] NTime: typeof import('naive-ui')['NTime']

View File

@@ -66,6 +66,9 @@ const route = useRoute()
const windowWidth = window.innerWidth const windowWidth = window.innerWidth
const themeType = useStorage('Settings.Theme', ThemeType.Auto) const themeType = useStorage('Settings.Theme', ThemeType.Auto)
// 收藏功能相关
const favoriteMenuItems = useStorage<string[]>('Settings.FavoriteMenuItems', [])
// 侧边栏和布局相关 // 侧边栏和布局相关
const sider = ref() const sider = ref()
const { width } = useElementSize(sider) const { width } = useElementSize(sider)

View File

@@ -29,6 +29,7 @@ import {
useMessage useMessage
} from 'naive-ui' } from 'naive-ui'
import { onUnmounted, ref } from 'vue' import { onUnmounted, ref } from 'vue'
import { useRouteQuery } from '@vueuse/router'
import VueTurnstile from 'vue-turnstile' import VueTurnstile from 'vue-turnstile'
import SettingPaymentView from './Setting_PaymentView.vue' import SettingPaymentView from './Setting_PaymentView.vue'
import SettingsManageView from './SettingsManageView.vue' import SettingsManageView from './SettingsManageView.vue'
@@ -41,6 +42,9 @@ const turnstile = ref()
const accountInfo = useAccount() const accountInfo = useAccount()
const message = useMessage() const message = useMessage()
// 使用 useRouteQuery 自动同步 URL 查询参数
const selectedTab = useRouteQuery('tab', 'info', { transform: String })
const resetEmailModalVisiable = ref(false) const resetEmailModalVisiable = ref(false)
const resetPasswordModalVisiable = ref(false) const resetPasswordModalVisiable = ref(false)
const bindBiliCodeModalVisiable = ref(false) const bindBiliCodeModalVisiable = ref(false)
@@ -311,10 +315,10 @@ onUnmounted(() => {
> >
<NTabs <NTabs
v-if="accountInfo" v-if="accountInfo"
v-model:value="selectedTab"
type="segment" type="segment"
animated animated
style="width: 100%;" style="width: 100%;"
:default-value="$route.query.tab?.toString() ?? 'info'"
> >
<NTabPane <NTabPane
name="info" name="info"

View File

@@ -59,6 +59,7 @@
} from 'naive-ui'; } from 'naive-ui';
import { computed, h, nextTick, onActivated, onMounted, ref, shallowRef, markRaw } from 'vue'; import { computed, h, nextTick, onActivated, onMounted, ref, shallowRef, markRaw } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { useRouteQuery } from '@vueuse/router';
// 模板定义类型接口 // 模板定义类型接口
interface TemplateDefineTypes { interface TemplateDefineTypes {
@@ -231,9 +232,9 @@
{ label: '日程表', value: 'schedule' }, { label: '日程表', value: 'schedule' },
] as SelectOption[]; ] as SelectOption[];
// 路由查询参数优先级高于默认值 // 使用 useRouteQuery 自动同步 URL 查询参数
const selectedOption = ref(route.query.template?.toString() ?? 'index'); const selectedOption = useRouteQuery('template', 'index', { transform: String });
const selectedTab = ref(route.query.setting?.toString() ?? 'general'); const selectedTab = useRouteQuery('setting', 'general', { transform: String });
// 动态表单相关 // 动态表单相关
const dynamicConfigRef = shallowRef(); const dynamicConfigRef = shallowRef();
@@ -582,14 +583,9 @@
message.success('已保存'); message.success('已保存');
} }
// 路由激活时更新选项卡 // 路由激活时的处理useRouteQuery 已自动处理参数同步)
onActivated(() => { onActivated(() => {
if (route.query.tab) { // useRouteQuery 会自动同步,这里可以添加其他激活时的逻辑
selectedTab.value = route.query.setting?.toString() ?? 'general';
}
if (route.query.template) {
selectedOption.value = route.query.template.toString();
}
}); });
// 组件挂载时初始化数据 // 组件挂载时初始化数据

View File

@@ -765,7 +765,6 @@ onMounted(async () => {
添加歌曲 添加歌曲
</NButton> </NButton>
<NButton <NButton
secondary
type="primary" type="primary"
@click="$router.push({ name: 'manage-index', query: { tab: 'setting', setting: 'template', template: 'songlist' } })" @click="$router.push({ name: 'manage-index', query: { tab: 'setting', setting: 'template', template: 'songlist' } })"
> >