From 7f771a2103578009290d61e8b3d4b110e8cded32 Mon Sep 17 00:00:00 2001 From: marvzhang Date: Wed, 25 Dec 2019 20:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/File/FileList.vue | 95 ++++++++++++++++++++--- frontend/src/i18n/zh.js | 4 + frontend/src/store/modules/file.js | 25 +++++- 3 files changed, 110 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/File/FileList.vue b/frontend/src/components/File/FileList.vue index e874c446..2d2fc93c 100644 --- a/frontend/src/components/File/FileList.vue +++ b/frontend/src/components/File/FileList.vue @@ -7,15 +7,42 @@ {{$t('Back')}} - + + + {{$t('Cancel')}} + + + {{$t('Confirm')}} + + + + {{$t('Save')}} - - - - {{$t('New File')}} - + + +
+ + {{$t('File')}} + + + {{$t('Directory')}} + +
+ +
@@ -70,7 +97,10 @@ export default { return { code: 'var hello = \'world\'', isEdit: false, - showFile: false + showFile: false, + name: '', + isShowAdd: false, + isShowDelete: false } }, computed: { @@ -110,15 +140,46 @@ export default { this.$store.commit('file/SET_CURRENT_PATH', path) this.$store.dispatch('file/getFileList', { path: this.currentPath }) }, - onFileSave () { - this.$store.dispatch('file/saveFileContent', { path: this.currentPath }) - .then(() => { - this.$message.success(this.$t('Saved file successfully')) - }) + async onFileSave () { + await this.$store.dispatch('file/saveFileContent', { path: this.currentPath }) + this.$message.success(this.$t('Saved file successfully')) }, onBackFile () { this.showFile = false this.onBack() + }, + onHideAdd () { + this.name = '' + }, + async onAddFile () { + if (!this.name) { + this.$message.error(this.$t('Name cannot be empty')) + return + } + const path = this.currentPath + '/' + this.name + await this.$store.dispatch('file/addFile', { path }) + await this.$store.dispatch('file/getFileList', { path: this.currentPath }) + this.isShowAdd = false + + this.showFile = true + this.$store.commit('file/SET_FILE_CONTENT', '') + this.$store.commit('file/SET_CURRENT_PATH', path) + await this.$store.dispatch('file/getFileContent', { path }) + }, + async onAddDir () { + if (!this.name) { + this.$message.error(this.$t('Name cannot be empty')) + return + } + await this.$store.dispatch('file/addDir', { path: this.currentPath + '/' + this.name }) + await this.$store.dispatch('file/getFileList', { path: this.currentPath }) + this.isShowAdd = false + }, + async onFileDelete () { + await this.$store.dispatch('file/deleteFile', { path: this.currentPath }) + this.$message.success(this.$t('Deleted successfully')) + this.isShowDelete = false + this.onBackFile() } }, created () { @@ -236,4 +297,14 @@ export default { font-size: 14px; color: rgba(3, 47, 98, 1); } + + .add-type-list { + text-align: right; + margin-top: 10px; + } + + .add-type { + cursor: pointer; + font-weight: bolder; + } diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js index 81ede24d..f5ed1324 100644 --- a/frontend/src/i18n/zh.js +++ b/frontend/src/i18n/zh.js @@ -40,6 +40,7 @@ export default { // 操作 Add: '添加', + Create: '创建', Run: '运行', Deploy: '部署', Save: '保存', @@ -234,6 +235,9 @@ export default { // 文件 'Choose Folder': '选择文件', + 'File': '文件', + 'Folder': '文件夹', + 'Directory': '目录', // 导入 'Import Spider': '导入爬虫', diff --git a/frontend/src/store/modules/file.js b/frontend/src/store/modules/file.js index 66b84651..b5412c20 100644 --- a/frontend/src/store/modules/file.js +++ b/frontend/src/store/modules/file.js @@ -25,8 +25,9 @@ const actions = { const { path } = payload const spiderId = rootState.spider.spiderForm._id commit('SET_CURRENT_PATH', path) - request.get(`/spiders/${spiderId}/dir`, { path }) + return request.get(`/spiders/${spiderId}/dir`, { path }) .then(response => { + if (!response.data.data) response.data.data = [] commit( 'SET_FILE_LIST', response.data.data @@ -38,10 +39,30 @@ const actions = { getFileContent ({ commit, rootState }, payload) { const { path } = payload const spiderId = rootState.spider.spiderForm._id - request.get(`/spiders/${spiderId}/file`, { path }) + return request.get(`/spiders/${spiderId}/file`, { path }) .then(response => { commit('SET_FILE_CONTENT', response.data.data) }) + }, + saveFileContent ({ state, rootState }, payload) { + const { path } = payload + const spiderId = rootState.spider.spiderForm._id + return request.post(`/spiders/${spiderId}/file`, { path, content: state.fileContent }) + }, + addFile ({ rootState }, payload) { + const { path } = payload + const spiderId = rootState.spider.spiderForm._id + return request.put(`/spiders/${spiderId}/file`, { path }) + }, + addDir ({ rootState }, payload) { + const { path } = payload + const spiderId = rootState.spider.spiderForm._id + return request.put(`/spiders/${spiderId}/dir`, { path }) + }, + deleteFile ({ rootState }, payload) { + const { path } = payload + const spiderId = rootState.spider.spiderForm._id + return request.delete(`/spiders/${spiderId}/file`, { path }) } }