fix 修复 HeaderSearch组件跳转query参数丢失问题

This commit is contained in:
疯狂的狮子Li 2023-10-09 11:57:22 +08:00
parent 078bb50130
commit a2f13185e1

View File

@ -12,7 +12,8 @@
class="header-search-select" class="header-search-select"
@change="change" @change="change"
> >
<el-option v-for="option in options" :key="option.item.path" :value="option.item" :label="option.item.title.join(' > ')" /> <el-option v-for="option in options" :key="option.item.path" :value="option.item"
:label="option.item.title.join(' > ')"/>
</el-select> </el-select>
</div> </div>
</template> </template>
@ -51,13 +52,18 @@ const close = () => {
} }
const change = (val: any) => { const change = (val: any) => {
const path = val.path; const path = val.path;
const query = val.query;
if (isHttp(path)) { if (isHttp(path)) {
// http(s):// // http(s)://
const pindex = path.indexOf("http"); const pindex = path.indexOf("http");
window.open(path.substr(pindex, path.length), "_blank"); window.open(path.substr(pindex, path.length), "_blank");
} else {
if (query) {
router.push({ path: path, query: JSON.parse(query) });
} else { } else {
router.push(path) router.push(path)
} }
}
search.value = '' search.value = ''
options.value = [] options.value = []
nextTick(() => { nextTick(() => {
@ -82,7 +88,7 @@ const initFuse = (list: Router) => {
} }
// Filter out the routes that can be displayed in the sidebar // Filter out the routes that can be displayed in the sidebar
// And generate the internationalized title // And generate the internationalized title
const generateRoutes = (routes: RouteOption[], basePath = '', prefixTitle: string[] = []) => { const generateRoutes = (routes: RouteOption[], basePath = '', prefixTitle: string[] = [], query: any = {}) => {
let res: Router = [] let res: Router = []
routes.forEach(r => { routes.forEach(r => {
// skip hidden router // skip hidden router
@ -90,7 +96,8 @@ const generateRoutes = (routes: RouteOption[], basePath = '', prefixTitle: strin
const p = r.path.length > 0 && r.path[0] === '/' ? r.path : '/' + r.path; const p = r.path.length > 0 && r.path[0] === '/' ? r.path : '/' + r.path;
const data = { const data = {
path: !isHttp(r.path) ? getNormalPath(basePath + p) : r.path, path: !isHttp(r.path) ? getNormalPath(basePath + p) : r.path,
title: [...prefixTitle] title: [...prefixTitle],
query: ''
} }
if (r.meta && r.meta.title) { if (r.meta && r.meta.title) {
data.title = [...data.title, r.meta.title]; data.title = [...data.title, r.meta.title];
@ -100,9 +107,14 @@ const generateRoutes = (routes: RouteOption[], basePath = '', prefixTitle: strin
res.push(data); res.push(data);
} }
} }
if (r.query) {
data.query = r.query
}
// recursive child routes // recursive child routes
if (r.children) { if (r.children) {
const tempRoutes = generateRoutes(r.children, data.path, data.title); const tempRoutes = generateRoutes(r.children, data.path, data.title, data.query);
if (tempRoutes.length >= 1) { if (tempRoutes.length >= 1) {
res = [...res, ...tempRoutes]; res = [...res, ...tempRoutes];
} }