feat(admin): 升级后台主题并增加本机只读预览

This commit is contained in:
2026-12-01 16:32:03 +08:00
parent c48df2464e
commit 9024e4b287
24 changed files with 1056 additions and 38 deletions
+42
View File
@@ -11,6 +11,31 @@ import { setTheme } from '@/utils/theme'
const storageSetting = cache.get(SETTING_KEY)
type AdminUi = 'legacy' | 'v2'
const APPEARANCE_KEY = 'admin_ui'
// A preview can seed <html data-admin-ui="v2"> before the first store is created.
// Its switch is local to that document; it never overwrites the normal entry's preference.
function initialAppearance() {
const root = document.documentElement
const preview = root.dataset.adminUi === 'v2'
const mode: AdminUi = preview || cache.get(APPEARANCE_KEY) === 'v2' ? 'v2' : 'legacy'
root.dataset.adminUi = mode
return { preview, mode }
}
// Keep the new preference separate from the existing, versioned settings object.
export const useAdminAppearanceStore = defineStore('adminAppearance', {
state: initialAppearance,
actions: {
select(mode: AdminUi) {
this.mode = mode
document.documentElement.dataset.adminUi = mode
if (!this.preview) cache.set(APPEARANCE_KEY, mode)
}
}
})
function applySettingSchemaMigrations(
state: Record<string, any>,
storedVersion: number
@@ -49,7 +74,15 @@ export const useSettingStore = defineStore({
state._settingSchemaVersion = SETTING_SCHEMA_VERSION
return state
},
getters: {
adminUi(): AdminUi {
return useAdminAppearanceStore().mode
}
},
actions: {
toggleAdminUi() {
useAdminAppearanceStore().select(this.adminUi === 'v2' ? 'legacy' : 'v2')
},
// 设置布局设置
setSetting(data: Record<string, any>) {
const { key, value } = data
@@ -64,6 +97,14 @@ export const useSettingStore = defineStore({
},
// 设置主题色
setTheme(isDark: boolean) {
// An explicitly chosen accent is shared; the legacy default stays blue,
// while the v2 default is jade. Neither switch rewrites the color picker.
const rootStyle = document.documentElement.style
if (this.theme && this.theme !== defaultSetting.theme) {
rootStyle.setProperty('--zyt-user-primary', this.theme)
} else {
rootStyle.removeProperty('--zyt-user-primary')
}
setTheme(
{
primary: this.theme,
@@ -83,6 +124,7 @@ export const useSettingStore = defineStore({
}
this._settingSchemaVersion = SETTING_SCHEMA_VERSION
cache.remove(SETTING_KEY)
useAdminAppearanceStore().select('legacy')
}
}
})