搜索菜单不区分大小写,同时支持外部连接打开
parent
3e01894db5
commit
b4539da84c
|
@ -12,6 +12,7 @@ export interface SearchResult {
|
||||||
name: string;
|
name: string;
|
||||||
path: string;
|
path: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
|
internalOrExternal: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate special characters
|
// Translate special characters
|
||||||
|
@ -23,7 +24,7 @@ function transform(c: string) {
|
||||||
function createSearchReg(key: string) {
|
function createSearchReg(key: string) {
|
||||||
const keys = [...key].map((item) => transform(item));
|
const keys = [...key].map((item) => transform(item));
|
||||||
const str = ['', ...keys, ''].join('.*');
|
const str = ['', ...keys, ''].join('.*');
|
||||||
return new RegExp(str);
|
return new RegExp(str, 'i');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useMenuSearch(refs: Ref<HTMLElement[]>, scrollWrap: Ref<ElRef>, emit: EmitType) {
|
export function useMenuSearch(refs: Ref<HTMLElement[]>, scrollWrap: Ref<ElRef>, emit: EmitType) {
|
||||||
|
@ -68,12 +69,13 @@ export function useMenuSearch(refs: Ref<HTMLElement[]>, scrollWrap: Ref<ElRef>,
|
||||||
function handlerSearchResult(filterMenu: Menu[], reg: RegExp, parent?: Menu) {
|
function handlerSearchResult(filterMenu: Menu[], reg: RegExp, parent?: Menu) {
|
||||||
const ret: SearchResult[] = [];
|
const ret: SearchResult[] = [];
|
||||||
filterMenu.forEach((item) => {
|
filterMenu.forEach((item) => {
|
||||||
const { name, path, icon, children, hideMenu, meta } = item;
|
const { name, path, icon, children, hideMenu, meta, internalOrExternal } = item;
|
||||||
if (!hideMenu && reg.test(name) && (!children?.length || meta?.hideChildrenInMenu)) {
|
if (!hideMenu && reg.test(name) && (!children?.length || meta?.hideChildrenInMenu)) {
|
||||||
ret.push({
|
ret.push({
|
||||||
name: parent?.name ? `${parent.name} > ${name}` : name,
|
name: parent?.name ? `${parent.name} > ${name}` : name,
|
||||||
path,
|
path,
|
||||||
icon,
|
icon,
|
||||||
|
internalOrExternal
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!meta?.hideChildrenInMenu && Array.isArray(children) && children.length) {
|
if (!meta?.hideChildrenInMenu && Array.isArray(children) && children.length) {
|
||||||
|
@ -149,8 +151,15 @@ export function useMenuSearch(refs: Ref<HTMLElement[]>, scrollWrap: Ref<ElRef>,
|
||||||
const to = result[index];
|
const to = result[index];
|
||||||
handleClose();
|
handleClose();
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
|
// update-begin--author:liaozhiyang---date:20230803---for:【QQYUN-8369】搜索区分大小写,外部链接新页打开
|
||||||
|
if (to.internalOrExternal) {
|
||||||
|
window.open(to.path, '_blank');
|
||||||
|
} else {
|
||||||
go(to.path);
|
go(to.path);
|
||||||
}
|
}
|
||||||
|
// update-end--author:liaozhiyang---date:20230803---for:【QQYUN-8369】搜索区分大小写,外部链接新页打开
|
||||||
|
}
|
||||||
|
|
||||||
// close search modal
|
// close search modal
|
||||||
function handleClose() {
|
function handleClose() {
|
||||||
|
|
Loading…
Reference in New Issue