selectList 80%

This commit is contained in:
fofolee 2022-04-11 12:15:31 +08:00
parent 7a04d2108a
commit 1b55377c3c
4 changed files with 364 additions and 285 deletions

View File

@ -94,15 +94,6 @@ window.quickcommand = {
}) })
}, },
// 显示选项列表
showSelectList: function(selects, opt = {}) {
return new Promise((reslove, reject) => {})
},
// 更新选项列表
updateSelectList: function(opt, id) {
},
// 关闭进程 // 关闭进程
kill: function(pid, signal = 'SIGTERM') { kill: function(pid, signal = 'SIGTERM') {
process.kill(pid, signal) process.kill(pid, signal)

View File

@ -4,28 +4,25 @@
maximized maximized
ref="dialog" ref="dialog"
transition-show="fade" transition-show="fade"
transition-hide="fade"
@hide="onDialogHide" @hide="onDialogHide"
>
<q-scroll-area
ref="scrollbar"
:thumb-style="{
width: '7px',
}"
> >
<q-card> <q-card>
<q-virtual-scroll <q-virtual-scroll
virtual-scroll-slice-size="50" ref="scrollBar"
virtual-scroll-item-size="50" :style="{ maxHeight: listMaxHeight + 'px' }"
:virtual-scroll-slice-size="lazyItemSize"
:virtual-scroll-item-size="itemHeight"
@virtual-scroll="scrollEvent" @virtual-scroll="scrollEvent"
:items="items" :items="matchedItems"
> >
<template v-slot="{ item, index }"> <template v-slot="{ item, index }">
<q-item <q-item
:key="index" :key="index"
ref="qitems"
clickable clickable
v-ripple v-ripple
@mousemove="currentIndex = index" @mousemove="currentIndex = index"
@click="onOKClick"
manual-focus manual-focus
:focused="index === currentIndex" :focused="index === currentIndex"
:active="index === currentIndex" :active="index === currentIndex"
@ -33,14 +30,28 @@
height: itemHeight + 'px', height: itemHeight + 'px',
}" }"
> >
<q-item-section> <q-item-section v-if="isText">{{ item }}</q-item-section>
<q-item-section>{{ item }}</q-item-section> <q-item-section v-else-if="isJson">
<q-avatar v-if="item.icon">
<q-icon :name="item.icon" />
</q-avatar>
<q-item-label>{{ item.title }}</q-item-label>
<q-item-label caption>{{ item.description }}</q-item-label>
</q-item-section>
<q-item-section v-else-if="isHtml">
<div v-html="item"></div>
</q-item-section> </q-item-section>
</q-item> </q-item>
</template> </template>
</q-virtual-scroll> </q-virtual-scroll>
<q-btn
class="absolute-bottom-right q-ma-md"
round
color="primary"
icon="close"
@click="onCancelClick"
/>
</q-card> </q-card>
</q-scroll-area>
</q-dialog> </q-dialog>
</template> </template>
@ -48,17 +59,44 @@
export default { export default {
data() { data() {
return { return {
result: this.items[0], listMaxHeight: 500,
currentIndex: 0, currentIndex: 0,
itemHeight: 50, itemHeight: 50,
lazyItemSize: 50,
searchWords: "",
}; };
}, },
mounted() { mounted() {
window.SelectList = this; window.SelectList = this;
this.setSubInput();
this.setUtoolsHeight(this.itemHeight * this.itemSize);
}, },
computed: { computed: {
maxIndex() { itemSize() {
return this.items.length - 1; return this.items.length;
},
matchedItems() {
if (!this.searchWords) return this.items;
let matchedItems = this.items.filter((x) => {
if (typeof x === "string") {
return x.toLowerCase().includes(this.searchWords.toLowerCase());
}
return (
x.title.toLowerCase().includes(this.searchWords.toLowerCase()) ||
x.description.toLowerCase().includes(this.searchWords.toLowerCase())
);
});
this.setUtoolsHeight(this.itemHeight * matchedItems.length);
return matchedItems;
},
isJson() {
return this.options.optionType === "json";
},
isHtml() {
return this.options.optionType === "html";
},
isText() {
return this.options.optionType === "plaintext";
}, },
}, },
props: { props: {
@ -70,6 +108,7 @@ export default {
show() { show() {
this.$refs.dialog.show(); this.$refs.dialog.show();
}, },
hide() { hide() {
this.$refs.dialog.hide(); this.$refs.dialog.hide();
}, },
@ -79,11 +118,20 @@ export default {
}, },
onOKClick() { onOKClick() {
this.$emit("ok", this.result); utools.removeSubInput();
let selected =
this.options.optionType === "json"
? this.matchedItems[this.currentIndex]
: {
id: this.currentIndex,
text: this.matchedItems[this.currentIndex],
};
this.$emit("ok", selected);
this.hide(); this.hide();
}, },
onCancelClick() { onCancelClick() {
utools.removeSubInput();
this.hide(); this.hide();
}, },
@ -94,13 +142,33 @@ export default {
this.currentIndex = Math.max(0, this.currentIndex - 1); this.currentIndex = Math.max(0, this.currentIndex - 1);
break; break;
case 40: case 40:
this.currentIndex = Math.min(this.maxIndex, this.currentIndex + 1); this.currentIndex = Math.min(
this.itemSize - 1,
this.currentIndex + 1
);
break; break;
case 13:
this.onOKClick();
return;
} }
// this.$refs.qitems[this.currentIndex].$el.scrollIntoViewIfNeeded(false); this.$refs.scrollBar.scrollTo(this.currentIndex);
}, },
scrollEvent(e) { scrollEvent(e) {
console.log(e); this.currentIndex =
e.direction === "increase"
? Math.max(e.index, this.currentIndex)
: Math.min(e.index + 9, this.currentIndex);
},
setSubInput() {
utools.setSubInput(({ text }) => {
this.searchWords = text;
}, this.options.placeholder);
},
setUtoolsHeight(height) {
utools.setExpendHeight(Math.min(height, this.listMaxHeight));
}, },
}, },
}; };

