Demo:修改主题和暗色的关联逻辑

This commit is contained in:
街角小林 2024-02-26 16:50:00 +08:00
parent 9a8cd1dd24
commit cdc5c7aa81
25 changed files with 95 additions and 37 deletions

View File

@ -30,7 +30,7 @@ export default {
computed: { computed: {
...mapState({ ...mapState({
isZenMode: state => state.localConfig.isZenMode, isZenMode: state => state.localConfig.isZenMode,
isDark: state => state.isDark, isDark: state => state.localConfig.isDark,
activeSidebar: state => state.activeSidebar activeSidebar: state => state.activeSidebar
}) })
}, },

View File

@ -1004,7 +1004,11 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['activeSidebar', 'localConfig', 'isDark']), ...mapState({
activeSidebar: state => state.activeSidebar,
localConfig: state => state.localConfig,
isDark: state => state.localConfig.isDark
}),
lineStyleList() { lineStyleList() {
return lineStyleList[this.$i18n.locale] || lineStyleList.zh return lineStyleList[this.$i18n.locale] || lineStyleList.zh
}, },

View File

@ -45,7 +45,9 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark']), ...mapState({
isDark: state => state.localConfig.isDark
})
}, },
watch: { watch: {
color() { color() {

View File

@ -167,7 +167,7 @@ export default {
computed: { computed: {
...mapState({ ...mapState({
isZenMode: state => state.localConfig.isZenMode, isZenMode: state => state.localConfig.isZenMode,
isDark: state => state.isDark isDark: state => state.localConfig.isDark
}), }),
expandList() { expandList() {
return [ return [

View File

@ -36,7 +36,9 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark']), ...mapState({
isDark: state => state.localConfig.isDark
}),
}, },
created() { created() {
this.$bus.$on('data_change', this.onDataChange) this.$bus.$on('data_change', this.onDataChange)

View File

@ -113,7 +113,7 @@ export default {
computed: { computed: {
...mapState({ ...mapState({
openNodeRichText: state => state.localConfig.openNodeRichText, openNodeRichText: state => state.localConfig.openNodeRichText,
isDark: state => state.isDark isDark: state => state.localConfig.isDark
}), }),
downTypeList() { downTypeList() {

View File

@ -53,7 +53,11 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['activeSidebar', 'isDark', 'localConfig']) ...mapState({
activeSidebar: state => state.activeSidebar,
isDark: state => state.localConfig.isDark,
localConfig: state => state.localConfig
})
}, },
watch: { watch: {
activeSidebar(val) { activeSidebar(val) {

View File

@ -54,7 +54,9 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark']) ...mapState({
isDark: state => state.localConfig.isDark
})
}, },
mounted() { mounted() {
this.setSize() this.setSize()

View File

@ -132,13 +132,16 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark', 'isReadonly']) ...mapState({
isReadonly: state => state.isReadonly,
isDark: state => state.localConfig.isDark
})
}, },
created() { created() {
this.lang = getLang() this.lang = getLang()
}, },
methods: { methods: {
...mapMutations(['setIsDark', 'setIsReadonly']), ...mapMutations(['setLocalConfig', 'setIsReadonly']),
readonlyChange() { readonlyChange() {
this.setIsReadonly(!this.isReadonly) this.setIsReadonly(!this.isReadonly)
@ -161,7 +164,9 @@ export default {
}, },
toggleDark() { toggleDark() {
this.setIsDark(!this.isDark) this.setLocalConfig({
isDark: !this.isDark
})
}, },
handleCommand(command) { handleCommand(command) {

View File

@ -78,7 +78,10 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['activeSidebar', 'isDark']) ...mapState({
activeSidebar: state => state.activeSidebar,
isDark: state => state.localConfig.isDark
})
}, },
watch: { watch: {
activeSidebar(val) { activeSidebar(val) {

View File

@ -70,7 +70,10 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark', 'isReadonly']) ...mapState({
isReadonly: state => state.isReadonly,
isDark: state => state.localConfig.isDark
})
}, },
created() { created() {
window.addEventListener('keydown', this.onKeyDown) window.addEventListener('keydown', this.onKeyDown)

View File

@ -77,7 +77,11 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isOutlineEdit', 'isDark', 'isReadonly']) ...mapState({
isReadonly: state => state.isReadonly,
isDark: state => state.localConfig.isDark,
isOutlineEdit: state => state.isOutlineEdit
})
}, },
watch: { watch: {
isOutlineEdit(val) { isOutlineEdit(val) {

View File

@ -33,7 +33,11 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['activeSidebar', 'isOutlineEdit', 'isDark']) ...mapState({
isDark: state => state.localConfig.isDark,
isOutlineEdit: state => state.isOutlineEdit,
activeSidebar: state => state.activeSidebar
})
}, },
watch: { watch: {
activeSidebar(val) { activeSidebar(val) {

View File

@ -144,7 +144,9 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark']), ...mapState({
isDark: state => state.localConfig.isDark
}),
fontFamilyList() { fontFamilyList() {
return fontFamilyList[this.$i18n.locale] || fontFamilyList.zh return fontFamilyList[this.$i18n.locale] || fontFamilyList.zh

View File

@ -47,7 +47,9 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark']) ...mapState({
isDark: state => state.localConfig.isDark
})
}, },
mounted() { mounted() {
this.setScrollBarWrapSize() this.setScrollBarWrapSize()

View File

@ -78,7 +78,10 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark', 'isReadonly']) ...mapState({
isReadonly: state => state.isReadonly,
isDark: state => state.localConfig.isDark
})
}, },
watch: { watch: {
searchText() { searchText() {

View File

@ -38,7 +38,10 @@ export default {
return {} return {}
}, },
computed: { computed: {
...mapState(['activeSidebar', 'isDark']), ...mapState({
isDark: state => state.localConfig.isDark,
activeSidebar: state => state.activeSidebar
}),
shortcutKeyList() { shortcutKeyList() {
return shortcutKeyList[this.$i18n.locale] || shortcutKeyList.zh return shortcutKeyList[this.$i18n.locale] || shortcutKeyList.zh

View File

@ -39,7 +39,9 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark']) ...mapState({
isDark: state => state.localConfig.isDark
})
}, },
watch: { watch: {
show(val, oldVal) { show(val, oldVal) {

View File

@ -39,7 +39,10 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['activeSidebar', 'isDark']), ...mapState({
isDark: state => state.localConfig.isDark,
activeSidebar: state => state.activeSidebar
}),
triggerList() { triggerList() {
return sidebarTriggerList[this.$i18n.locale] || sidebarTriggerList.zh return sidebarTriggerList[this.$i18n.locale] || sidebarTriggerList.zh

View File

@ -47,7 +47,10 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['activeSidebar', 'isDark']) ...mapState({
isDark: state => state.localConfig.isDark,
activeSidebar: state => state.activeSidebar
})
}, },
watch: { watch: {
activeSidebar(val) { activeSidebar(val) {

View File

@ -507,7 +507,10 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['activeSidebar', 'isDark']), ...mapState({
isDark: state => state.localConfig.isDark,
activeSidebar: state => state.activeSidebar
}),
fontFamilyList() { fontFamilyList() {
return fontFamilyList[this.$i18n.locale] || fontFamilyList.zh return fontFamilyList[this.$i18n.locale] || fontFamilyList.zh

View File

@ -58,7 +58,10 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['activeSidebar', 'isDark']), ...mapState({
isDark: state => state.localConfig.isDark,
activeSidebar: state => state.activeSidebar
}),
currentList() { currentList() {
return this.groupList.find(item => { return this.groupList.find(item => {
@ -70,7 +73,6 @@ export default {
activeSidebar(val) { activeSidebar(val) {
if (val === 'theme') { if (val === 'theme') {
this.theme = this.mindMap.getTheme() this.theme = this.mindMap.getTheme()
this.handleDark()
this.$refs.sidebar.show = true this.$refs.sidebar.show = true
} else { } else {
this.$refs.sidebar.show = false this.$refs.sidebar.show = false
@ -80,14 +82,13 @@ export default {
created() { created() {
this.initGroup() this.initGroup()
this.theme = this.mindMap.getTheme() this.theme = this.mindMap.getTheme()
this.handleDark()
this.mindMap.on('view_theme_change', this.handleViewThemeChange) this.mindMap.on('view_theme_change', this.handleViewThemeChange)
}, },
beforeDestroy() { beforeDestroy() {
this.mindMap.off('view_theme_change', this.handleViewThemeChange) this.mindMap.off('view_theme_change', this.handleViewThemeChange)
}, },
methods: { methods: {
...mapMutations(['setIsDark']), ...mapMutations(['setLocalConfig']),
handleViewThemeChange() { handleViewThemeChange() {
this.theme = this.mindMap.getTheme() this.theme = this.mindMap.getTheme()
@ -180,7 +181,9 @@ export default {
let target = this.themeList.find(item => { let target = this.themeList.find(item => {
return item.value === this.theme return item.value === this.theme
}) })
this.setIsDark(target.dark) this.setLocalConfig({
isDark: target.dark
})
} }
} }
} }

View File

@ -116,7 +116,10 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isHandleLocalFile', 'isDark']) ...mapState({
isDark: state => state.localConfig.isDark,
isHandleLocalFile: state => state.isHandleLocalFile
})
}, },
watch: { watch: {
isHandleLocalFile(val) { isHandleLocalFile(val) {

View File

@ -188,7 +188,9 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['isDark']), ...mapState({
isDark: state => state.localConfig.isDark
}),
hasRoot() { hasRoot() {
return ( return (
this.activeNodes.findIndex(node => { this.activeNodes.findIndex(node => {

View File

@ -19,10 +19,11 @@ const store = new Vuex.Store({
// 是否显示滚动条 // 是否显示滚动条
isShowScrollbar: false, isShowScrollbar: false,
// 是否开启手绘风格 // 是否开启手绘风格
isUseHandDrawnLikeStyle: false isUseHandDrawnLikeStyle: false,
// 是否是暗黑模式
isDark: false,
}, },
activeSidebar: '', // 当前显示的侧边栏 activeSidebar: '', // 当前显示的侧边栏
isDark: false, // 是否是暗黑模式
isOutlineEdit: false, // 是否是大纲编辑模式 isOutlineEdit: false, // 是否是大纲编辑模式
isReadonly: false // 是否只读 isReadonly: false // 是否只读
}, },
@ -51,11 +52,6 @@ const store = new Vuex.Store({
state.activeSidebar = data state.activeSidebar = data
}, },
// 设置暗黑模式
setIsDark(state, data) {
state.isDark = data
},
// 设置大纲编辑模式 // 设置大纲编辑模式
setIsOutlineEdit(state, data) { setIsOutlineEdit(state, data) {
state.isOutlineEdit = data state.isOutlineEdit = data