3 个 ui 完善

This commit is contained in:
fofolee
2022-04-07 23:53:22 +08:00
parent 362cde8da7
commit ec41728d0e
7 changed files with 220 additions and 136 deletions

View File

@@ -0,0 +1,55 @@
<template>
<q-dialog ref="dialog" @hide="onDialogHide">
<q-card class="q-dialog-plugin">
<q-card-section>
<div class="text-h5" align="center" v-text="title"></div>
</q-card-section>
<q-card-section class="q-gutter-lg">
<div v-for="(label, index) in labels" :key="index">
<q-btn
class="full-width"
color="primary"
:label="label"
@click="onOKClick(label, index)"
/>
</div>
</q-card-section>
</q-card>
</q-dialog>
</template>
<script>
export default {
data() {
return {
results: this.values,
};
},
props: {
labels: Array,
title: String,
},
emits: ["ok", "hide"],
methods: {
show() {
this.$refs.dialog.show();
},
hide() {
this.$refs.dialog.hide();
},
onDialogHide() {
this.$emit("hide");
},
onOKClick(label, index) {
this.$emit("ok", { id: index, text: label });
this.hide();
},
onCancelClick() {
this.hide();
},
},
};
</script>

View File

@@ -0,0 +1,69 @@
<template>
<q-dialog maximized ref="dialog" @hide="onDialogHide">
<q-card class="q-dialog-plugin">
<textarea
v-model="result"
:placeholder="placeholder"
autofocus
class="fixed"
:style="{
top: 0,
bottom: '36px',
left: 0,
right: 0,
background: '#00000000',
color: $q.dark.isActive ? 'white' : 'black',
fontSize: '16px',
outline: 'none',
}"
/>
<q-btn-group
spread
class="fixed-bottom"
:style="{
left: 0,
right: 0,
}"
>
<q-btn label="取消" color="negative" @click="onCancelClick" />
<q-btn label="确定" color="primary" @click="onOKClick" />
</q-btn-group>
</q-card>
</q-dialog>
</template>
<script>
export default {
data() {
return {
result: this.value,
};
},
props: {
placeholder: String,
value: String,
},
emits: ["ok", "hide"],
methods: {
show() {
this.$refs.dialog.show();
},
hide() {
this.$refs.dialog.hide();
},
onDialogHide() {
this.$emit("hide");
},
onOKClick() {
this.$emit("ok", this.result);
this.hide();
},
onCancelClick() {
this.hide();
},
},
};
</script>

View File

@@ -7,10 +7,12 @@ import {
Dialog,
Notify
} from 'quasar'
import inputBox from "../components/InputBox"
import inputBox from "../components/quickcommandUI/InputBox"
import buttonBox from "../components/quickcommandUI/ButtonBox"
import TextArea from "../components/quickcommandUI/TextArea"
let showInputBox = (options = [], title = "") => {
let showInputBox = (options = ["请输入"], title = "") => {
return new Promise((reslove, reject) => {
let props = {
labels: [],
@@ -32,6 +34,25 @@ let showInputBox = (options = [], title = "") => {
})
};
let showButtonBox = (labels = ["确定"], title = "") => {
return new Promise((reslove, reject) => {
if (!(labels instanceof Array)) return reject(new TypeError("必须为数组"))
let props = {
labels: labels,
title: title
}
Dialog.create({
component: buttonBox,
componentProps: props
}).onOk(results => {
reslove(results)
}).onCancel(() => {
console.log('取消')
})
})
};
let showConfirmBox = (message = "", title = "提示") => {
return new Promise((reslove, reject) => {
Dialog.create({
@@ -58,9 +79,28 @@ let showMessageBox = (message, icon = 'success', time = 3000) => {
})
}
let showTextArea = (placeholder = "", value = "") => {
return new Promise((reslove, reject) => {
let props = {
placeholder: placeholder,
value: value
}
Dialog.create({
component: TextArea,
componentProps: props
}).onOk(results => {
reslove(results)
}).onCancel(() => {
console.log('取消')
})
})
}
export default {
showInputBox,
showMessageBox,
showConfirmBox
};
showConfirmBox,
showButtonBox,
showTextArea
};

View File

@@ -13,11 +13,11 @@
]
},
"program": "quickcommand",
"cmd": "var snippet = {}\nquickcommand.showTextAera(\"请输入代码片段\").then(code => {\n snippet.body = code.split(\"\\n\")\n quickcommand.showInputBox([\"代码片段的描述\", \"触发代码片段的关键词\"])\n .then(inputs => {\n snippet.prefix = inputs[1]\n snippet.description = inputs[0]\n var result = `\"${inputs[0]}\": ` + JSON.stringify(snippet, null, '\\t')\n console.log(result)\n utools.copyText(result)\n quickcommand.showMessageBox('已复制')\n })\n})",
"cmd": "var snippet = {}\nquickcommand.showTextArea(\"请输入代码片段\").then(code => {\n snippet.body = code.split(\"\\n\")\n quickcommand.showInputBox([\"代码片段的描述\", \"触发代码片段的关键词\"])\n .then(inputs => {\n snippet.prefix = inputs[1]\n snippet.description = inputs[0]\n var result = `\"${inputs[0]}\": ` + JSON.stringify(snippet, null, '\\t')\n console.log(result)\n utools.copyText(result)\n quickcommand.showMessageBox('已复制')\n })\n})",
"output": "text",
"hasSubInput": false,
"scptarg": "",
"tags": [
"默认"
]
}
}

View File

@@ -111,7 +111,7 @@ interface quickcommandApi {
* @param placeholder 文本框占位符
* @param value 默认的文本值
*/
showTextAera(placeholder?: string, value?: string): Promise<string>;
showTextArea(placeholder?: string, value?: string): Promise<string>;
/**
* 显示一个自动消失的提示框