diff --git a/frontend/src/components/File/FileList.vue b/frontend/src/components/File/FileList.vue
index f7ec8a21..eae2b4a0 100644
--- a/frontend/src/components/File/FileList.vue
+++ b/frontend/src/components/File/FileList.vue
@@ -9,9 +9,14 @@
@node-click="onFileClick"
>
-
- {{$t('Create')}}
+
+
+
+
+
+ {{$t('Create')}}
+
+
-
-
-
-
-
-
-
-
- this.isShowDelete = false">
- {{$t('Cancel')}}
-
-
- {{$t('Confirm')}}
-
-
- this.isShowDelete = true">
-
- {{$t('Remove')}}
+
+ {{$t('Please select a file on the left.')}}
+
+
+
+
+
+
+ this.isShowDelete = false">
+ {{$t('Cancel')}}
-
-
-
-
-
-
+
{{$t('Confirm')}}
-
-
-
-
- {{$t('Rename')}}
-
-
-
-
-
- {{$t('Save')}}
-
-
-
-
-
- {{$t('File')}}
-
-
- {{$t('Directory')}}
-
-
-
-
-
- {{$t('Create')}}
-
-
-
+
+
+
+ {{$t('Remove')}}
+
+
+
+
+
+
+
+ {{$t('Confirm')}}
+
+
+
+
+
+
+ {{$t('Rename')}}
+
+
+
+
+
+
+ {{$t('Save')}}
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
- {{$t('Please select a file on the left')}}
-
-
-
+
+
@@ -192,24 +176,11 @@ export default {
}
this.$st.sendEv('爬虫详情', '文件', '点击')
},
- onBack () {
- const sep = '/'
- let arr = this.currentPath.split(sep)
- arr.splice(arr.length - 1, 1)
- const path = arr.join(sep)
- this.$store.commit('file/SET_CURRENT_PATH', path)
- this.$store.dispatch('file/getFileList', { path: this.currentPath })
- this.$st.sendEv('爬虫详情', '文件', '回退')
- },
async onFileSave () {
await this.$store.dispatch('file/saveFileContent', { path: this.currentPath })
this.$message.success(this.$t('Saved file successfully'))
this.$st.sendEv('爬虫详情', '文件', '保存')
},
- onBackFile () {
- this.showFile = false
- this.onBack()
- },
onHideAdd () {
this.name = ''
},
@@ -240,27 +211,24 @@ export default {
this.$st.sendEv('爬虫详情', '文件', '添加')
},
async onFileDelete () {
- await this.$store.dispatch('file/deleteFile', { path: this.currentPath })
+ await this.$store.dispatch('file/deleteFile', { path: this.currentFilePath })
+ await this.$store.dispatch('spider/getFileTree')
this.$message.success(this.$t('Deleted successfully'))
this.isShowDelete = false
- this.onBackFile()
+ this.showFile = false
this.$st.sendEv('爬虫详情', '文件', '删除')
},
onOpenRename () {
- this.isShowRename = true
- const arr = this.currentPath.split('/')
+ const arr = this.currentFilePath.split('/')
this.name = arr[arr.length - 1]
},
async onRenameFile () {
- let newPath
- if (this.currentPath.split('/').length === 1) {
- newPath = this.name
- } else {
- const arr = this.currentPath.split('/')
- newPath = arr[0] + '/' + this.name
- }
- await this.$store.dispatch('file/renameFile', { path: this.currentPath, newPath })
- this.$store.commit('file/SET_CURRENT_PATH', newPath)
+ await this.$store.dispatch('file/renameFile', { path: this.currentFilePath, newPath: this.name })
+ await this.$store.dispatch('spider/getFileTree')
+ const arr = this.currentFilePath.split('/')
+ arr[arr.length - 1] = this.name
+ this.currentFilePath = arr.join('/')
+ this.$store.commit('file/SET_CURRENT_PATH', this.currentFilePath)
this.$message.success(this.$t('Renamed successfully'))
this.isShowRename = false
this.$st.sendEv('爬虫详情', '文件', '重命名')
@@ -310,18 +278,30 @@ export default {
return node.path === this.currentFilePath
},
onFileRightClick (ev, data) {
- console.log(data.path)
+ this.isShowCreatePopoverDict = {}
this.$set(this.isShowCreatePopoverDict, data.path, true)
+ },
+ onHideCreate (data) {
+ this.$set(this.isShowCreatePopoverDict, data.path, false)
}
},
async created () {
await this.getFileTree()
+ },
+ mounted () {
+ this.listener = document.querySelector('body').addEventListener('click', ev => {
+ this.isShowCreatePopoverDict = {}
+ })
+ },
+ destroyed () {
+ document.querySelector('body').removeEventListener('click', this.listener)
}
}
@@ -473,8 +456,8 @@ export default {
display: flex;
align-items: center;
height: 35px;
- margin: 0 0 0 15px;
- padding: 0;
+ padding: 0 0 0 15px;
+ margin: 0;
cursor: pointer;
}
diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js
index 136dbf3f..27f32d61 100644
--- a/frontend/src/i18n/zh.js
+++ b/frontend/src/i18n/zh.js
@@ -325,6 +325,7 @@ export default {
'The schedule has been added': '已添加定时任务',
'The schedule has been saved': '已保存定时任务',
'Email format invalid': '邮箱地址格式不正确',
+ 'Please select a file on the left.': '请在左侧选择一个文件.',
// 登录
'Sign in': '登录',
diff --git a/frontend/src/store/modules/file.js b/frontend/src/store/modules/file.js
index 33f089fe..abdf5638 100644
--- a/frontend/src/store/modules/file.js
+++ b/frontend/src/store/modules/file.js
@@ -38,7 +38,8 @@ const actions = {
},
getFileContent ({ commit, rootState }, payload) {
const { path } = payload
- return request.get(`/file`, { path })
+ const spiderId = rootState.spider.spiderForm._id
+ return request.get(`/spiders/${spiderId}/file`, { path })
.then(response => {
commit('SET_FILE_CONTENT', response.data.data)
})
diff --git a/frontend/src/store/modules/spider.js b/frontend/src/store/modules/spider.js
index ea913287..ac1fc81b 100644
--- a/frontend/src/store/modules/spider.js
+++ b/frontend/src/store/modules/spider.js
@@ -193,7 +193,7 @@ const actions = {
commit('schedule/SET_SCHEDULE_LIST', res.data.data, { root: true })
},
async getFileTree ({ state, commit }, payload) {
- const { id } = payload
+ const id = payload ? payload.id : state.spiderForm._id
const res = await request.get(`/spiders/${id}/file/tree`)
commit('SET_FILE_TREE', res.data.data)
}