View File

@ -89,11 +89,9 @@ const quickcommand = {
}) })
}), }),
showSelectList: (selects, options = {}) => new Promise((reslove, reject) => {
showSelectList: (selects, options = { if (!options.placeholder) options.placeholder = "输入进行筛选"
placeholder: "请选择", if (!options.optionType) options.optionType = "plaintext"
optionType: "plaintext"
}) => new Promise((reslove, reject) => {
let props = { let props = {
items: selects, items: selects,
options: options options: options
@ -106,7 +104,12 @@ const quickcommand = {
}).onCancel(() => { }).onCancel(() => {
console.log('取消') console.log('取消')
}) })
}) }),
// 更新选项列表
updateSelectList: (opt, id) => {
},
} }
export default quickcommand export default quickcommand

View File

@ -12,7 +12,10 @@ interface quickcommandApi {
* @param buttons * @param buttons
* @param title * @param title
*/ */
showButtonBox(buttons: array, title?: string): Promise<{ id: number, text: string }>; showButtonBox(
buttons: array,
title?: string
): Promise<{ id: number; text: string }>;
/** /**
* *
@ -32,10 +35,13 @@ interface quickcommandApi {
* @param options * @param options
* @param title * @param title
*/ */
showInputBox(options: array | { labels: array, values: array, hints: array }, title?: string): Promise<array>; showInputBox(
options: array | { labels: array; values: array; hints: array },
title?: string
): Promise<array>;
/** /**
* * html时
* *
* ```js * ```js
* // plaintext * // plaintext
@ -52,7 +58,7 @@ interface quickcommandApi {
* var opt = [] * var opt = []
* for (var i = 0; i < 15; i++) { * for (var i = 0; i < 15; i++) {
* // 每一个选项为 json 格式 * // 每一个选项为 json 格式
* opt.push({title: `选项${i}`, description: `选项${i}的描述`, abcd: `选项${i}的自定义属性`}) * opt.push({title: `选项${i}`, description: `选项${i}的描述`, icon: `选项${i}的图标`,abcd: `选项${i}的自定义属性`})
* } * }
* quickcommand.showSelectList(opt, {optionType: 'json'}).then(choise => { * quickcommand.showSelectList(opt, {optionType: 'json'}).then(choise => {
* console.log(`选择的选项为${choise.title}`) * console.log(`选择的选项为${choise.title}`)
@ -72,7 +78,10 @@ interface quickcommandApi {
* @param selects * @param selects
* @param options placeholder: 搜索框占位符,optionType: 选项的格式plaintext * @param options placeholder: 搜索框占位符,optionType: 选项的格式plaintext
*/ */
showSelectList(selects: array, options?: { placeholder: string, optionType: 'plaintext' | 'html' | 'json' }): Promise<{ id: number, text: string }>; showSelectList(
selects: array,
options?: { placeholder: string; optionType: "plaintext" | "html" | "json" }
): Promise<{ id: number; text: string | object }>;
/** /**
* *
@ -123,7 +132,11 @@ interface quickcommandApi {
* @param icon success * @param icon success
* @param time 3000 * @param time 3000
*/ */
showMessageBox(message: string, icon?: 'success' | 'error' | 'warning' | 'info' , time?: number): void; showMessageBox(
message: string,
icon?: "success" | "error" | "warning" | "info",
time?: number
): void;
/** /**
* *
@ -155,7 +168,7 @@ interface quickcommandApi {
* *
* @param ms * @param ms
*/ */
setTimeout(callback: () => void, ms) setTimeout(callback: () => void, ms);
/** /**
* html字符串解析为 DOM * html字符串解析为 DOM
@ -168,8 +181,7 @@ interface quickcommandApi {
* *
* @param html html * @param html html
*/ */
htmlParse(html: string): object htmlParse(html: string): object;
/** /**
* Buffer * Buffer
@ -187,7 +199,7 @@ interface quickcommandApi {
* *
* Object时 options utools.showSaveDialog options一致 * Object时 options utools.showSaveDialog options一致
*/ */
downloadFile(url, file?: string | object): Promise<Buffer> downloadFile(url, file?: string | object): Promise<Buffer>;
/** /**
* *
@ -214,7 +226,12 @@ interface quickcommandApi {
* @param name file * @param name file
* @param formData * @param formData
*/ */
uploadFile(url: string, file?: string | object, name?: string, formData?: object): Promise<object> uploadFile(
url: string,
file?: string | object,
name?: string,
formData?: object
): Promise<object>;
/** /**
* export * export
@ -228,14 +245,14 @@ interface quickcommandApi {
* *
* @param url * @param url
*/ */
loadRemoteScript(url: string): Promise<object> loadRemoteScript(url: string): Promise<object>;
/** /**
* signal pid , process.kill * signal pid , process.kill
* @param pid ID * @param pid ID
* @param signal SIGTERM * @param signal SIGTERM
*/ */
kill(pid: number, signal?: number | string): void kill(pid: number, signal?: number | string): void;
/** /**
* windows VBS * windows VBS
@ -246,7 +263,7 @@ interface quickcommandApi {
* *
* @param script VBS * @param script VBS
*/ */
runVbs(script: string): Promise<string> runVbs(script: string): Promise<string>;
/** /**
* utools.onPluginEnter code type payload * utools.onPluginEnter code type payload
@ -265,17 +282,17 @@ interface quickcommandApi {
* ``` * ```
* *
*/ */
enterData: { code: string, type: string, payload: any } enterData: { code: string; type: string; payload: any };
/** /**
* *
*/ */
simulateCopy() simulateCopy();
/** /**
* *
*/ */
simulatePaste() simulatePaste();
} }
declare var quickcommand: quickcommandApi; declare var quickcommand: quickcommandApi;