新增禅模式

This commit is contained in:
wanglin2 2022-11-14 19:25:25 +08:00
parent 6f351d4cee
commit 1b2da4eb72
10 changed files with 172 additions and 27 deletions

View File

@ -4,6 +4,7 @@ import Vue from 'vue'
const SIMPLE_MIND_MAP_DATA = 'SIMPLE_MIND_MAP_DATA' const SIMPLE_MIND_MAP_DATA = 'SIMPLE_MIND_MAP_DATA'
const SIMPLE_MIND_MAP_LANG = 'SIMPLE_MIND_MAP_LANG' const SIMPLE_MIND_MAP_LANG = 'SIMPLE_MIND_MAP_LANG'
const SIMPLE_MIND_MAP_LOCAL_CONFIG = 'SIMPLE_MIND_MAP_LOCAL_CONFIG'
/** /**
* @Author: 王林 * @Author: 王林
@ -101,3 +102,27 @@ export const getLang = () => {
storeLang('zh') storeLang('zh')
return 'zh' return 'zh'
} }
/**
* javascript comment
* @Author: 王林25
* @Date: 2022-11-14 18:57:31
* @Desc: 存储本地配置
*/
export const storeLocalConfig = config => {
localStorage.setItem(SIMPLE_MIND_MAP_LOCAL_CONFIG, JSON.stringify(config))
}
/**
* javascript comment
* @Author: 王林25
* @Date: 2022-11-14 18:57:37
* @Desc: 获取本地配置
*/
export const getLocalConfig = () => {
let config = localStorage.getItem(SIMPLE_MIND_MAP_LOCAL_CONFIG)
if (config) {
return JSON.parse(config)
}
return null
}

View File

