From a4eab941885110b37022c79eba3f4f752461fba8 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期五, 24 一月 2025 11:17:48 +0800
Subject: [PATCH] fix 修复 选择用户列表数据未清除问题
---
src/layout/components/TopBar/search.vue | 190 +++++++++++++++++++++++-----------------------
1 files changed, 95 insertions(+), 95 deletions(-)
diff --git a/src/layout/components/TopBar/search.vue b/src/layout/components/TopBar/search.vue
index 9dee360..182e84a 100644
--- a/src/layout/components/TopBar/search.vue
+++ b/src/layout/components/TopBar/search.vue
@@ -3,12 +3,12 @@
<el-dialog v-model="state.isShowSearch" destroy-on-close :show-close="false">
<template #footer>
<el-autocomplete
+ ref="layoutMenuAutocompleteRef"
v-model="state.menuQuery"
:fetch-suggestions="menuSearch"
placeholder="鎼滅储"
- ref="layoutMenuAutocompleteRef"
- @select="onHandleSelect"
:fit-input-width="true"
+ @select="onHandleSelect"
>
<template #prefix>
<svg-icon class-name="search-icon" icon-class="search" />
@@ -29,130 +29,130 @@
import { getNormalPath } from '@/utils/ruoyi';
import { isHttp } from '@/utils/validate';
import usePermissionStore from '@/store/modules/permission';
-import { RouteOption } from 'vue-router';
+import { RouteRecordRaw } from 'vue-router';
type Router = Array<{
- path: string;
- icon: string;
- title: string[];
-}>
+ path: string;
+ icon: string;
+ title: string[];
+}>;
type SearchState<T = any> = {
- isShowSearch: boolean;
- menuQuery: string;
- menuList: T[];
+ isShowSearch: boolean;
+ menuQuery: string;
+ menuList: T[];
};
// 瀹氫箟鍙橀噺鍐呭
const layoutMenuAutocompleteRef = ref();
const router = useRouter();
const routes = computed(() => usePermissionStore().routes);
const state = reactive<SearchState>({
- isShowSearch: false,
- menuQuery: '',
- menuList: [],
+ isShowSearch: false,
+ menuQuery: '',
+ menuList: []
});
// 鎼滅储寮圭獥鎵撳紑
const openSearch = () => {
- state.menuQuery = '';
- state.isShowSearch = true;
- state.menuList = generateRoutes(routes.value);
- nextTick(() => {
- setTimeout(() => {
- layoutMenuAutocompleteRef.value.focus();
- });
- });
+ state.menuQuery = '';
+ state.isShowSearch = true;
+ state.menuList = generateRoutes(routes.value as any);
+ nextTick(() => {
+ setTimeout(() => {
+ layoutMenuAutocompleteRef.value.focus();
+ });
+ });
};
// 鎼滅储寮圭獥鍏抽棴
const closeSearch = () => {
- state.isShowSearch = false;
+ state.isShowSearch = false;
};
// 鑿滃崟鎼滅储鏁版嵁杩囨护
-const menuSearch = (queryString: string, cb: Function) => {
- let options = state.menuList.filter((item) => {
- return item.title.indexOf(queryString) > -1;
- });
- cb(options);
+const menuSearch = (queryString: string, cb: (options: any[]) => void) => {
+ let options = state.menuList.filter((item) => {
+ return item.title.indexOf(queryString) > -1;
+ });
+ cb(options);
};
// Filter out the routes that can be displayed in the sidebar
// And generate the internationalized title
-const generateRoutes = (routes: RouteOption[], basePath = '', prefixTitle: string[] = []) => {
- let res: Router = []
- routes.forEach(r => {
- // skip hidden router
- if (!r.hidden) {
- const p = r.path.length > 0 && r.path[0] === '/' ? r.path : '/' + r.path;
- const data: any = {
- path: !isHttp(r.path) ? getNormalPath(basePath + p) : r.path,
- icon: r.meta?.icon,
- title: [...prefixTitle]
- }
- if (r.meta && r.meta.title) {
- data.title = [...data.title, r.meta.title];
- if (r.redirect !== 'noRedirect') {
- // only push the routes with title
- // special case: need to exclude parent router without redirect
- res.push(data);
- }
- }
- // recursive child routes
- if (r.children) {
- const tempRoutes = generateRoutes(r.children, data.path, data.title);
- if (tempRoutes.length >= 1) {
- res = [...res, ...tempRoutes];
- }
- }
- }
- })
- res.forEach((item: any) => {
- if (item.title instanceof Array) {
- item.title = item.title.join('/');
- }
- });
- return res;
-}
+const generateRoutes = (routes: RouteRecordRaw[], basePath = '', prefixTitle: string[] = []) => {
+ let res: Router = [];
+ routes.forEach((r) => {
+ // skip hidden router
+ if (!r.hidden) {
+ const p = r.path.length > 0 && r.path[0] === '/' ? r.path : '/' + r.path;
+ const data: any = {
+ path: !isHttp(r.path) ? getNormalPath(basePath + p) : r.path,
+ icon: r.meta?.icon,
+ title: [...prefixTitle]
+ };
+ if (r.meta && r.meta.title) {
+ data.title = [...data.title, r.meta.title];
+ if (r.redirect !== 'noRedirect') {
+ // only push the routes with title
+ // special case: need to exclude parent router without redirect
+ res.push(data);
+ }
+ }
+ // recursive child routes
+ if (r.children) {
+ const tempRoutes = generateRoutes(r.children, data.path, data.title);
+ if (tempRoutes.length >= 1) {
+ res = [...res, ...tempRoutes];
+ }
+ }
+ }
+ });
+ res.forEach((item: any) => {
+ if (item.title instanceof Array) {
+ item.title = item.title.join('/');
+ }
+ });
+ return res;
+};
// 褰撳墠鑿滃崟閫変腑鏃�
const onHandleSelect = (val: any) => {
- const paths = val.path;
- if (isHttp(paths)) {
- // http(s):// 璺緞鏂扮獥鍙f墦寮�
- const pindex = paths.indexOf("http");
- window.open(paths.substring(pindex, paths.length), "_blank");
- } else {
- router.push(paths);
- }
- state.menuQuery = ''
- closeSearch();
-
+ const paths = val.path;
+ if (isHttp(paths)) {
+ // http(s):// 璺緞鏂扮獥鍙f墦寮�
+ const pindex = paths.indexOf('http');
+ window.open(paths.substring(pindex, paths.length), '_blank');
+ } else {
+ router.push(paths);
+ }
+ state.menuQuery = '';
+ closeSearch();
};
// 鏆撮湶鍙橀噺
defineExpose({
- openSearch
+ openSearch
});
</script>
<style scoped lang="scss">
.layout-search-dialog {
- position: relative;
- :deep(.el-dialog) {
- .el-dialog__header,
- .el-dialog__body {
- display: none;
- }
- .el-dialog__footer {
- width: 100%;
- position: absolute;
- left: 50%;
- transform: translateX(-50%);
- top: -53vh;
- }
- }
- :deep(.el-autocomplete) {
- width: 560px;
- position: absolute;
- top: 150px;
- left: 50%;
- transform: translateX(-50%);
- }
+ position: relative;
+ :deep(.el-dialog) {
+ padding: 0;
+ .el-dialog__header,
+ .el-dialog__body {
+ display: none;
+ }
+ .el-dialog__footer {
+ width: 100%;
+ position: absolute;
+ left: 50%;
+ transform: translateX(-50%);
+ top: -53vh;
+ }
+ }
+ :deep(.el-autocomplete) {
+ width: 560px;
+ position: absolute;
+ top: 150px;
+ left: 50%;
+ transform: translateX(-50%);
+ }
}
</style>
--
Gitblit v1.9.3