From 2ee249a07f87a5b5aab915c2e343ccb266160f5c Mon Sep 17 00:00:00 2001 From: Yang Date: Sat, 3 Feb 2018 20:37:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=88=A0=E9=99=A4=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/Tree.vue | 18 +++++++++++++++- frontend/src/components/TreeNode.vue | 10 ++++----- frontend/src/pages/Home.vue | 31 +++++++++++++++++++--------- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/frontend/src/components/Tree.vue b/frontend/src/components/Tree.vue index 5fcfa629..c6ad5bb4 100644 --- a/frontend/src/components/Tree.vue +++ b/frontend/src/components/Tree.vue @@ -1,6 +1,14 @@ @@ -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() } diff --git a/frontend/src/components/TreeNode.vue b/frontend/src/components/TreeNode.vue index 015b277c..7465d049 100644 --- a/frontend/src/components/TreeNode.vue +++ b/frontend/src/components/TreeNode.vue @@ -6,11 +6,12 @@ @dblclick="createFile()" @contextmenu.shift.prevent="deleteFile"> {{ item.name }} + :slected-file="slectedFile" + @select="select" + @change="p => $emit('change', p)" + @delete="p => $emit('delete', p)">
{ - this.$emit('change') + this.$emit('delete', this.item.path) }) } } @@ -81,7 +82,6 @@ export default { watch: { slectedFile () { this.selected = false - console.log('xxxxxxxxx') } } } diff --git a/frontend/src/pages/Home.vue b/frontend/src/pages/Home.vue index 5387d765..43c75c9c 100644 --- a/frontend/src/pages/Home.vue +++ b/frontend/src/pages/Home.vue @@ -2,7 +2,14 @@
-

{{ file.path }}-{{ status }}

+

+ + {{ file.path }}-{{ status }} + + + 未打开文件 + +

@@ -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('') + } } } }