mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 23:16:18 +08:00
优化搜索功能
This commit is contained in:
parent
fee026d631
commit
b09ec5fa3d
@ -95,9 +95,8 @@
|
|||||||
:style="{
|
:style="{
|
||||||
fontSize: cardStyleVars.showBiggerTitle ? '1.25rem' : '1.1rem',
|
fontSize: cardStyleVars.showBiggerTitle ? '1.25rem' : '1.1rem',
|
||||||
}"
|
}"
|
||||||
>
|
v-html="commandInfo.features.explain"
|
||||||
{{ commandInfo.features.explain }}
|
/>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- 匹配模式 -->
|
<!-- 匹配模式 -->
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
:content-class="
|
:content-class="
|
||||||
tag === '搜索结果' ? 'text-blue-9 text-weight-bold' : ''
|
tag === '搜索结果' ? 'text-blue-9 text-weight-bold' : ''
|
||||||
"
|
"
|
||||||
v-show="!(tag === '搜索结果' && !commandSearchKeyword)"
|
v-show="!(tag === '搜索结果' && commandSearchKeyword?.length < 2)"
|
||||||
>
|
>
|
||||||
{{ tag }}
|
{{ tag }}
|
||||||
<q-tooltip v-if="tag === '未分类'">
|
<q-tooltip v-if="tag === '未分类'">
|
||||||
@ -104,7 +104,7 @@
|
|||||||
clearable
|
clearable
|
||||||
clear-icon="close"
|
clear-icon="close"
|
||||||
@update:model-value="updateSearch"
|
@update:model-value="updateSearch"
|
||||||
placeholder="搜索"
|
placeholder="搜索,支持拼音首字母"
|
||||||
>
|
>
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<q-icon name="search" />
|
<q-icon name="search" />
|
||||||
@ -236,15 +236,35 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
// 当前标签下的所有快捷命令
|
// 当前标签下的所有快捷命令
|
||||||
currentTagQuickCommands() {
|
currentTagQuickCommands() {
|
||||||
let commands = Object.values(this.allQuickCommands);
|
let commands = Object.values(
|
||||||
|
JSON.parse(JSON.stringify(this.allQuickCommands))
|
||||||
|
);
|
||||||
switch (this.currentTag) {
|
switch (this.currentTag) {
|
||||||
case "未分类":
|
case "未分类":
|
||||||
return commands.filter((cmd) => !cmd.tags || cmd.tags.length === 0);
|
return commands.filter((cmd) => !cmd.tags || cmd.tags.length === 0);
|
||||||
case "搜索结果":
|
case "搜索结果":
|
||||||
if (this.commandSearchKeyword)
|
if (this.commandSearchKeyword?.length < 2) return;
|
||||||
return commands.filter((cmd) =>
|
let searchResult = [];
|
||||||
cmd.features.explain.includes(this.commandSearchKeyword)
|
commands.forEach((cmd) => {
|
||||||
|
// 拼音搜索
|
||||||
|
let explain = cmd.features.explain;
|
||||||
|
let matchedWordPositions = window.pinYinMatch.match(
|
||||||
|
explain,
|
||||||
|
this.commandSearchKeyword
|
||||||
);
|
);
|
||||||
|
if (!matchedWordPositions) return;
|
||||||
|
let matchedWords = explain.slice(
|
||||||
|
matchedWordPositions[0],
|
||||||
|
matchedWordPositions[1] + 1
|
||||||
|
);
|
||||||
|
// 高亮
|
||||||
|
cmd.features.explain = explain.replace(
|
||||||
|
matchedWords,
|
||||||
|
`<strong style="color:#ed6237">${matchedWords}</strong>`
|
||||||
|
);
|
||||||
|
searchResult.push(cmd);
|
||||||
|
});
|
||||||
|
return searchResult;
|
||||||
default:
|
default:
|
||||||
return commands.filter((cmd) => cmd.tags?.includes(this.currentTag));
|
return commands.filter((cmd) => cmd.tags?.includes(this.currentTag));
|
||||||
}
|
}
|
||||||
@ -475,7 +495,7 @@ export default {
|
|||||||
updateSearch() {
|
updateSearch() {
|
||||||
// 记录当前标签页
|
// 记录当前标签页
|
||||||
if (this.currentTag !== "搜索结果") this.lastTag = this.currentTag;
|
if (this.currentTag !== "搜索结果") this.lastTag = this.currentTag;
|
||||||
if (this.commandSearchKeyword) {
|
if (this.commandSearchKeyword?.length > 1) {
|
||||||
// 搜索时跳转到搜索结果标签
|
// 搜索时跳转到搜索结果标签
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.currentTag = "搜索结果";
|
this.currentTag = "搜索结果";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user