fix: 搜索状态下跳转路径失败的问题

This commit is contained in:
jmal 2024-05-20 18:38:06 +08:00
parent 805dbcd253
commit 133133b0d6

View File

@ -1331,6 +1331,18 @@ export default {
this.onCreateFilename = this.$route.query.highlight this.onCreateFilename = this.$route.query.highlight
this.clearOnCreateFilename() 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; let that = this;
window.onresize = function() { window.onresize = function() {
that.clientHeight = that.clientHeight =
@ -2276,27 +2288,24 @@ export default {
this.lastLink(); this.lastLink();
}, },
lastLink() { lastLink() {
this.handleLink( let keywordQuery = ''
this.pathList[this.pathList.length - 2], const searchPathIndex = this.pathList.findIndex(item => item.search)
this.pathList.length - 2 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 && item.search) {
if (item.searchKey) { if (item.searchKey) {
this.searchFileByKeyWord(item.searchKey); this.searchFileByKeyword(item.searchKey);
} else if (item.row) { } 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 { } else {
this.pathList.splice(
this.pathList.findIndex((v, i) => i === index + 1),
this.pathList.length - (index + 1)
);
this.pathList.forEach((p, number) => { this.pathList.forEach((p, number) => {
if (number === 0) { if (number === 0) {
this.path = ""; this.path = "";
@ -2306,18 +2315,22 @@ export default {
} }
this.path = this.path.replace(/\\/g, "/"); this.path = this.path.replace(/\\/g, "/");
}) })
let queryFolder = localStorage.getItem(this.path) let queryFolder = localStorage.getItem(this.path)
if (!unPushLink) { if (!unPushLink) {
const queryTagId = this.$route.query.tagId ? `&tagId=${this.$route.query.tagId}` : '' const queryTagId = this.$route.query.tagId ? `&tagId=${this.$route.query.tagId}` : ''
const basePath = this.getBasePath() const basePath = this.getBasePath()
const keyword = this.$route.query.keyword ? `&keyword=${this.$route.query.keyword}` : '' if (keywordQuery !=='&keyword=') {
if (!this.$route.query.path) { keywordQuery = this.$route.query.keyword ? `&keyword=${this.$route.query.keyword}` : ''
this.$router.push(`?vmode=${this.vmode}&path=${encodeURI(this.path)}${queryFolder ? '&folder='+queryFolder : ''}${queryTagId}${basePath}${keyword}`);
} else { } 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) { if (!unRefresh) {
this.pagination.pageIndex = 1; this.pagination.pageIndex = 1;
@ -2328,6 +2341,7 @@ export default {
getBasePath() { getBasePath() {
let basePath = this.$route.query.basePath ? `&basePath=${this.$route.query.basePath}` : '' let basePath = this.$route.query.basePath ? `&basePath=${this.$route.query.basePath}` : ''
if (!this.path || this.path.length < 2) { if (!this.path || this.path.length < 2) {
this.basePath = '/'
return '' return ''
} }
return basePath return basePath
@ -2495,15 +2509,13 @@ export default {
} }
} }
let suffix = newFileName.substring(newFileName.lastIndexOf(".") + 1); let suffix = newFileName.substring(newFileName.lastIndexOf(".") + 1);
api api.addFile({
.addFile({
fileName: encodeURI(newFileName), fileName: encodeURI(newFileName),
isFolder: false, isFolder: false,
folder: this.$route.query.folder, folder: this.$route.query.folder,
username: this.$store.state.user.name, username: this.$store.state.user.name,
parentPath: encodeURI(parentPath) parentPath: encodeURI(parentPath)
}) }).then(res => {
.then(res => {
this.createFileLoading = false; this.createFileLoading = false;
switch (suffix && !this.$route.query.folder) { switch (suffix && !this.$route.query.folder) {
case "txt": case "txt":
@ -2525,13 +2537,12 @@ export default {
setTimeout(function() { setTimeout(function() {
that.newCreateFileDialog = false; that.newCreateFileDialog = false;
}, 200) }, 200)
}) }).catch(() => {
.catch(() => {
this.createFileLoading = false; this.createFileLoading = false;
}); });
} }
}, },
searchFileByKeyWord(key) { searchFileByKeyword(key) {
this.searchFile(key); this.searchFile(key);
}, },
// 切换布局 // 切换布局
@ -2678,6 +2689,17 @@ export default {
storageType = 'File' 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}) this.$store.dispatch('updateMessage', {event: 'storageTypeChange', data: storageType})
}, },
// 设置挂载文件的用户名(文件的所有者) // 设置挂载文件的用户名(文件的所有者)
@ -2697,7 +2719,7 @@ export default {
if (this.onCreateFilename) { if (this.onCreateFilename) {
let index = this.fileList.findIndex(item => item.name === this.onCreateFilename); let index = this.fileList.findIndex(item => item.name === this.onCreateFilename);
if (index > -1) { if (index > -1) {
let row = this.fileList[index]; let row = this.fileList[index]
setTimeout(() => { setTimeout(() => {
this.$refs.fileListTable.clearSelection() this.$refs.fileListTable.clearSelection()
this.$refs.fileListTable.toggleRowSelection([{ row: row ,selected: true}]) this.$refs.fileListTable.toggleRowSelection([{ row: row ,selected: true}])
@ -2708,28 +2730,24 @@ export default {
searchFile(key, onLoad) { searchFile(key, onLoad) {
if (key) { if (key) {
this.beforeLoadData(onLoad); this.beforeLoadData(onLoad);
// this.pathList = [{ folder: "" }]; // this.pathList = [{ folder: "" }]
// 查找this.pathList中是否已经有搜索的路径 // 查找this.pathList中是否已经有搜索的路径
let isExist = false; const searchPathIndex = this.pathList.findIndex(item => item.search)
this.pathList.forEach(item => { if (searchPathIndex < 0) {
if (item.search) { const item1 = {}
// 修改搜索的路径 item1["folder"] = `搜索: ${key}`
item.folder = "搜索: " + '"' + key + '"'; item1["search"] = true
isExist = true; item1["searchKey"] = key
} this.pathList.push(item1)
});
if (!isExist) {
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 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 basePath = this.getBasePath()
const keyword = key ? `&keyword=${key}` : '' const keyword = key ? `&keyword=${key}` : ''
const path = this.path ? encodeURI(this.path) : "/"; console.log('this.path', this.path, this.$route.query.path)
this.$router.push(`?vmode=${this.vmode}&path=${path}${keyword}${queryTagId}${basePath}`); const path = this.path ? encodeURI(this.path.replace(this.basePath, '/')) : "/"
this.$router.push(`?vmode=${this.vmode}&path=${path}${keyword}${queryTagId}${basePath}${folder}`)
api.searchFile({ api.searchFile({
userId: this.$store.state.user.userId, userId: this.$store.state.user.userId,
username: this.$store.state.user.name, username: this.$store.state.user.name,
@ -2744,8 +2762,7 @@ export default {
pageIndex: this.pagination.pageIndex, pageIndex: this.pagination.pageIndex,
pageSize: this.pagination.pageSize, pageSize: this.pagination.pageSize,
showFolderSize: localStorage.getItem('showFolderSize') showFolderSize: localStorage.getItem('showFolderSize')
}) }).then(res => {
.then(res => {
this.loadData(res, onLoad); this.loadData(res, onLoad);
this.listModeSearch = true; this.listModeSearch = true;
this.listModeSearchOpenDir = false; this.listModeSearchOpenDir = false;
@ -2756,13 +2773,12 @@ export default {
} }
} }
}, },
searchFileAndOpenDir(row, onLoad) { searchFileAndOpenDir(fileId, onLoad) {
this.beforeLoadData(onLoad); this.beforeLoadData(onLoad);
api api.searchFileAndOpenDir({
.searchFileAndOpenDir({
userId: this.$store.state.user.userId, userId: this.$store.state.user.userId,
username: this.$store.getters.name, username: this.$store.getters.name,
id: row.id, id: fileId,
currentDirectory: this.getQueryPath(), currentDirectory: this.getQueryPath(),
pageIndex: this.pagination.pageIndex, pageIndex: this.pagination.pageIndex,
pageSize: this.pagination.pageSize, pageSize: this.pagination.pageSize,
@ -2772,15 +2788,12 @@ export default {
.then(res => { .then(res => {
this.loadData(res, onLoad); this.loadData(res, onLoad);
this.listModeSearch = true; this.listModeSearch = true;
this.listModeSearchOpenDir = row; this.listModeSearchOpenDir = fileId;
}); });
this.path = row.path + row.name;
this.path = this.path.replace(/\\/g, "/");
}, },
openDir(row, onLoad) { openDir(row, onLoad) {
this.beforeLoadData(onLoad); this.beforeLoadData(onLoad);
api api.searchFileAndOpenDir({
.searchFileAndOpenDir({
userId: this.$store.state.user.userId, userId: this.$store.state.user.userId,
username: this.$store.getters.name, username: this.$store.getters.name,
id: row.mountFileId || row.id, id: row.mountFileId || row.id,
@ -2789,25 +2802,28 @@ export default {
pageSize: this.pagination.pageSize, pageSize: this.pagination.pageSize,
folder: this.$route.query.folder, folder: this.$route.query.folder,
showFolderSize: localStorage.getItem('showFolderSize') showFolderSize: localStorage.getItem('showFolderSize')
}) }).then(res => {
.then(res => {
this.loadData(res, onLoad); this.loadData(res, onLoad);
}); });
this.path = row.path + row.name; this.path = row.path + row.name
this.path = this.path.replace(/\\/g, "/"); this.path = this.path.replace(/\\/g, '/')
}, },
getFileList(onLoad) { getFileList(onLoad) {
if (this.$route.query.keyword) { if (this.$route.query.keyword) {
if (this.$route.query.keyword !== "undefined") { 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 { } else {
this.searchFileName = "" this.searchFileName = ""
this.getFileListed = true this.getFileListed = true
this.beforeLoadData(onLoad) this.beforeLoadData(onLoad)
api api.fileList({
.fileList({
userId: this.$store.state.user.userId, userId: this.$store.state.user.userId,
username: this.$store.state.user.name, username: this.$store.state.user.name,
currentDirectory: this.getQueryPath(), currentDirectory: this.getQueryPath(),
@ -2830,8 +2846,7 @@ export default {
}, },
getFileListBySearchMode(onLoad) { getFileListBySearchMode(onLoad) {
this.beforeLoadData(onLoad); this.beforeLoadData(onLoad);
api api.fileList({
.fileList({
userId: this.$store.state.user.userId, userId: this.$store.state.user.userId,
username: this.$store.state.user.name, username: this.$store.state.user.name,
currentDirectory: this.getQueryPath(), currentDirectory: this.getQueryPath(),
@ -2839,8 +2854,7 @@ export default {
pageIndex: this.pagination.pageIndex, pageIndex: this.pagination.pageIndex,
pageSize: this.pagination.pageSize, pageSize: this.pagination.pageSize,
showFolderSize: localStorage.getItem('showFolderSize') showFolderSize: localStorage.getItem('showFolderSize')
}) }).then(res => {
.then(res => {
this.loadData(res, onLoad); this.loadData(res, onLoad);
}); });
}, },
@ -4073,32 +4087,45 @@ export default {
this.pathList.push(item); this.pathList.push(item);
this.pagination.pageIndex = 1; this.pagination.pageIndex = 1;
const folder = row.id ? `&folder=${row.id}` : '' const folder = row.id ? `&folder=${row.id}` : ''
this.$router.push(`?vmode=${this.vmode}${keyword}${folder}${queryTagId}${basePath}`); const path = this.$route.query.path ? `&path=${this.$route.query.path}` : ''
this.searchFileAndOpenDir(row); 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 { } else {
let notHomePage = this.$route.path.length > 1 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 this.basePath = row.path
} }
if (this.path) {
this.path += "/" + row.name; this.path += "/" + row.name;
} else { this.path = this.path.replace(/\\/g, '/')
this.path = this.basePath + row.name; this.path = this.path.replace(/\/\//g, '/')
}
// 去掉this.path开头的this.basePath // 去掉this.path开头的this.basePath
this.path = this.path.replace(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 }; const item = { folder: row.name, shareBase: row.shareBase };
this.pathList.push(item); this.pathList.push(item);
this.pagination.pageIndex = 1; this.pagination.pageIndex = 1;
const path = encodeURI(this.path);
if (this.$store.getters.userId !== row.userId) { if (this.$store.getters.userId !== row.userId) {
row.mountFileId = row.id row.mountFileId = row.id
} }
if (row.mountFileId) { if (row.mountFileId) {
localStorage.setItem(this.path, row.mountFileId) localStorage.setItem(this.path, row.mountFileId)
} }
const basePath = this.basePath.length > 1 ? '&basePath='+this.basePath : '' const basePath = this.basePath ? `&basePath=${this.basePath}` : ''
this.$router.push(`?vmode=${this.vmode}&path=${path}${row.mountFileId ? '&folder='+row.mountFileId : ''}${queryTagId}${basePath}${keyword}`); this.$router.push(`?vmode=${this.vmode}&path=${encodeURI(path)}${row.mountFileId ? '&folder='+row.mountFileId : ''}${queryTagId}${basePath}${keyword}`);
this.openDir(row); this.openDir(row);
} }
} else { } else {