mirror of
https://github.com/purocean/yn.git
synced 2026-10-12 23:31:39 +08:00
增加打开上一次文件功能
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
"monaco-editor": "^0.13.1",
|
||||
"normalize.css": "^7.0.0",
|
||||
"vue": "^2.5.2",
|
||||
"vue-bus": "^1.1.0",
|
||||
"vue-router": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
|
||||
<script>
|
||||
import 'normalize.css/normalize.css'
|
||||
import Vue from 'vue'
|
||||
import VueBus from 'vue-bus'
|
||||
|
||||
Vue.use(VueBus)
|
||||
|
||||
export default {
|
||||
name: 'App'
|
||||
|
||||
@@ -68,6 +68,10 @@ export default {
|
||||
|
||||
this.keyBind()
|
||||
window.addEventListener('paste', this.paste)
|
||||
|
||||
setTimeout(() => {
|
||||
this.$emit('ready')
|
||||
}, 500)
|
||||
},
|
||||
keyBind () {
|
||||
const KM = window.monaco.KeyMod
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="tree-node">
|
||||
<details :open="item.name === '/'" v-if="item.type === 'dir'">
|
||||
<details ref="dir" :open="item.path === '/'" v-if="item.type === 'dir'">
|
||||
<summary
|
||||
:style="{background: selected ? '#eee' : 'none'}"
|
||||
@dblclick="createFile()"
|
||||
@@ -42,6 +42,14 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.$bus.on('editor-ready', () => {
|
||||
const filePath = this.getSelectedFilePath()
|
||||
if (this.item.type === 'dir' && filePath.startsWith(this.item.path)) {
|
||||
this.$refs.dir.open = true
|
||||
} else if (filePath === this.item.path) {
|
||||
this.select(this.item)
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
select (f) {
|
||||
@@ -53,6 +61,7 @@ export default {
|
||||
})
|
||||
|
||||
this.$emit('select', f)
|
||||
this.storeSelectedFilePath(f.path)
|
||||
} else {
|
||||
window.open(`api/attachment/${f.name}?path=${encodeURIComponent(f.path)}`)
|
||||
}
|
||||
@@ -97,6 +106,12 @@ export default {
|
||||
this.$emit('delete', this.item.path)
|
||||
})
|
||||
}
|
||||
},
|
||||
storeSelectedFilePath (path) {
|
||||
window.localStorage['selectedFile'] = path
|
||||
},
|
||||
getSelectedFilePath () {
|
||||
return window.localStorage['selectedFile'] || ''
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
ref="editor"
|
||||
class="editor"
|
||||
v-model="value"
|
||||
@ready="editorReady"
|
||||
@scroll-line="syncScrollView"
|
||||
@paste-img="pasteImg"
|
||||
@save="saveFile"></Editor>
|
||||
@@ -59,6 +60,9 @@ export default {
|
||||
this.clearTimer()
|
||||
},
|
||||
methods: {
|
||||
editorReady () {
|
||||
this.$bus.emit('editor-ready')
|
||||
},
|
||||
clearTimer () {
|
||||
if (this.timer) {
|
||||
window.clearTimeout(this.timer)
|
||||
@@ -86,6 +90,10 @@ export default {
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.value) {
|
||||
return
|
||||
}
|
||||
|
||||
const content = this.value
|
||||
this.lastSaveContent = content
|
||||
File.write(file.path, content, () => {
|
||||
|
||||
@@ -6162,6 +6162,10 @@ vm-browserify@0.0.4:
|
||||
dependencies:
|
||||
indexof "0.0.1"
|
||||
|
||||
vue-bus@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "http://registry.npm.taobao.org/vue-bus/download/vue-bus-1.1.0.tgz#803c53ced328a8ce01c95bfb72bf9d623d6df5a7"
|
||||
|
||||
vue-eslint-parser@^2.0.1:
|
||||
version "2.0.2"
|
||||
resolved "http://registry.npm.taobao.org/vue-eslint-parser/download/vue-eslint-parser-2.0.2.tgz#8d603545e9d7c134699075bd1772af1ffd86b744"
|
||||
|
||||
Reference in New Issue
Block a user