From 0664e021d0aaef073c61728e08dfc55291ef753a Mon Sep 17 00:00:00 2001 From: wanmeihuaxu <540765296@qq.com> Date: Thu, 16 Jan 2025 16:02:55 +0800 Subject: [PATCH] =?UTF-8?q?bug=20fix:showSelectList=20options=E7=9A=84clos?= =?UTF-8?q?eOnSelect=E8=AE=BE=E7=BD=AE=E4=B8=BAfalse=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E9=80=89=E9=A1=B9=E5=8F=AA=E8=83=BD=E7=82=B9=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=EF=BC=9A=E6=B7=BB=E5=8A=A0=E6=AF=8F?= =?UTF-8?q?=E4=B8=AA=E9=80=89=E9=A1=B9=E7=8B=AC=E7=AB=8B=E7=9A=84=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/quickcommandUI/QuickCommand.vue | 3 +++ src/components/quickcommandUI/SelectList.vue | 2 +- src/plugins/monaco/types/quickcommand.api.d.ts | 11 +++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/quickcommandUI/QuickCommand.vue b/src/components/quickcommandUI/QuickCommand.vue index c575c5c..b89b931 100644 --- a/src/components/quickcommandUI/QuickCommand.vue +++ b/src/components/quickcommandUI/QuickCommand.vue @@ -186,6 +186,9 @@ export default { * initItems = [{title: "1", description: "1"}, {title: "2", description: "2"}, {title: "3", description: "3"}] * options = {placeholder: "输入进行筛选,支持拼音", optionType: "json", enableSearch: true, showCancelButton: false, closeOnSelect: true} * + * 如需对每个选项单独注册点击事件,可以在initItems的元素中添加id和clickFn,如: + * initItems = [{id:1, title: "1", description: "1", clickFn:function(e){console.log(e)}}, {id:2, title: "2", description: "2", clickFn:function(e){console.log(e)}}] + * * @example * initItems = ["
1
", "
2
", "
3
"] * options = {placeholder: "输入进行筛选,支持拼音", optionType: "html", enableSearch: true, showCancelButton: false, closeOnSelect: true} diff --git a/src/components/quickcommandUI/SelectList.vue b/src/components/quickcommandUI/SelectList.vue index 4ada780..23d5e97 100644 --- a/src/components/quickcommandUI/SelectList.vue +++ b/src/components/quickcommandUI/SelectList.vue @@ -144,7 +144,7 @@ export default { id: this.currentIndex, text: this.matchedItems[this.currentIndex], }; - this.$emit("clickOK", selected); + this.is.json && selected.clickFn ? selected.clickFn(this.matchedItems[this.currentIndex].id) : this.$emit("clickOK", selected); this.options.options.closeOnSelect && this.hide(); }, diff --git a/src/plugins/monaco/types/quickcommand.api.d.ts b/src/plugins/monaco/types/quickcommand.api.d.ts index 27bfff0..5fb9062 100644 --- a/src/plugins/monaco/types/quickcommand.api.d.ts +++ b/src/plugins/monaco/types/quickcommand.api.d.ts @@ -55,8 +55,15 @@ interface quickcommandApi { * // json * var opt = [] * for (var i = 0; i < 15; i++) { - * // 每一个选项为 json 格式 - * opt.push({title: `选项${i}`, description: `选项${i}的描述`, icon: `http://www.u.tools/favicon.ico`,abcd: `选项${i}的自定义属性`}) + * // 每一个选项为 json 格式, 使用clickFn注册选项单击事件时id属性是必需的 + * opt.push({ + * id: i, + * title: `选项${i}`, + * description: `选项${i}的描述`, + * icon: `http://www.u.tools/favicon.ico`, + * abcd: `选项${i}的自定义属性`, + * clickFn:function(e){console.log(e)} + * }) * } * quickcommand.showSelectList(opt, {optionType: 'json'}).then(choise => { * console.log(`选择的选项为${choise.title}`)