Skip to content

Commit f07fa1a

Browse files
authored
fix: fix change theme error when open playground (#2681)
1 parent 1bd0c02 commit f07fa1a

File tree

5 files changed

+36
-57
lines changed

5 files changed

+36
-57
lines changed

examples/sites/playground/App.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import logoUrl from './assets/opentiny-logo.svg?url'
1111
import GitHub from './icons/Github.vue'
1212
import Share from './icons/Share.vue'
1313
14-
const VERSION = 'tiny-vue-version-3.19'
14+
const VERSION = 'tiny-vue-version-3.20'
1515
const NOTIFY_KEY = 'tiny-vue-playground-notify'
1616
const LAYOUT = 'playground-layout'
1717
const LAYOUT_REVERSE = 'playground-layout-reverse'
@@ -83,7 +83,7 @@ const createImportMap = (version) => {
8383
'@opentiny/vue-renderless/': `${cdnHost}/@opentiny/vue-renderless${versionDelimiter}${version}/${fileDelimiter}`,
8484
'sortablejs': `${cdnHost}/sortablejs${versionDelimiter}1.15.0/${fileDelimiter}modular/sortable.esm.js`
8585
}
86-
if (['aurora', 'saas'].includes(tinyTheme)) {
86+
if (['aurora', 'saas', 'smb'].includes(tinyTheme)) {
8787
imports[`@opentiny/vue-design-${tinyTheme}`] =
8888
`${cdnHost}/@opentiny/vue-design-${tinyTheme}${versionDelimiter}${version}/${fileDelimiter}index.js`
8989
}
@@ -143,7 +143,7 @@ const state = reactive({
143143
144144
const designThemeMap = {
145145
aurora: 'tinyAuroraTheme',
146-
infinity: 'tinyInfinityTheme'
146+
old: 'tinyOldTheme'
147147
}
148148
149149
function setTinyDesign() {
@@ -154,16 +154,16 @@ function setTinyDesign() {
154154
useCode += 'app.provide("TinyMode", "mobile-first");\n'
155155
}
156156
157-
if (['aurora', 'saas'].includes(tinyTheme)) {
157+
if (['aurora', 'saas', 'smb'].includes(tinyTheme)) {
158158
importCode += `import designConfig from '@opentiny/vue-design-${tinyTheme}';
159159
import { design } from '@opentiny/vue-common';\n`
160160
useCode += 'app.provide(design.configKey, designConfig);\n'
161161
}
162162
163-
if (['aurora', 'infinity'].includes(tinyTheme)) {
163+
if (['aurora', 'old'].includes(tinyTheme)) {
164164
const designTheme = designThemeMap[tinyTheme]
165165
importCode += `import TinyThemeTool from '@opentiny/vue-theme/theme-tool';
166-
import { ${designTheme} } from '@opentiny/vue-theme/theme';\n`
166+
import ${designTheme} from '@opentiny/vue-theme/${tinyTheme}-theme-index.js';\n`
167167
useCode += `const theme = new TinyThemeTool(${designTheme});\n`
168168
}
169169

examples/sites/src/const.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { tinyOldTheme, tinyAuroraTheme } from '@opentiny/vue-theme/theme-tool'
2+
13
// localStorage中保存语言的key
24
export const LANG_KEY = '_lang'
35
// localStorage中保存语言的value
@@ -12,17 +14,17 @@ export const LANG_PATH_MAP = {
1214
export const CURRENT_THEME_KEY = 'tiny-current-theme'
1315

1416
// 主题
15-
export const DEFAULT_THEME = 'tiny-default-theme'
16-
export const AURORA_THEME = 'tiny-aurora-theme'
17-
export const SMB_THEME = 'tiny-smb-theme'
18-
export const INFINITY_THEME = 'tiny-infinity-theme'
17+
export const DEFAULT_THEME = 'os-theme'
18+
export const AURORA_THEME = 'aurora-theme'
19+
export const SMB_THEME = 'smb-theme'
20+
export const OLD_THEME = 'old-theme'
1921

20-
// 主题对应路由参数映射表
21-
export const THEME_ROUTE_MAP = {
22-
[DEFAULT_THEME]: 'os-theme',
23-
[AURORA_THEME]: 'aurora-theme',
24-
[SMB_THEME]: 'smb-theme',
25-
[INFINITY_THEME]: 'infinity-theme'
22+
// 主题工具导出主题变量和主题的映射关系
23+
export const themeToolValuesMap = {
24+
[DEFAULT_THEME]: '',
25+
[AURORA_THEME]: tinyAuroraTheme,
26+
[SMB_THEME]: '',
27+
[OLD_THEME]: tinyOldTheme
2628
}
2729

2830
/**

examples/sites/src/router.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRouter, createWebHistory } from 'vue-router'
22
import Layout from '@/views/layout/layout.vue'
3-
import { LANG_PATH_MAP, ZH_CN_LANG, THEME_ROUTE_MAP, DEFAULT_THEME } from './const'
3+
import { LANG_PATH_MAP, ZH_CN_LANG, DEFAULT_THEME } from './const'
44

55
const Components = () => import('@/views/components/components.vue')
66
const Docs = () => import('@/views/docs/docs.vue')
@@ -35,8 +35,7 @@ let routes = [
3535
path: '/:pathMatch(.*)*',
3636
redirect: () => {
3737
const langPath = LANG_PATH_MAP[ZH_CN_LANG]
38-
const theme = THEME_ROUTE_MAP[DEFAULT_THEME]
39-
return { path: `${context}${langPath}/${theme}/overview` }
38+
return { path: `${context}${langPath}/${DEFAULT_THEME}/overview` }
4039
}
4140
}
4241
]

examples/sites/src/tools/useTheme.js

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,44 @@ import designSaasConfig from '@opentiny/vue-design-saas'
44
import designSMBConfig from '@opentiny/vue-design-smb'
55
import { router } from '@/router'
66
import { appData } from './appData'
7-
import { THEME_ROUTE_MAP, CURRENT_THEME_KEY, DEFAULT_THEME, AURORA_THEME, SMB_THEME, INFINITY_THEME } from '../const'
7+
import { CURRENT_THEME_KEY, DEFAULT_THEME, AURORA_THEME, OLD_THEME, themeToolValuesMap } from '../const'
88
import glaciers from '@/assets/images/glaciers.png'
99
import glaciersIcon from '@/assets/images/glaciers-icon.png'
1010

11-
import infinitely from '@/assets/images/Infinitely.png'
12-
import infinitelyIcon from '@/assets/images/Infinitely-icon.png'
13-
1411
import oceanic from '@/assets/images/oceanic.png'
1512
import oceanicIcon from '@/assets/images/oceanic-icon.png'
1613

1714
import starrySky from '@/assets/images/starry-sky.png'
1815
import starrySkyIcon from '@/assets/images/starry-sky-icon.png'
19-
import TinyThemeTool, { tinyOldTheme, tinyAuroraTheme } from '@opentiny/vue-theme/theme-tool'
16+
import TinyThemeTool from '@opentiny/vue-theme/theme-tool'
2017

2118
const isEn = appData.lang === 'enUS'
2219

2320
const themeData = [
2421
{
2522
value: [DEFAULT_THEME],
26-
label: isEn ? 'Default Theme' : '冰川主题',
27-
tips: isEn ? 'Accurate, Efficient, Distinct' : '精准、高效、清晰',
28-
icon: glaciersIcon,
29-
bgImage: glaciers
30-
},
31-
{
32-
value: [SMB_THEME],
3323
label: isEn ? 'Star Theme' : '星空主题',
3424
tips: isEn ? 'Leading, Innovative, Reliable' : '领先、创新、信赖',
3525
icon: starrySkyIcon,
3626
bgImage: starrySky
3727
},
28+
{
29+
value: [OLD_THEME],
30+
label: isEn ? 'Default Theme' : '冰川主题',
31+
tips: isEn ? 'Accurate, Efficient, Distinct' : '精准、高效、清晰',
32+
icon: glaciersIcon,
33+
bgImage: glaciers
34+
},
3835
{
3936
value: [AURORA_THEME],
4037
label: isEn ? 'Ocean Theme' : '海洋主题',
4138
tips: isEn ? 'Simple, Agile, Delightful' : '简约、敏捷、愉悦',
4239
icon: oceanicIcon,
4340
bgImage: oceanic
44-
},
45-
{
46-
value: [INFINITY_THEME],
47-
label: isEn ? 'Infinity Theme' : '无限主题',
48-
tips: isEn ? 'Creative, Scientific, Efficient' : '创造、科学、高效',
49-
icon: infinitelyIcon,
50-
bgImage: infinitely
5141
}
5242
]
5343

54-
const designConfigMap = {
55-
[DEFAULT_THEME]: {},
56-
[INFINITY_THEME]: {},
57-
[AURORA_THEME]: {},
58-
[SMB_THEME]: {}
59-
}
60-
61-
const defaultThemeKey = DEFAULT_THEME
62-
const currentThemeKey = hooks.ref(defaultThemeKey)
44+
const currentThemeKey = hooks.ref(DEFAULT_THEME)
6345

6446
watch(
6547
() => currentThemeKey.value,
@@ -82,7 +64,7 @@ const designConfig = computed(() => {
8264
const changeTheme = (themeKey) => {
8365
router.push({
8466
params: {
85-
theme: THEME_ROUTE_MAP[themeKey]
67+
theme: themeKey
8668
},
8769
hash: router?.currentRoute.value.hash
8870
})
@@ -101,14 +83,10 @@ const watchRoute = () => {
10183
watch(
10284
() => router.currentRoute.value.params.theme,
10385
(val) => {
104-
if (!loadedTheme && val === 'old-theme') {
105-
const themeTool = new TinyThemeTool()
106-
themeTool.changeTheme(tinyOldTheme)
107-
loadedTheme = true
108-
}
109-
if (!loadedTheme && val === 'aurora-theme') {
86+
if (!loadedTheme && themeToolValuesMap[val]) {
87+
currentThemeKey.value = val
11088
const themeTool = new TinyThemeTool()
111-
themeTool.changeTheme(tinyAuroraTheme)
89+
themeTool.changeTheme(themeToolValuesMap[val])
11290
loadedTheme = true
11391
}
11492
}
@@ -122,6 +100,6 @@ export default function useTheme() {
122100
changeTheme,
123101
currentThemeKey,
124102
designConfig,
125-
defaultTheme: THEME_ROUTE_MAP[defaultThemeKey]
103+
defaultTheme: DEFAULT_THEME
126104
}
127105
}

examples/sites/src/views/components/demo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export default defineComponent({
190190
},
191191
openPlayground(demo, open = true) {
192192
const cmpId = router.currentRoute.value.params.cmpId
193-
const tinyTheme = templateModeState.isSaas ? 'saas' : currentThemeKey.value.split('-')[1]
193+
const tinyTheme = templateModeState.isSaas ? 'saas' : currentThemeKey.value.split('-')[0]
194194
const openModeQuery = open ? '' : '&openMode=preview'
195195
// TODO: 目前mf只有Options写法,后续再放开compositon
196196
const url = `${import.meta.env.VITE_PLAYGROUND_URL}?cmpId=${cmpId}&fileName=${demo.codeFiles[0]}&apiMode=${

0 commit comments

Comments
 (0)