@ -43,7 +43,8 @@ export default {
level3: 'Level3', level3: 'Level3',
level4: 'Level4', level4: 'Level4',
level5: 'Level5', level5: 'Level5',
level6: 'Level6' level6: 'Level6',
zenMode: 'Zen mode'
}, },
count: { count: {
words: 'Words', words: 'Words',

View File

@ -43,7 +43,8 @@ export default {
level3: '三级主题', level3: '三级主题',
level4: '四级主题', level4: '四级主题',
level5: '五级主题', level5: '五级主题',
level6: '六级主题' level6: '六级主题',
zenMode: '禅模式'
}, },
count: { count: {
words: '字数', words: '字数',

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="container"> <div class="container">
<template v-if="show"> <template v-if="show">
<Toolbar></Toolbar> <Toolbar v-if="!isZenMode"></Toolbar>
<Edit></Edit> <Edit></Edit>
</template> </template>
</div> </div>
@ -10,7 +10,8 @@
<script> <script>
import Toolbar from './components/Toolbar' import Toolbar from './components/Toolbar'
import Edit from './components/Edit' import Edit from './components/Edit'
import { mapActions } from 'vuex' import { mapState, mapActions, mapMutations } from 'vuex'
import { getLocalConfig } from '@/api'
export default { export default {
name: 'Index', name: 'Index',
@ -23,7 +24,13 @@ export default {
show: false show: false
} }
}, },
computed: {
...mapState({
isZenMode: state => state.localConfig.isZenMode
})
},
async created() { async created() {
this.initLocalConfig()
const loading = this.$loading({ const loading = this.$loading({
lock: true, lock: true,
text: '正在加载,请稍后...' text: '正在加载,请稍后...'
@ -33,7 +40,23 @@ export default {
loading.close() loading.close()
}, },
methods: { methods: {
...mapActions(['getUserMindMapData']) ...mapActions(['getUserMindMapData']),
...mapMutations(['setLocalConfig']),
/**
* @Author: 王林25
* @Date: 2022-11-14 19:07:03
* @Desc: 初始化本地配置
*/
initLocalConfig() {
let config = getLocalConfig()
if (config) {
this.setLocalConfig({
...this.$store.state.localConfig,
...config
})
}
}
} }
} }
</script> </script>

View File

@ -89,11 +89,17 @@
{{ $t('contextmenu.arrangeLayout') }} {{ $t('contextmenu.arrangeLayout') }}
<span class="desc">Ctrl + L</span> <span class="desc">Ctrl + L</span>
</div> </div>
<div class="item" @click="exec('TOGGLE_ZEN_MODE')">
{{ $t('contextmenu.zenMode') }}
{{ isZenMode ? '√' : '' }}
</div>
</template> </template>
</div> </div>
</template> </template>
<script> <script>
import { mapState, mapMutations } from 'vuex'
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-06-24 22:53:10 * @Date: 2021-06-24 22:53:10
@ -120,6 +126,9 @@ export default {
} }
}, },
computed: { computed: {
...mapState({
isZenMode: state => state.localConfig.isZenMode
}),
expandList() { expandList() {
return [ return [
this.$t('contextmenu.level1'), this.$t('contextmenu.level1'),
@ -181,6 +190,8 @@ export default {
this.mindMap.keyCommand.removeShortcut('Control+x', this.cut) this.mindMap.keyCommand.removeShortcut('Control+x', this.cut)
}, },
methods: { methods: {
...mapMutations(['setLocalConfig']),
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-07-14 21:38:50 * @Date: 2021-07-14 21:38:50
@ -276,6 +287,11 @@ export default {
case 'RETURN_CENTER': case 'RETURN_CENTER':
this.mindMap.view.reset() this.mindMap.view.reset()
break break
case 'TOGGLE_ZEN_MODE':
this.setLocalConfig({
isZenMode: !this.isZenMode
})
break
default: default:
this.$bus.$emit('execCommand', key, ...args) this.$bus.$emit('execCommand', key, ...args)
break break

View File

@ -27,13 +27,23 @@ export default {
} }
}, },
created() { created() {
this.$bus.$on('data_change', data => { this.$bus.$on('data_change', this.onDataChange)
},
beforeDestroy() {
this.$bus.$off('data_change', this.onDataChange)
},
methods: {
/**
* @Author: 王林25
* @Date: 2022-11-14 19:20:20
* @Desc: 监听数据变化
*/
onDataChange(data) {
this.words = 0 this.words = 0
this.num = 0 this.num = 0
this.walk(data) this.walk(data)
}) },
},
methods: {
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-06-30 22:13:07 * @Date: 2021-06-30 22:13:07

View File

@ -1,11 +1,11 @@
<template> <template>
<div class="editContainer"> <div class="editContainer">
<div class="mindMapContainer" ref="mindMapContainer"></div> <div class="mindMapContainer" ref="mindMapContainer"></div>
<Count></Count> <Count v-if="!isZenMode"></Count>
<Navigator :mindMap="mindMap"></Navigator> <Navigator :mindMap="mindMap"></Navigator>
<NavigatorToolbar :mindMap="mindMap"></NavigatorToolbar> <NavigatorToolbar :mindMap="mindMap" v-if="!isZenMode"></NavigatorToolbar>
<Outline></Outline> <Outline></Outline>
<Style></Style> <Style v-if="!isZenMode"></Style>
<BaseStyle :data="mindMapData" :mindMap="mindMap"></BaseStyle> <BaseStyle :data="mindMapData" :mindMap="mindMap"></BaseStyle>
<Theme :mindMap="mindMap"></Theme> <Theme :mindMap="mindMap"></Theme>
<Structure :mindMap="mindMap"></Structure> <Structure :mindMap="mindMap"></Structure>
@ -31,6 +31,7 @@ import NodeNoteContentShow from './NodeNoteContentShow.vue'
import { getData, storeData, storeConfig } from '@/api' import { getData, storeData, storeConfig } from '@/api'
import Navigator from './Navigator.vue' import Navigator from './Navigator.vue'
import NodeImgPreview from './NodeImgPreview.vue' import NodeImgPreview from './NodeImgPreview.vue'
import { mapState } from 'vuex'
/** /**
* @Author: 王林 * @Author: 王林
@ -61,6 +62,11 @@ export default {
openTest: false openTest: false
} }
}, },
computed: {
...mapState({
isZenMode: state => state.localConfig.isZenMode
})
},
mounted() { mounted() {
this.getData() this.getData()
this.init() this.init()

View File

@ -440,7 +440,18 @@ export default {
} }
}, },
created() { created() {
this.$bus.$on('node_active', (...args) => { this.$bus.$on('node_active', this.onNodeActive)
},
beforeDestroy() {
this.$bus.$off('node_active', this.onNodeActive)
},
methods: {
/**
* @Author: 王林25
* @Date: 2022-11-14 19:16:21
* @Desc: 监听节点激活事件
*/
onNodeActive(...args) {
if (this.$refs.sidebar) this.$refs.sidebar.show = false if (this.$refs.sidebar) this.$refs.sidebar.show = false
this.$nextTick(() => { this.$nextTick(() => {
this.activeTab = 'normal' this.activeTab = 'normal'
@ -449,9 +460,8 @@ export default {
this.$refs.sidebar.show = this.activeNodes.length > 0 this.$refs.sidebar.show = this.activeNodes.length > 0
this.initNodeStyle() this.initNodeStyle()
}) })
}) },
},
methods: {
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2021-05-05 11:42:32 * @Date: 2021-05-05 11:42:32

View File

@ -236,24 +236,58 @@ export default {
} }
}, },
created() { created() {
this.$bus.$on('mode_change', mode => { this.$bus.$on('mode_change', this.onModeChange)
this.$bus.$on('node_active', this.onNodeActive)
this.$bus.$on('back_forward', this.onBackForward)
this.$bus.$on('write_local_file', this.onWriteLocalFile)
},
beforeDestroy() {
this.$bus.$off('mode_change', this.onModeChange)
this.$bus.$off('node_active', this.onNodeActive)
this.$bus.$off('back_forward', this.onBackForward)
this.$bus.$off('write_local_file', this.onWriteLocalFile)
},
methods: {
/**
* @Author: 王林25
* @Date: 2022-11-14 19:17:40
* @Desc: 监听模式切换
*/
onModeChange(mode) {
this.readonly = mode === 'readonly' this.readonly = mode === 'readonly'
}) },
this.$bus.$on('node_active', (...args) => {
/**
* @Author: 王林25
* @Date: 2022-11-14 19:18:06
* @Desc: 监听节点激活
*/
onNodeActive(...args) {
this.activeNodes = args[1] this.activeNodes = args[1]
}) },
this.$bus.$on('back_forward', (index, len) => {
/**
* @Author: 王林25
* @Date: 2022-11-14 19:18:31
* @Desc: 监听前进后退
*/
onBackForward(index, len) {
this.backEnd = index <= 0 this.backEnd = index <= 0
this.forwardEnd = index >= len - 1 this.forwardEnd = index >= len - 1
}) },
this.$bus.$on('write_local_file', content => {
/**
* @Author: 王林25
* @Date: 2022-11-14 19:19:14
* @Desc: 监听本地文件读写
*/
onWriteLocalFile(content) {
clearTimeout(this.timer) clearTimeout(this.timer)
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
this.writeLocalFile(content) this.writeLocalFile(content)
}, 1000) }, 1000)
}) },
},
methods: {
/** /**
* @Author: 王林 * @Author: 王林
* @Date: 2022-09-24 15:40:09 * @Date: 2022-09-24 15:40:09

View File

@ -1,13 +1,18 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import exampleData from 'simple-mind-map/example/exampleData' import exampleData from 'simple-mind-map/example/exampleData'
import { storeLocalConfig } from '@/api'
Vue.use(Vuex) Vue.use(Vuex)
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
mindMapData: null, // 思维导图数据 mindMapData: null, // 思维导图数据
isHandleLocalFile: false // 是否操作的是本地文件 isHandleLocalFile: false, // 是否操作的是本地文件
localConfig: {
// 本地配置
isZenMode: false // 是否是禅模式
}
}, },
mutations: { mutations: {
/** /**
@ -27,6 +32,20 @@ const store = new Vuex.Store({
*/ */
setIsHandleLocalFile(state, data) { setIsHandleLocalFile(state, data) {
state.isHandleLocalFile = data state.isHandleLocalFile = data
},
/**
* javascript comment
* @Author: 王林25
* @Date: 2022-11-14 18:42:47
* @Desc: 设置本地配置
*/
setLocalConfig(state, data) {
state.localConfig = {
...state.localConfig,
...data
}
storeLocalConfig(state.localConfig)
} }
}, },
actions: { actions: {