Demo:打开本地文件编辑的情况下不再将数据写入浏览器缓存

This commit is contained in:
街角小林
2024-07-29 17:00:39 +08:00
parent cf56b5db24
commit 4fb9bd5135
4 changed files with 20 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import exampleData from 'simple-mind-map/example/exampleData'
import { simpleDeepClone } from 'simple-mind-map/src/utils/index'
import Vue from 'vue'
import vuexStore from '@/store'
const SIMPLE_MIND_MAP_DATA = 'SIMPLE_MIND_MAP_DATA'
const SIMPLE_MIND_MAP_LANG = 'SIMPLE_MIND_MAP_LANG'
@@ -36,6 +37,9 @@ export const getData = () => {
mindMapData = window.takeOverAppMethods.getMindMapData()
return mindMapData
}
if (vuexStore.state.isHandleLocalFile) {
return Vue.prototype.getCurrentData()
}
let store = localStorage.getItem(SIMPLE_MIND_MAP_DATA)
if (store === null) {
return simpleDeepClone(exampleData)
@@ -68,6 +72,9 @@ export const storeData = data => {
return
}
Vue.prototype.$bus.$emit('write_local_file', originData)
if (vuexStore.state.isHandleLocalFile) {
return
}
let dataStr = JSON.stringify(originData)
localStorage.setItem(SIMPLE_MIND_MAP_DATA, dataStr)
} catch (error) {
@@ -98,6 +105,9 @@ export const storeConfig = config => {
return
}
Vue.prototype.$bus.$emit('write_local_file', originData)
if (vuexStore.state.isHandleLocalFile) {
return
}
let dataStr = JSON.stringify(originData)
localStorage.setItem(SIMPLE_MIND_MAP_DATA, dataStr)
} catch (error) {

View File

@@ -290,9 +290,9 @@ export default {
creatingTip: 'Creating file',
directory: 'Directory',
newFileTip:
'Please export the currently edited file before creating a new one, otherwise the content will be lost',
'Please export the currently edited file before creating a new one, Beware of content loss',
openFileTip:
'Please export the currently edited file before opening it, otherwise the content will be lost'
'Please export the currently edited file before opening it, Beware of content loss'
},
edit: {
newFeatureNoticeTitle: 'New feature reminder',

View File

@@ -285,8 +285,8 @@ export default {
defaultFileName: '思维导图',
creatingTip: '正在创建文件',
directory: '目录',
newFileTip: '新建文件前请先导出当前编辑的文件,否则内容丢失',
openFileTip: '打开文件前请先导出当前编辑的文件,否则内容会丢'
newFileTip: '新建文件前请先导出当前编辑的文件,谨防内容丢失',
openFileTip: '打开文件前请先导出当前编辑的文件,谨防内容丢失'
},
edit: {
newFeatureNoticeTitle: '新特性提醒',

View File

@@ -581,6 +581,12 @@ export default {
if (hasFileURL) {
this.$bus.$emit('handle_file_url')
}
// api/index.js文件使用
// 当正在编辑本地文件时通过该方法获取最新数据
Vue.prototype.getCurrentData = () => {
const fullData = this.mindMap.getData(true)
return { ...fullData, config: this.mindMapData.config }
}
// 协同测试
this.cooperateTest()
// 销毁