mirror of
https://github.com/rubickCenter/rubick
synced 2025-10-27 07:01:26 +08:00
✨ 优化拼音搜索 #174,#67,#114,#61,#16
This commit is contained in:
@@ -99,12 +99,12 @@ export default async (nativeImage: any) => {
|
||||
};
|
||||
|
||||
if (app._name && isZhRegex.test(app._name)) {
|
||||
const [, pinyinArr] = translate(app._name);
|
||||
const firstLatter = pinyinArr.map((py) => py[0]);
|
||||
// 拼音
|
||||
fileOptions.keyWords.push(pinyinArr.join(''));
|
||||
// 缩写
|
||||
fileOptions.keyWords.push(firstLatter.join(''));
|
||||
// const [, pinyinArr] = translate(app._name);
|
||||
// const firstLatter = pinyinArr.map((py) => py[0]);
|
||||
// // 拼音
|
||||
// fileOptions.keyWords.push(pinyinArr.join(''));
|
||||
// // 缩写
|
||||
// fileOptions.keyWords.push(firstLatter.join(''));
|
||||
// 中文
|
||||
fileOptions.keyWords.push(app._name);
|
||||
}
|
||||
|
||||
@@ -78,12 +78,12 @@ function fileDisplay(filePath) {
|
||||
keyWords.push(path.basename(appDetail.target, '.exe'));
|
||||
|
||||
if (isZhRegex.test(appName)) {
|
||||
const [, pinyinArr] = translate(appName);
|
||||
const zh_firstLatter = pinyinArr.map((py) => py[0]);
|
||||
// 拼音
|
||||
keyWords.push(pinyinArr.join(''));
|
||||
// const [, pinyinArr] = translate(appName);
|
||||
// const zh_firstLatter = pinyinArr.map((py) => py[0]);
|
||||
// // 拼音
|
||||
// keyWords.push(pinyinArr.join(''));
|
||||
// 缩写
|
||||
keyWords.push(zh_firstLatter.join(''));
|
||||
// keyWords.push(zh_firstLatter.join(''));
|
||||
} else {
|
||||
const firstLatter = appName
|
||||
.split(' ')
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
>
|
||||
<a-list-item-meta :description="renderDesc(item.desc)">
|
||||
<template #title>
|
||||
<span v-html="renderTitle(item.name)"></span>
|
||||
<span v-html="renderTitle(item.name, item.match)"></span>
|
||||
</template>
|
||||
<template #avatar>
|
||||
<a-avatar style="border-radius: 0" :src="item.icon" />
|
||||
@@ -66,15 +66,11 @@ const props = defineProps({
|
||||
clipboardFile: (() => [])(),
|
||||
});
|
||||
|
||||
const renderTitle = (title) => {
|
||||
const renderTitle = (title, match) => {
|
||||
if (typeof title !== 'string') return;
|
||||
if (!props.searchValue) return title;
|
||||
const result = title.toLowerCase().split(props.searchValue.toLowerCase());
|
||||
if (result && result.length > 1) {
|
||||
return `<div>${result[0]}<span style='color: var(--ant-error-color)'>${props.searchValue}</span>${result[1]}</div>`;
|
||||
} else {
|
||||
return `<div>${result[0]}</div>`;
|
||||
}
|
||||
if (!props.searchValue || !match) return title;
|
||||
const result = title.substring(match[0], match[1] + 1);
|
||||
return `<div>${title.substring(0, match[0])}<span style='color: var(--ant-error-color)'>${result}</span>${title.substring(match[1]+1, title.length)}</div>`;
|
||||
};
|
||||
|
||||
const renderDesc = (desc) => {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ref, watch } from 'vue';
|
||||
import throttle from 'lodash.throttle';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { getGlobal } from '@electron/remote';
|
||||
import PinyinMatch from 'pinyin-match';
|
||||
import pluginClickEvent from './pluginClickEvent';
|
||||
import useFocus from './clipboardWatch';
|
||||
|
||||
@@ -14,7 +15,7 @@ function formatReg(regStr) {
|
||||
function searchKeyValues(lists, value, strict = false) {
|
||||
return lists.filter((item) => {
|
||||
if (typeof item === 'string') {
|
||||
return item.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
||||
return !!PinyinMatch.match(item, value);
|
||||
}
|
||||
if (item.type === 'regex' && !strict) {
|
||||
return formatReg(item.match).test(value);
|
||||
@@ -59,6 +60,7 @@ const optionsManager = ({
|
||||
icon: plugin.logo,
|
||||
desc: fe.explain,
|
||||
type: plugin.pluginType,
|
||||
match: PinyinMatch.match(cmd.label || cmd, value),
|
||||
zIndex: cmd.label ? 0 : 1, // 排序权重
|
||||
click: () => {
|
||||
pluginClickEvent({
|
||||
@@ -93,13 +95,16 @@ const optionsManager = ({
|
||||
descMap.set(plugin, true);
|
||||
let has = false;
|
||||
plugin.keyWords.some((keyWord) => {
|
||||
const match = PinyinMatch.match(keyWord, value);
|
||||
if (
|
||||
keyWord
|
||||
.toLocaleUpperCase()
|
||||
.indexOf(value.toLocaleUpperCase()) >= 0
|
||||
// keyWord
|
||||
// .toLocaleUpperCase()
|
||||
// .indexOf(value.toLocaleUpperCase()) >= 0 ||
|
||||
match
|
||||
) {
|
||||
has = keyWord;
|
||||
plugin.name = keyWord;
|
||||
plugin.match = match;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user