From 133133b0d6a6fbf32c72b8644bed0ae1c2de1649 Mon Sep 17 00:00:00 2001 From: jmal Date: Mon, 20 May 2024 18:38:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=90=9C=E7=B4=A2=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8B=E8=B7=B3=E8=BD=AC=E8=B7=AF=E5=BE=84=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ShowFile/ShowFile.vue | 185 +++++++++++++++------------ 1 file changed, 106 insertions(+), 79 deletions(-) diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index cf84b92..a0524c0 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -1331,6 +1331,18 @@ export default { this.onCreateFilename = this.$route.query.highlight this.clearOnCreateFilename() } + // remove query.basePath + if (this.$route.query.basePath) { + this.basePath = this.$route.query.basePath + } + + // remove query.folder + if (this.$route.query.folder && this.$route.query.keyword) { + const query = { ...this.$route.query }; + delete query.folder; + this.$router.replace({ query }); + } + let that = this; window.onresize = function() { that.clientHeight = @@ -2276,27 +2288,24 @@ export default { this.lastLink(); }, lastLink() { - this.handleLink( - this.pathList[this.pathList.length - 2], - this.pathList.length - 2 - ) + let keywordQuery = '' + const searchPathIndex = this.pathList.findIndex(item => item.search) + if (searchPathIndex === this.pathList.length - 1) { + keywordQuery = '&keyword=' + } + this.handleLink(this.pathList[this.pathList.length - 2],this.pathList.length - 2, undefined, undefined, keywordQuery) }, - handleLink(item, index, unPushLink, unRefresh) { + handleLink(item, index, unPushLink, unRefresh, keywordQuery) { + console.log('handleLink item', item) + console.log('handleLink: this.pathList', this.pathList) + this.pathList.splice(this.pathList.findIndex((v, i) => i === index + 1),this.pathList.length - (index + 1)) if (item && item.search) { if (item.searchKey) { - this.searchFileByKeyWord(item.searchKey); + this.searchFileByKeyword(item.searchKey); } else if (item.row) { - this.searchFileAndOpenDir(item.row); + this.searchFileAndOpenDir(item.row.id); } - this.pathList.splice( - this.pathList.findIndex((v, i) => i === index + 1), - this.pathList.length - (index + 1) - ); } else { - this.pathList.splice( - this.pathList.findIndex((v, i) => i === index + 1), - this.pathList.length - (index + 1) - ); this.pathList.forEach((p, number) => { if (number === 0) { this.path = ""; @@ -2306,18 +2315,22 @@ export default { } this.path = this.path.replace(/\\/g, "/"); }) - let queryFolder = localStorage.getItem(this.path) if (!unPushLink) { const queryTagId = this.$route.query.tagId ? `&tagId=${this.$route.query.tagId}` : '' const basePath = this.getBasePath() - const keyword = this.$route.query.keyword ? `&keyword=${this.$route.query.keyword}` : '' - if (!this.$route.query.path) { - this.$router.push(`?vmode=${this.vmode}&path=${encodeURI(this.path)}${queryFolder ? '&folder='+queryFolder : ''}${queryTagId}${basePath}${keyword}`); + if (keywordQuery !=='&keyword=') { + keywordQuery = this.$route.query.keyword ? `&keyword=${this.$route.query.keyword}` : '' } else { - this.$router.push(`?vmode=${this.vmode}&path=${encodeURI(this.path)}${queryFolder ? '&folder='+queryFolder : ''}${queryTagId}${basePath}${keyword}`); + keywordQuery = '' } + const searchPathIndex = this.pathList.findIndex(item => item.search) + if (searchPathIndex < 0) { + keywordQuery = '' + } + console.log('keywordQuery', keywordQuery) + this.$router.push(`?vmode=${this.vmode}&path=${encodeURI(this.path)}${queryFolder ? '&folder='+queryFolder : ''}${queryTagId}${basePath}${keywordQuery}`); } if (!unRefresh) { this.pagination.pageIndex = 1; @@ -2328,6 +2341,7 @@ export default { getBasePath() { let basePath = this.$route.query.basePath ? `&basePath=${this.$route.query.basePath}` : '' if (!this.path || this.path.length < 2) { + this.basePath = '/' return '' } return basePath @@ -2495,15 +2509,13 @@ export default { } } let suffix = newFileName.substring(newFileName.lastIndexOf(".") + 1); - api - .addFile({ + api.addFile({ fileName: encodeURI(newFileName), isFolder: false, folder: this.$route.query.folder, username: this.$store.state.user.name, parentPath: encodeURI(parentPath) - }) - .then(res => { + }).then(res => { this.createFileLoading = false; switch (suffix && !this.$route.query.folder) { case "txt": @@ -2525,13 +2537,12 @@ export default { setTimeout(function() { that.newCreateFileDialog = false; }, 200) - }) - .catch(() => { + }).catch(() => { this.createFileLoading = false; }); } }, - searchFileByKeyWord(key) { + searchFileByKeyword(key) { this.searchFile(key); }, // 切换布局 @@ -2678,6 +2689,17 @@ export default { storageType = 'File' } } + + console.log('loadData1: this.path', this.path) + + const path = this.$route.query.path ? this.$route.query.path : '/' + const basePath = this.$route.query.basePath ? this.$route.query.basePath : '/' + this.path = basePath + path + this.path = this.path.replace(/\\/g, '/') + this.path = this.path.replace(/\/\//g, '/') + + console.log('loadData2: this.path', this.path) + this.$store.dispatch('updateMessage', {event: 'storageTypeChange', data: storageType}) }, // 设置挂载文件的用户名(文件的所有者) @@ -2697,7 +2719,7 @@ export default { if (this.onCreateFilename) { let index = this.fileList.findIndex(item => item.name === this.onCreateFilename); if (index > -1) { - let row = this.fileList[index]; + let row = this.fileList[index] setTimeout(() => { this.$refs.fileListTable.clearSelection() this.$refs.fileListTable.toggleRowSelection([{ row: row ,selected: true}]) @@ -2708,28 +2730,24 @@ export default { searchFile(key, onLoad) { if (key) { this.beforeLoadData(onLoad); - // this.pathList = [{ folder: "" }]; + // this.pathList = [{ folder: "" }] // 查找this.pathList中是否已经有搜索的路径 - let isExist = false; - this.pathList.forEach(item => { - if (item.search) { - // 修改搜索的路径 - item.folder = "搜索: " + '"' + key + '"'; - isExist = true; - } - }); - if (!isExist) { - const item1 = {}; - item1["folder"] = "搜索: " + '"' + key + '"'; - item1["search"] = true; - item1["searchKey"] = key; - this.pathList.push(item1); + const searchPathIndex = this.pathList.findIndex(item => item.search) + if (searchPathIndex < 0) { + const item1 = {} + item1["folder"] = `搜索: ${key}` + item1["search"] = true + item1["searchKey"] = key + this.pathList.push(item1) } + console.log('searchFile: this.pathList', this.pathList) const queryTagId = this.$route.query.tagId ? `&tagId=${this.$route.query.tagId}` : '' + const folder = this.$route.query.folder ? `&folder=${this.$route.query.folder}` : '' const basePath = this.getBasePath() const keyword = key ? `&keyword=${key}` : '' - const path = this.path ? encodeURI(this.path) : "/"; - this.$router.push(`?vmode=${this.vmode}&path=${path}${keyword}${queryTagId}${basePath}`); + console.log('this.path', this.path, this.$route.query.path) + const path = this.path ? encodeURI(this.path.replace(this.basePath, '/')) : "/" + this.$router.push(`?vmode=${this.vmode}&path=${path}${keyword}${queryTagId}${basePath}${folder}`) api.searchFile({ userId: this.$store.state.user.userId, username: this.$store.state.user.name, @@ -2744,8 +2762,7 @@ export default { pageIndex: this.pagination.pageIndex, pageSize: this.pagination.pageSize, showFolderSize: localStorage.getItem('showFolderSize') - }) - .then(res => { + }).then(res => { this.loadData(res, onLoad); this.listModeSearch = true; this.listModeSearchOpenDir = false; @@ -2756,13 +2773,12 @@ export default { } } }, - searchFileAndOpenDir(row, onLoad) { + searchFileAndOpenDir(fileId, onLoad) { this.beforeLoadData(onLoad); - api - .searchFileAndOpenDir({ + api.searchFileAndOpenDir({ userId: this.$store.state.user.userId, username: this.$store.getters.name, - id: row.id, + id: fileId, currentDirectory: this.getQueryPath(), pageIndex: this.pagination.pageIndex, pageSize: this.pagination.pageSize, @@ -2772,15 +2788,12 @@ export default { .then(res => { this.loadData(res, onLoad); this.listModeSearch = true; - this.listModeSearchOpenDir = row; + this.listModeSearchOpenDir = fileId; }); - this.path = row.path + row.name; - this.path = this.path.replace(/\\/g, "/"); }, openDir(row, onLoad) { this.beforeLoadData(onLoad); - api - .searchFileAndOpenDir({ + api.searchFileAndOpenDir({ userId: this.$store.state.user.userId, username: this.$store.getters.name, id: row.mountFileId || row.id, @@ -2789,25 +2802,28 @@ export default { pageSize: this.pagination.pageSize, folder: this.$route.query.folder, showFolderSize: localStorage.getItem('showFolderSize') - }) - .then(res => { + }).then(res => { this.loadData(res, onLoad); }); - this.path = row.path + row.name; - this.path = this.path.replace(/\\/g, "/"); + this.path = row.path + row.name + this.path = this.path.replace(/\\/g, '/') }, getFileList(onLoad) { if (this.$route.query.keyword) { if (this.$route.query.keyword !== "undefined") { - this.searchFileName = this.$route.query.keyword; + this.searchFileName = this.$route.query.keyword + } + const searchPathIndex = this.pathList.findIndex(item => item.search) + if (this.$route.query.folder && searchPathIndex > -1) { + this.searchFileAndOpenDir(this.$route.query.folder, onLoad) + } else { + this.searchFile(this.searchFileName) } - this.searchFile(this.searchFileName) } else { this.searchFileName = "" this.getFileListed = true this.beforeLoadData(onLoad) - api - .fileList({ + api.fileList({ userId: this.$store.state.user.userId, username: this.$store.state.user.name, currentDirectory: this.getQueryPath(), @@ -2830,8 +2846,7 @@ export default { }, getFileListBySearchMode(onLoad) { this.beforeLoadData(onLoad); - api - .fileList({ + api.fileList({ userId: this.$store.state.user.userId, username: this.$store.state.user.name, currentDirectory: this.getQueryPath(), @@ -2839,8 +2854,7 @@ export default { pageIndex: this.pagination.pageIndex, pageSize: this.pagination.pageSize, showFolderSize: localStorage.getItem('showFolderSize') - }) - .then(res => { + }).then(res => { this.loadData(res, onLoad); }); }, @@ -4073,32 +4087,45 @@ export default { this.pathList.push(item); this.pagination.pageIndex = 1; const folder = row.id ? `&folder=${row.id}` : '' - this.$router.push(`?vmode=${this.vmode}${keyword}${folder}${queryTagId}${basePath}`); - this.searchFileAndOpenDir(row); + const path = this.$route.query.path ? `&path=${this.$route.query.path}` : '' + console.log('this.listModeSearch: this.path', this.path) + console.log('this.listModeSearch: this.pathList', this.pathList) + const basePath = this.getBasePath() + this.$router.push(`?vmode=${this.vmode}${path}${keyword}${folder}${queryTagId}${basePath}`); + this.searchFileAndOpenDir(row.id); } else { let notHomePage = this.$route.path.length > 1 - if (notHomePage && this.basePath.length === 1) { + console.log('notHomePage', notHomePage) + console.log('this.path', this.path) + console.log('row.path', row.path) + if (notHomePage && this.path + "/" !== row.path && this.basePath.length === 1) { this.basePath = row.path } - if (this.path) { - this.path += "/" + row.name; - } else { - this.path = this.basePath + row.name; - } + + this.path += "/" + row.name; + this.path = this.path.replace(/\\/g, '/') + this.path = this.path.replace(/\/\//g, '/') // 去掉this.path开头的this.basePath this.path = this.path.replace(this.basePath, '/') + const path = encodeURI(this.path); + + // if (this.path) { + // this.path += "/" + row.name; + // } else { + // this.path = this.basePath + row.name; + // } + // // 去掉this.path开头的this.basePath const item = { folder: row.name, shareBase: row.shareBase }; this.pathList.push(item); this.pagination.pageIndex = 1; - const path = encodeURI(this.path); if (this.$store.getters.userId !== row.userId) { row.mountFileId = row.id } if (row.mountFileId) { localStorage.setItem(this.path, row.mountFileId) } - const basePath = this.basePath.length > 1 ? '&basePath='+this.basePath : '' - this.$router.push(`?vmode=${this.vmode}&path=${path}${row.mountFileId ? '&folder='+row.mountFileId : ''}${queryTagId}${basePath}${keyword}`); + const basePath = this.basePath ? `&basePath=${this.basePath}` : '' + this.$router.push(`?vmode=${this.vmode}&path=${encodeURI(path)}${row.mountFileId ? '&folder='+row.mountFileId : ''}${queryTagId}${basePath}${keyword}`); this.openDir(row); } } else {