mirror of
https://github.com/rubickCenter/rubick
synced 2025-08-09 05:09:34 +08:00
✨ 优化拼音搜索 #174,#67,#114,#61,#16
This commit is contained in:
parent
b06df01527
commit
96f53e3b40
@ -32,6 +32,7 @@
|
|||||||
"got": "^11.8.3",
|
"got": "^11.8.3",
|
||||||
"lodash.throttle": "^4.1.1",
|
"lodash.throttle": "^4.1.1",
|
||||||
"node-key-sender": "^1.0.11",
|
"node-key-sender": "^1.0.11",
|
||||||
|
"pinyin-match": "^1.2.4",
|
||||||
"pouchdb": "^7.2.2",
|
"pouchdb": "^7.2.2",
|
||||||
"simple-plist": "0.2.1",
|
"simple-plist": "0.2.1",
|
||||||
"vue": "^3.0.0",
|
"vue": "^3.0.0",
|
||||||
|
@ -99,12 +99,12 @@ export default async (nativeImage: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (app._name && isZhRegex.test(app._name)) {
|
if (app._name && isZhRegex.test(app._name)) {
|
||||||
const [, pinyinArr] = translate(app._name);
|
// const [, pinyinArr] = translate(app._name);
|
||||||
const firstLatter = pinyinArr.map((py) => py[0]);
|
// const firstLatter = pinyinArr.map((py) => py[0]);
|
||||||
// 拼音
|
// // 拼音
|
||||||
fileOptions.keyWords.push(pinyinArr.join(''));
|
// fileOptions.keyWords.push(pinyinArr.join(''));
|
||||||
// 缩写
|
// // 缩写
|
||||||
fileOptions.keyWords.push(firstLatter.join(''));
|
// fileOptions.keyWords.push(firstLatter.join(''));
|
||||||
// 中文
|
// 中文
|
||||||
fileOptions.keyWords.push(app._name);
|
fileOptions.keyWords.push(app._name);
|
||||||
}
|
}
|
||||||
|
@ -78,12 +78,12 @@ function fileDisplay(filePath) {
|
|||||||
keyWords.push(path.basename(appDetail.target, '.exe'));
|
keyWords.push(path.basename(appDetail.target, '.exe'));
|
||||||
|
|
||||||
if (isZhRegex.test(appName)) {
|
if (isZhRegex.test(appName)) {
|
||||||
const [, pinyinArr] = translate(appName);
|
// const [, pinyinArr] = translate(appName);
|
||||||
const zh_firstLatter = pinyinArr.map((py) => py[0]);
|
// const zh_firstLatter = pinyinArr.map((py) => py[0]);
|
||||||
// 拼音
|
// // 拼音
|
||||||
keyWords.push(pinyinArr.join(''));
|
// keyWords.push(pinyinArr.join(''));
|
||||||
// 缩写
|
// 缩写
|
||||||
keyWords.push(zh_firstLatter.join(''));
|
// keyWords.push(zh_firstLatter.join(''));
|
||||||
} else {
|
} else {
|
||||||
const firstLatter = appName
|
const firstLatter = appName
|
||||||
.split(' ')
|
.split(' ')
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
>
|
>
|
||||||
<a-list-item-meta :description="renderDesc(item.desc)">
|
<a-list-item-meta :description="renderDesc(item.desc)">
|
||||||
<template #title>
|
<template #title>
|
||||||
<span v-html="renderTitle(item.name)"></span>
|
<span v-html="renderTitle(item.name, item.match)"></span>
|
||||||
</template>
|
</template>
|
||||||
<template #avatar>
|
<template #avatar>
|
||||||
<a-avatar style="border-radius: 0" :src="item.icon" />
|
<a-avatar style="border-radius: 0" :src="item.icon" />
|
||||||
@ -66,15 +66,11 @@ const props = defineProps({
|
|||||||
clipboardFile: (() => [])(),
|
clipboardFile: (() => [])(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderTitle = (title) => {
|
const renderTitle = (title, match) => {
|
||||||
if (typeof title !== 'string') return;
|
if (typeof title !== 'string') return;
|
||||||
if (!props.searchValue) return title;
|
if (!props.searchValue || !match) return title;
|
||||||
const result = title.toLowerCase().split(props.searchValue.toLowerCase());
|
const result = title.substring(match[0], match[1] + 1);
|
||||||
if (result && result.length > 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>`;
|
||||||
return `<div>${result[0]}<span style='color: var(--ant-error-color)'>${props.searchValue}</span>${result[1]}</div>`;
|
|
||||||
} else {
|
|
||||||
return `<div>${result[0]}</div>`;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderDesc = (desc) => {
|
const renderDesc = (desc) => {
|
||||||
|
@ -2,6 +2,7 @@ import { ref, watch } from 'vue';
|
|||||||
import throttle from 'lodash.throttle';
|
import throttle from 'lodash.throttle';
|
||||||
import { ipcRenderer } from 'electron';
|
import { ipcRenderer } from 'electron';
|
||||||
import { getGlobal } from '@electron/remote';
|
import { getGlobal } from '@electron/remote';
|
||||||
|
import PinyinMatch from 'pinyin-match';
|
||||||
import pluginClickEvent from './pluginClickEvent';
|
import pluginClickEvent from './pluginClickEvent';
|
||||||
import useFocus from './clipboardWatch';
|
import useFocus from './clipboardWatch';
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ function formatReg(regStr) {
|
|||||||
function searchKeyValues(lists, value, strict = false) {
|
function searchKeyValues(lists, value, strict = false) {
|
||||||
return lists.filter((item) => {
|
return lists.filter((item) => {
|
||||||
if (typeof item === 'string') {
|
if (typeof item === 'string') {
|
||||||
return item.toLowerCase().indexOf(value.toLowerCase()) >= 0;
|
return !!PinyinMatch.match(item, value);
|
||||||
}
|
}
|
||||||
if (item.type === 'regex' && !strict) {
|
if (item.type === 'regex' && !strict) {
|
||||||
return formatReg(item.match).test(value);
|
return formatReg(item.match).test(value);
|
||||||
@ -59,6 +60,7 @@ const optionsManager = ({
|
|||||||
icon: plugin.logo,
|
icon: plugin.logo,
|
||||||
desc: fe.explain,
|
desc: fe.explain,
|
||||||
type: plugin.pluginType,
|
type: plugin.pluginType,
|
||||||
|
match: PinyinMatch.match(cmd.label || cmd, value),
|
||||||
zIndex: cmd.label ? 0 : 1, // 排序权重
|
zIndex: cmd.label ? 0 : 1, // 排序权重
|
||||||
click: () => {
|
click: () => {
|
||||||
pluginClickEvent({
|
pluginClickEvent({
|
||||||
@ -93,13 +95,16 @@ const optionsManager = ({
|
|||||||
descMap.set(plugin, true);
|
descMap.set(plugin, true);
|
||||||
let has = false;
|
let has = false;
|
||||||
plugin.keyWords.some((keyWord) => {
|
plugin.keyWords.some((keyWord) => {
|
||||||
|
const match = PinyinMatch.match(keyWord, value);
|
||||||
if (
|
if (
|
||||||
keyWord
|
// keyWord
|
||||||
.toLocaleUpperCase()
|
// .toLocaleUpperCase()
|
||||||
.indexOf(value.toLocaleUpperCase()) >= 0
|
// .indexOf(value.toLocaleUpperCase()) >= 0 ||
|
||||||
|
match
|
||||||
) {
|
) {
|
||||||
has = keyWord;
|
has = keyWord;
|
||||||
plugin.name = keyWord;
|
plugin.name = keyWord;
|
||||||
|
plugin.match = match;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
62
yarn.lock
62
yarn.lock
@ -2728,6 +2728,11 @@ balanced-match@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
|
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
|
||||||
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
|
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==
|
||||||
|
|
||||||
|
base64-js@1.1.2:
|
||||||
|
version "1.1.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.1.2.tgz#d6400cac1c4c660976d90d07a04351d89395f5e8"
|
||||||
|
integrity sha512-AIxxJSNK6fMJTnRuY14y/+86h+R4Ybztcchea+Al8aPIPFa6LvDSV90VN5EH81DVXQmh6YjIqpLyG/ljQDoqeQ==
|
||||||
|
|
||||||
base64-js@^1.0.2, base64-js@^1.3.1, base64-js@^1.5.1:
|
base64-js@^1.0.2, base64-js@^1.3.1, base64-js@^1.5.1:
|
||||||
version "1.5.1"
|
version "1.5.1"
|
||||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
|
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
|
||||||
@ -2768,6 +2773,11 @@ bfj@^6.1.1:
|
|||||||
hoopy "^0.1.4"
|
hoopy "^0.1.4"
|
||||||
tryer "^1.0.1"
|
tryer "^1.0.1"
|
||||||
|
|
||||||
|
big-integer@^1.6.7:
|
||||||
|
version "1.6.51"
|
||||||
|
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.51.tgz#0df92a5d9880560d3ff2d5fd20245c889d130686"
|
||||||
|
integrity sha512-GPEid2Y9QU1Exl1rpO9B2IPJGHPSupF5GnVIP0blYvNOMer2bTvSWs1jGOUg04hTmu67nmLsQ9TBo1puaotBHg==
|
||||||
|
|
||||||
big.js@^3.1.3:
|
big.js@^3.1.3:
|
||||||
version "3.2.0"
|
version "3.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e"
|
resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e"
|
||||||
@ -2871,6 +2881,20 @@ boxen@^5.0.0:
|
|||||||
widest-line "^3.1.0"
|
widest-line "^3.1.0"
|
||||||
wrap-ansi "^7.0.0"
|
wrap-ansi "^7.0.0"
|
||||||
|
|
||||||
|
bplist-creator@0.0.7:
|
||||||
|
version "0.0.7"
|
||||||
|
resolved "https://registry.yarnpkg.com/bplist-creator/-/bplist-creator-0.0.7.tgz#37df1536092824b87c42f957b01344117372ae45"
|
||||||
|
integrity sha512-xp/tcaV3T5PCiaY04mXga7o/TE+t95gqeLmADeBI1CvZtdWTbgBt3uLpvh4UWtenKeBhCV6oVxGk38yZr2uYEA==
|
||||||
|
dependencies:
|
||||||
|
stream-buffers "~2.2.0"
|
||||||
|
|
||||||
|
bplist-parser@0.1.1:
|
||||||
|
version "0.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/bplist-parser/-/bplist-parser-0.1.1.tgz#d60d5dcc20cba6dc7e1f299b35d3e1f95dafbae6"
|
||||||
|
integrity sha512-2AEM0FXy8ZxVLBuqX0hqt1gDwcnz2zygEkQ6zaD5Wko/sB9paUNwlpawrFtKeHUAQUOzjVy9AO4oeonqIHKA9Q==
|
||||||
|
dependencies:
|
||||||
|
big-integer "^1.6.7"
|
||||||
|
|
||||||
brace-expansion@^1.1.7:
|
brace-expansion@^1.1.7:
|
||||||
version "1.1.11"
|
version "1.1.11"
|
||||||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
|
||||||
@ -8684,6 +8708,11 @@ pinkie@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
|
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
|
||||||
integrity sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==
|
integrity sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==
|
||||||
|
|
||||||
|
pinyin-match@^1.2.4:
|
||||||
|
version "1.2.4"
|
||||||
|
resolved "https://registry.yarnpkg.com/pinyin-match/-/pinyin-match-1.2.4.tgz#94381bb6501cfd3c24f923fe36c81710d8c49bcc"
|
||||||
|
integrity sha512-HpUiaSxcG3rrpKAMZXq/rMHbEp7wvfu9B64lHJBy+63xAr/hVdBC8xqkWWPnNyjSb19ihdh8FnXo+9m6jAr9Mg==
|
||||||
|
|
||||||
pkg-dir@^1.0.0:
|
pkg-dir@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4"
|
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-1.0.0.tgz#7a4b508a8d5bb2d629d447056ff4e9c9314cf3d4"
|
||||||
@ -8705,6 +8734,15 @@ pkg-dir@^4.1.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
find-up "^4.0.0"
|
find-up "^4.0.0"
|
||||||
|
|
||||||
|
plist@2.0.1:
|
||||||
|
version "2.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/plist/-/plist-2.0.1.tgz#0a32ca9481b1c364e92e18dc55c876de9d01da8b"
|
||||||
|
integrity sha512-pLZ1xkqqdO0puqm8g9kHzGb9oPkW32RPprDsNtjyVJ1cAWdglIgq+k+kO3sFAm5fEGIW04B4oa27JsfzncnHkA==
|
||||||
|
dependencies:
|
||||||
|
base64-js "1.1.2"
|
||||||
|
xmlbuilder "8.2.2"
|
||||||
|
xmldom "0.1.x"
|
||||||
|
|
||||||
plist@^3.0.1, plist@^3.0.4:
|
plist@^3.0.1, plist@^3.0.4:
|
||||||
version "3.0.6"
|
version "3.0.6"
|
||||||
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.6.tgz#7cfb68a856a7834bca6dbfe3218eb9c7740145d3"
|
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.6.tgz#7cfb68a856a7834bca6dbfe3218eb9c7740145d3"
|
||||||
@ -10038,6 +10076,15 @@ signal-exit@^3.0.0, signal-exit@^3.0.2, signal-exit@^3.0.3:
|
|||||||
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
|
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
|
||||||
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
|
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==
|
||||||
|
|
||||||
|
simple-plist@0.2.1:
|
||||||
|
version "0.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/simple-plist/-/simple-plist-0.2.1.tgz#71766db352326928cf3a807242ba762322636723"
|
||||||
|
integrity sha512-1xgqR0IwahCZDfwUp36DmxKX0dwoh/KtnxbY8D5cs19BF5889ZlRSViTAknEWO39ND573T2NBBHqP7Qf6spPPQ==
|
||||||
|
dependencies:
|
||||||
|
bplist-creator "0.0.7"
|
||||||
|
bplist-parser "0.1.1"
|
||||||
|
plist "2.0.1"
|
||||||
|
|
||||||
simple-swizzle@^0.2.2:
|
simple-swizzle@^0.2.2:
|
||||||
version "0.2.2"
|
version "0.2.2"
|
||||||
resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"
|
resolved "https://registry.yarnpkg.com/simple-swizzle/-/simple-swizzle-0.2.2.tgz#a4da6b635ffcccca33f70d17cb92592de95e557a"
|
||||||
@ -10349,6 +10396,11 @@ stream-browserify@^2.0.1:
|
|||||||
inherits "~2.0.1"
|
inherits "~2.0.1"
|
||||||
readable-stream "^2.0.2"
|
readable-stream "^2.0.2"
|
||||||
|
|
||||||
|
stream-buffers@~2.2.0:
|
||||||
|
version "2.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
|
||||||
|
integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg==
|
||||||
|
|
||||||
stream-each@^1.1.0:
|
stream-each@^1.1.0:
|
||||||
version "1.2.3"
|
version "1.2.3"
|
||||||
resolved "https://registry.yarnpkg.com/stream-each/-/stream-each-1.2.3.tgz#ebe27a0c389b04fbcc233642952e10731afa9bae"
|
resolved "https://registry.yarnpkg.com/stream-each/-/stream-each-1.2.3.tgz#ebe27a0c389b04fbcc233642952e10731afa9bae"
|
||||||
@ -11762,11 +11814,21 @@ xdg-basedir@^4.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-4.0.0.tgz#4bc8d9984403696225ef83a1573cbbcb4e79db13"
|
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-4.0.0.tgz#4bc8d9984403696225ef83a1573cbbcb4e79db13"
|
||||||
integrity sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==
|
integrity sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==
|
||||||
|
|
||||||
|
xmlbuilder@8.2.2:
|
||||||
|
version "8.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-8.2.2.tgz#69248673410b4ba42e1a6136551d2922335aa773"
|
||||||
|
integrity sha512-eKRAFz04jghooy8muekqzo8uCSVNeyRedbuJrp0fovbLIi7wlsYtdUn3vBAAPq2Y3/0xMz2WMEUQ8yhVVO9Stw==
|
||||||
|
|
||||||
xmlbuilder@>=11.0.1, xmlbuilder@^15.1.1:
|
xmlbuilder@>=11.0.1, xmlbuilder@^15.1.1:
|
||||||
version "15.1.1"
|
version "15.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-15.1.1.tgz#9dcdce49eea66d8d10b42cae94a79c3c8d0c2ec5"
|
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-15.1.1.tgz#9dcdce49eea66d8d10b42cae94a79c3c8d0c2ec5"
|
||||||
integrity sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==
|
integrity sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==
|
||||||
|
|
||||||
|
xmldom@0.1.x:
|
||||||
|
version "0.1.31"
|
||||||
|
resolved "https://registry.yarnpkg.com/xmldom/-/xmldom-0.1.31.tgz#b76c9a1bd9f0a9737e5a72dc37231cf38375e2ff"
|
||||||
|
integrity sha512-yS2uJflVQs6n+CyjHoaBmVSqIDevTAWrzMmjG1Gc7h1qQ7uVozNhEPJAwZXWyGQ/Gafo3fCwrcaokezLPupVyQ==
|
||||||
|
|
||||||
xtend@^4.0.0, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1:
|
xtend@^4.0.0, xtend@^4.0.2, xtend@~4.0.0, xtend@~4.0.1:
|
||||||
version "4.0.2"
|
version "4.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
|
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user