From 40e972cbf416fcdd7a2d31bccf67d2a2f70f2d7f Mon Sep 17 00:00:00 2001 From: fofolee Date: Mon, 11 Apr 2022 18:37:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=8B=BC=E9=9F=B3=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/preload.js | 3 +-- src/components/quickcommandUI/SelectList.vue | 22 ++++++-------------- src/js/quickcommand.js | 2 +- src/pages/ConfigurationPage.vue | 2 +- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/public/preload.js b/public/preload.js index 1212f8c..1b14dd8 100644 --- a/public/preload.js +++ b/public/preload.js @@ -9,12 +9,11 @@ const { } = require('./lib/vm2') const path = require("path") const util = require("util") -const PinyinMatch = require('pinyin-match'); const axios = require('axios'); const pictureCompress = require("./lib/picture-compressor") _ = require("lodash") -window.pinYinMatch = PinyinMatch +pinyinMatch = require('pinyin-match').match; // axios.defaults.adapter = require('axios/lib/adapters/http') diff --git a/src/components/quickcommandUI/SelectList.vue b/src/components/quickcommandUI/SelectList.vue index ef4b156..1db6813 100644 --- a/src/components/quickcommandUI/SelectList.vue +++ b/src/components/quickcommandUI/SelectList.vue @@ -73,22 +73,11 @@ export default { }, computed: { matchedItems() { - let matchedItems; - if (!this.searchWords) { - matchedItems = this.items; - } else { - matchedItems = this.items.filter((x) => { - if (this.isJson) { - return ( - x.title.toLowerCase().includes(this.searchWords.toLowerCase()) || - x.description - .toLowerCase() - .includes(this.searchWords.toLowerCase()) - ); - } - return x.toLowerCase().includes(this.searchWords.toLowerCase()); - }); - } + let matchedItems = this.searchWords + ? this.items.filter((x) => + window.pinyinMatch(x.title ? x.title : x, this.searchWords) + ) + : this.items; this.setUtoolsHeight(this.itemHeight * matchedItems.length); return matchedItems; }, @@ -108,6 +97,7 @@ export default { props: { options: Object, items: Array, + pinyinMatch: Function, }, emits: ["ok", "hide"], methods: { diff --git a/src/js/quickcommand.js b/src/js/quickcommand.js index fb370e3..c73bb22 100644 --- a/src/js/quickcommand.js +++ b/src/js/quickcommand.js @@ -90,7 +90,7 @@ const quickcommand = { }), showSelectList: (selects, options = {}) => new Promise((reslove, reject) => { - if (!options.placeholder) options.placeholder = "输入进行筛选" + if (!options.placeholder) options.placeholder = "输入进行筛选,支持拼音" if (!options.optionType) options.optionType = "plaintext" let props = { items: selects, diff --git a/src/pages/ConfigurationPage.vue b/src/pages/ConfigurationPage.vue index 6a13b40..6dd75a8 100644 --- a/src/pages/ConfigurationPage.vue +++ b/src/pages/ConfigurationPage.vue @@ -262,7 +262,7 @@ export default { commands.forEach((cmd) => { // 拼音搜索 let explain = cmd.features.explain; - let matchedWordPositions = window.pinYinMatch.match( + let matchedWordPositions = window.pinyinMatch( explain, this.commandSearchKeyword );