调整删除逻辑

This commit is contained in:
Yang
2018-02-03 20:37:14 +08:00
parent 4c8cecd2f4
commit 2ee249a07f
3 changed files with 43 additions and 16 deletions
+17 -1
View File
@@ -1,6 +1,14 @@
<template>
<aside>
<TreeNode :slected-file="file" v-for="item in tree" :item = "item" :key="item.path" @change="change" @select="f => file = f"></TreeNode>
<TreeNode
v-for="item in tree"
:slected-file="file"
:item="item"
:key="item.path"
@change="change"
@select="f => file = f"
@delete="onDelete"
></TreeNode>
</aside>
</template>
@@ -26,6 +34,14 @@ export default {
this.tree = tree
})
},
onDelete (path) {
// 删除了正在编辑的文件或者其父目录
if (this.file.path.startsWith(path)) {
this.file = null
}
this.init()
},
change (path) {
this.init()
}
+5 -5
View File
@@ -6,11 +6,12 @@
@dblclick="createFile()"
@contextmenu.shift.prevent="deleteFile"> {{ item.name }} </summary>
<tree-node
@select="select"
@change="p => $emit('change', p)"
v-for="x in item.children"
:key="x.path" :item="x"
:slected-file="slectedFile"></tree-node>
:slected-file="slectedFile"
@select="select"
@change="p => $emit('change', p)"
@delete="p => $emit('delete', p)"></tree-node>
</details>
<div
v-else
@@ -73,7 +74,7 @@ export default {
deleteFile () {
if (window.confirm(`确定要删除 [${this.item.path}] 吗?`)) {
File.delete(this.item.path, () => {
this.$emit('change')
this.$emit('delete', this.item.path)
})
}
}
@@ -81,7 +82,6 @@ export default {
watch: {
slectedFile () {
this.selected = false
console.log('xxxxxxxxx')
}
}
}
+21 -10
View File
@@ -2,7 +2,14 @@
<div>
<header class="header">
<div>
<h4 style="padding: 2em;margin: 0"> {{ file.path }}-{{ status }} </h4>
<h4 style="padding: 2em;margin: 0">
<span v-if="file">
{{ file.path }}-{{ status }}
</span>
<span v-else>
未打开文件
</span>
</h4>
</div>
</header>
<div style="display: flex; just-content: ">
@@ -27,13 +34,13 @@ export default {
status: '请选择文件',
value: '',
lastSaveContent: '',
file: {name: '未选择文件'},
file: null,
timer: null
}
},
mounted () {
this.timer = window.setInterval(() => {
this.saveFile(this.file.path)
this.saveFile(this.file)
}, 5000)
},
beforeDestroy () {
@@ -42,8 +49,8 @@ export default {
}
},
methods: {
saveFile (path) {
if (!path) {
saveFile (file) {
if (!file) {
return
}
@@ -53,17 +60,21 @@ export default {
const content = this.value
this.lastSaveContent = content
File.write(path, content, () => {
File.write(file.path, content, () => {
this.status = '保存于:' + (new Date()).toLocaleString()
})
}
},
watch: {
file (f) {
File.read(f.path, data => {
this.$refs.editor.setValue(data)
this.status = '加载完毕'
})
if (f) {
File.read(f.path, data => {
this.$refs.editor.setValue(data)
this.status = '加载完毕'
})
} else {
this.$refs.editor.setValue('')
}
}
}
}