删除fuse选项maxPatternLength

This commit is contained in:
不做码农 2022-12-16 14:58:47 +08:00
parent 2d951c82f6
commit a3216b9050

View File

@ -1,5 +1,5 @@
<template> <template>
<div :class="{ 'show': show }" class="header-search"> <div :class="{ show: show }" class="header-search">
<svg-icon class-name="search-icon" name="search" @click.stop="click" /> <svg-icon class-name="search-icon" name="search" @click.stop="click" />
<el-select <el-select
ref="headerSearchSelectRef" ref="headerSearchSelectRef"
@ -10,8 +10,7 @@
remote remote
placeholder="Search" placeholder="Search"
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>
@ -23,32 +22,32 @@ import { getNormalPath } from '@/utils/ruoyi'
import { isHttp } from '@/utils/validate' import { isHttp } from '@/utils/validate'
import usePermissionStore from '@/store/modules/permission' import usePermissionStore from '@/store/modules/permission'
const search = ref(''); const search = ref('')
const options = ref([]); const options = ref([])
const searchPool = ref([]); const searchPool = ref([])
const show = ref(false); const show = ref(false)
const fuse = ref(undefined); const fuse = ref(undefined)
const headerSearchSelectRef = ref(null); const headerSearchSelectRef = ref(null)
const router = useRouter(); const router = useRouter()
const routes = computed(() => usePermissionStore().routes); const routes = computed(() => usePermissionStore().routes)
function click() { function click() {
show.value = !show.value show.value = !show.value
if (show.value) { if (show.value) {
headerSearchSelectRef.value && headerSearchSelectRef.value.focus() headerSearchSelectRef.value && headerSearchSelectRef.value.focus()
} }
}; }
function close() { function close() {
headerSearchSelectRef.value && headerSearchSelectRef.value.blur() headerSearchSelectRef.value && headerSearchSelectRef.value.blur()
options.value = [] options.value = []
show.value = false show.value = false
} }
function change(val) { function change(val) {
const path = val.path; const path = val.path
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 { } else {
router.push(path) router.push(path)
} }
@ -65,15 +64,17 @@ function initFuse(list) {
threshold: 0.4, threshold: 0.4,
location: 0, location: 0,
distance: 100, distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1, minMatchCharLength: 1,
keys: [{ keys: [
{
name: 'title', name: 'title',
weight: 0.7 weight: 0.7
}, { },
{
name: 'path', name: 'path',
weight: 0.3 weight: 0.3
}] }
]
}) })
} }
// Filter out the routes that can be displayed in the sidebar // Filter out the routes that can be displayed in the sidebar
@ -83,8 +84,10 @@ function generateRoutes(routes, basePath = '', prefixTitle = []) {
for (const r of routes) { for (const r of routes) {
// skip hidden router // skip hidden router
if (r.hidden) { continue } if (r.hidden) {
const p = r.path.length > 0 && r.path[0] === '/' ? r.path : '/' + r.path; continue
}
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]
@ -119,7 +122,7 @@ function querySearch(query) {
} }
onMounted(() => { onMounted(() => {
searchPool.value = generateRoutes(routes.value); searchPool.value = generateRoutes(routes.value)
}) })
watchEffect(() => { watchEffect(() => {
@ -139,7 +142,7 @@ watch(searchPool, (list) => {
}) })
</script> </script>
<style lang='scss' scoped> <style lang="scss" scoped>
.header-search { .header-search {
font-size: 0 !important; font-size: 0 !important;