+
+
+
+ {{$t('File')}}
+
+
+ {{$t('Directory')}}
+
+
+
+
+
+ {{$t('Create')}}
+
+
+
@@ -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 })
}
}