Demo:切换主题时支持选择是否覆盖设置过的基础样式

This commit is contained in:
wanglin2 2023-07-26 09:17:48 +08:00
parent 5ff9137745
commit 7e1a43143d

View File

@ -42,7 +42,7 @@ export default {
}, },
data() { data() {
return { return {
themeList: [...themeList].reverse(),// ...customThemeList themeList: [...themeList].reverse(), // ...customThemeList
themeMap, themeMap,
theme: '' theme: ''
} }
@ -61,32 +61,48 @@ export default {
} }
} }
}, },
created () { created() {
this.theme = this.mindMap.getTheme() this.theme = this.mindMap.getTheme()
this.handleDark() this.handleDark()
}, },
methods: { methods: {
...mapMutations(['setIsDark']), ...mapMutations(['setIsDark']),
/**
* @Author: 王林
* @Date: 2021-06-24 23:04:38
* @Desc: 使用主题
*/
useTheme(theme) { useTheme(theme) {
this.theme = theme.value this.theme = theme.value
this.handleDark() this.handleDark()
const customThemeConfig = this.mindMap.getCustomThemeConfig()
const hasCustomThemeConfig = Object.keys(customThemeConfig).length > 0
if (hasCustomThemeConfig) {
this.$confirm('你当前自定义过基础样式,是否覆盖?', '提示', {
confirmButtonText: '覆盖',
cancelButtonText: '保留',
type: 'warning'
})
.then(() => {
this.mindMap.setThemeConfig({})
this.changeTheme(theme, {})
})
.catch(() => {
this.changeTheme(theme, customThemeConfig)
})
} else {
this.changeTheme(theme, customThemeConfig)
}
},
changeTheme(theme, config) {
this.mindMap.setTheme(theme.value) this.mindMap.setTheme(theme.value)
storeConfig({ storeConfig({
theme: { theme: {
template: theme.value, template: theme.value,
config: this.mindMap.getCustomThemeConfig() config
} }
}) })
}, },
handleDark() { handleDark() {
let target = themeList.find((item) => { let target = themeList.find(item => {
return item.value === this.theme return item.value === this.theme
}) })
this.setIsDark(target.dark) this.setIsDark(target.dark)