From 95b7136f2d0b24f0259997fe46e74114f46cc90f Mon Sep 17 00:00:00 2001 From: jmal Date: Sun, 16 Feb 2020 17:06:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/upload-api.js | 16 +++++ src/icons/svg/file/pdf.svg | 1 - src/icons/svg/search.svg | 1 + src/views/home/index.vue | 141 ++++++++++++++++++++++++++++++------- 4 files changed, 132 insertions(+), 27 deletions(-) delete mode 100644 src/icons/svg/file/pdf.svg create mode 100644 src/icons/svg/search.svg diff --git a/src/api/upload-api.js b/src/api/upload-api.js index e8fb0f2..9191503 100644 --- a/src/api/upload-api.js +++ b/src/api/upload-api.js @@ -65,6 +65,22 @@ export default { method: 'get', params }) + }, + // 搜索文件🔍 + searchFile: function(params) { + return request({ + url: 'search-file', + method: 'get', + params + }) + }, + // 搜索文件🔍 + searchFileAndOpenDir: function(params) { + return request({ + url: 'search-file-open', + method: 'get', + params + }) } } diff --git a/src/icons/svg/file/pdf.svg b/src/icons/svg/file/pdf.svg deleted file mode 100644 index bd98515..0000000 --- a/src/icons/svg/file/pdf.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/icons/svg/search.svg b/src/icons/svg/search.svg new file mode 100644 index 0000000..df6d57c --- /dev/null +++ b/src/icons/svg/search.svg @@ -0,0 +1 @@ + diff --git a/src/views/home/index.vue b/src/views/home/index.vue index 50ef863..61e98f0 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -3,9 +3,9 @@ - + {{ item.folder }} - {{ item.folder }} + {{ item.folder }} +
+ + + + + +
@@ -73,7 +80,8 @@ - +
path: {{ path }}
+ v.index === index + 2), this.pathList.length - (index + 2)) - this.pathList.forEach((p, number) => { - if (number === 0) { - this.path = '' - } else if (number === this.pathList.length - 1) { - } else { - this.path += '/' + this.pathList[number].folder + if(item.search){ + if(item.searchKey){ + this.searchFileByKeyWord(item.searchKey) + } else if(item.fileId){ + this.searchFileAndOpenDir(item.fileId) } - }) - setPath(this.path, this.pathList) - this.getFileList() + this.pathList.splice(this.pathList.findIndex(v => v.index === index + 2), this.pathList.length - (index + 2)) + } else { + this.pathList.splice(this.pathList.findIndex(v => v.index === index + 2), this.pathList.length - (index + 2)) + this.pathList.forEach((p, number) => { + if (number === 0) { + this.path = '' + } else if (number === this.pathList.length - 1) { + } else { + this.path += '/' + this.pathList[number].folder + } + }) + setPath(this.path, this.pathList) + this.getFileList() + } }, newFolder() { - console.log(879) this.newFolderName = '新建文件夹' let append = 0 let filenameList = [] @@ -455,6 +473,56 @@ export default { }); } }, + searchFileByKeyWord(key) { + this.searchFile(key) + }, + searchFile(key) { + if(key){ + + this.pathList = [{ 'folder': '', index: 0 }] + const item1 = {} + item1['folder'] = '搜索: ' + '"'+ key +'"' + item1['search'] = true + item1['searchKey'] = key + item1['index'] = 1 + const item2 = {} + item2['folder'] = '+' + item2['index'] = 2 + this.pathList.push(item1) + this.pathList.push(item2) + + this.tableLoading = true + api.searchFile({ + userId: this.$store.state.user.userId, + keyword: key, + currentDirectory: getPath(), + pageIndex: 1, + pageSize: 30 + }).then(res => { + this.fileList = res.data + this.tableLoading = false + this.clientHeight = document.documentElement.clientHeight - 150 + this.listModeSearch = true + }).catch(e => {}) + }else{ + this.handleLink('',0) + } + }, + searchFileAndOpenDir(fileId) { + this.tableLoading = true + api.searchFileAndOpenDir({ + userId: this.$store.state.user.userId, + id: fileId, + currentDirectory: getPath(), + pageIndex: 1, + pageSize: 30 + }).then(res => { + this.fileList = res.data + this.tableLoading = false + this.clientHeight = document.documentElement.clientHeight - 150 + this.listModeSearch = true + }).catch(e => {}) + }, getFileList() { this.tableLoading = true api.fileList({ @@ -466,6 +534,7 @@ export default { this.fileList = res.data this.tableLoading = false this.clientHeight = document.documentElement.clientHeight - 150 + this.listModeSearch = false }).catch(e => {}) }, getSummaries(param) { @@ -895,21 +964,36 @@ export default { fileClick(row) { console.log(row) if (row.isFolder) { - // 打开文件 - this.path += '/' + row.name + // 打开文件夹 + if (this.listModeSearch) { - const item1 = {} - item1['folder'] = row.name - item1['index'] = this.pathList.length - 1 + const item1 = {} + item1['folder'] = row.name + item1['search'] = true + item1['fileId'] = row.id + item1['index'] = this.pathList.length - 1 + const item2 = {} + item2['folder'] = '+' + item2['index'] = this.pathList.length + this.pathList[this.pathList.length - 1] = item1 + this.pathList.push(item2) - const item2 = {} - item2['folder'] = '+' - item2['index'] = this.pathList.length - this.pathList[this.pathList.length - 1] = item1 - this.pathList.push(item2) - setPath(this.path, this.pathList) - this.getFileList() + this.searchFileAndOpenDir(row.id) + } else { + this.path += '/' + row.name + const item1 = {} + item1['folder'] = row.name + item1['index'] = this.pathList.length - 1 + const item2 = {} + item2['folder'] = '+' + item2['index'] = this.pathList.length + this.pathList[this.pathList.length - 1] = item1 + this.pathList.push(item2) + setPath(this.path, this.pathList) + this.getFileList() + } } else { + // 打开文件 const fileIds = [row.id] const url = process.env.VUE_APP_BASE_FILE_API + 'preview/' + row.name + '?jmal-token=' + this.$store.state.user.token + '&fileIds=' + fileIds window.open(url, '_blank') @@ -1104,5 +1188,10 @@ export default { position: fixed; } + .searchClass{ + float: right; + width: 30%; + } +