搜索栏

This commit is contained in:
bb_pan 2026-01-26 14:57:27 +08:00
parent cc2cf5d9e3
commit d03570e30d
2 changed files with 78 additions and 42 deletions

View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1769408646770" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7350" id="mx_n_1769408646771" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M995.555556 950.044444l-335.644445-335.644444c56.888889-62.577778 85.333333-147.911111 85.333333-238.933333C750.933333 170.666667 585.955556 0 375.466667 0S0 170.666667 0 375.466667s170.666667 375.466667 375.466667 375.466666c91.022222 0 176.355556-34.133333 238.933333-85.333333l335.644444 335.644444c5.688889 5.688889 17.066667 11.377778 22.755556 11.377778 11.377778 0 17.066667 0 22.755556-11.377778 17.066667-17.066667 17.066667-39.822222 0-51.2zM68.266667 375.466667c0-170.666667 136.533333-307.2 307.2-307.2 170.666667 0 307.2 136.533333 307.2 307.2 0 170.666667-136.533333 307.2-307.2 307.2-164.977778 0-307.2-136.533333-307.2-307.2z" fill="#ffffff" p-id="7351"></path></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,22 +1,28 @@
<template> <template>
<div :class="{'show':show}" class="header-search"> <div :class="{ show: show }" class="header-search">
<!-- <svg-icon class-name="search-icon" icon-class="search" @click.stop="click" /> --> <div class="header-search-wrapper">
<el-select <svg-icon icon-class="search2" class="search-icon" />
ref="headerSearchSelect"
v-model="search" <el-select
:remote-method="querySearch" ref="headerSearchSelect"
filterable v-model="search"
default-first-option :remote-method="querySearch"
remote filterable
placeholder="全局搜索" default-first-option
class="header-search-select" remote
@change="change" placeholder="全局搜索"
> class="header-search-select"
<template #prefix> @change="change"
<img src="@/assets/images/search.png" style="width: 18px; height: 18px; margin-top: 17px" /> style="width: 150px"
</template> >
<el-option v-for="option in options" :key="option.item.path" :value="option.item" :label="option.item.title.join(' > ')" /> <el-option
</el-select> v-for="option in options"
:key="option.item.path"
:value="option.item"
:label="option.item.title.join(' > ')"
/>
</el-select>
</div>
</div> </div>
</template> </template>
@ -34,13 +40,13 @@ export default {
options: [], options: [],
searchPool: [], searchPool: [],
show: false, show: false,
fuse: undefined fuse: undefined,
} }
}, },
computed: { computed: {
routes() { routes() {
return this.$store.getters.permission_routes return this.$store.getters.permission_routes
} },
}, },
watch: { watch: {
routes() { routes() {
@ -55,7 +61,7 @@ export default {
} else { } else {
document.body.removeEventListener('click', this.close) document.body.removeEventListener('click', this.close)
} }
} },
}, },
mounted() { mounted() {
this.searchPool = this.generateRoutes(this.routes) this.searchPool = this.generateRoutes(this.routes)
@ -73,15 +79,15 @@ export default {
this.show = false this.show = false
}, },
change(val) { change(val) {
const path = val.path; const path = val.path
const query = val.query; const query = val.query
if(this.ishttp(val.path)) { if (this.ishttp(val.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 {
if (query) { if (query) {
this.$router.push({ path: path, query: JSON.parse(query) }); this.$router.push({ path: path, query: JSON.parse(query) })
} else { } else {
this.$router.push(path) this.$router.push(path)
} }
@ -99,13 +105,16 @@ export default {
location: 0, location: 0,
distance: 100, distance: 100,
minMatchCharLength: 1, minMatchCharLength: 1,
keys: [{ keys: [
name: 'title', {
weight: 0.7 name: 'title',
}, { weight: 0.7,
name: 'path', },
weight: 0.3 {
}] name: 'path',
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
@ -115,11 +124,13 @@ export default {
for (const router of routes) { for (const router of routes) {
// skip hidden router // skip hidden router
if (router.hidden) { continue } if (router.hidden) {
continue
}
const data = { const data = {
path: !this.ishttp(router.path) ? path.resolve(basePath, router.path) : router.path, path: !this.ishttp(router.path) ? path.resolve(basePath, router.path) : router.path,
title: [...prefixTitle] title: [...prefixTitle],
} }
if (router.meta && router.meta.title) { if (router.meta && router.meta.title) {
@ -155,8 +166,8 @@ export default {
}, },
ishttp(url) { ishttp(url) {
return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1 return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
} },
} },
} }
</script> </script>
@ -166,7 +177,7 @@ export default {
.search-icon { .search-icon {
cursor: pointer; cursor: pointer;
font-size: 18px; font-size: 14px;
vertical-align: middle; vertical-align: middle;
} }
@ -189,15 +200,19 @@ export default {
// border-bottom: 1px solid #d9d9d9; // border-bottom: 1px solid #d9d9d9;
// vertical-align: middle; // vertical-align: middle;
border: none; border: none;
background: rgba(255,255,255,0.2); background: rgba(255, 255, 255, 0.2);
border-radius: 4px 4px 4px 4px; border-radius: 4px 4px 4px 4px;
font-family: Microsoft YaHei, Microsoft YaHei; font-family: Microsoft YaHei, Microsoft YaHei;
font-weight: 400; font-weight: 400;
font-size: 12px; font-size: 14px;
color: #EBEBEB; color: #ebebeb;
text-align: left; text-align: left;
font-style: normal; font-style: normal;
text-transform: none; text-transform: none;
padding-left: 30px;
}
::v-deep .el-input__inner::placeholder {
color: #C9E7F7;
} }
} }
@ -208,4 +223,24 @@ export default {
} }
} }
} }
.header-search-wrapper {
position: relative;
display: inline-block;
}
/* 放大镜图标 */
.search-icon {
position: absolute;
left: 8px;
top: 46%;
transform: translateY(-50%);
z-index: 3;
pointer-events: none; /* 不挡点击 */
}
/* 给输入框让出图标位置 */
:deep(.header-search-select .el-input__inner) {
padding-left: 32px !important;
}
</style> </style>