子输入框

This commit is contained in:
fofolee 2022-04-10 01:54:07 +08:00
parent 73c5dbacee
commit 8cc7f4f985
3 changed files with 51 additions and 3 deletions

View File

@ -44,6 +44,9 @@ export default defineComponent({
utools.onPluginOut(() => {
//
this.$router.push("loading");
//
document.removeEventListener("keydown", this.$profile.tmp.handleEnter);
this.$profile.tmp = {};
//
this.$utools.putDB(
_.cloneDeep(this.$profile),

View File

@ -10,7 +10,8 @@ let defaultProfile = {
primaryColor: "#009688",
defaultPrimaryColor: "#009688",
backgroundImg: null,
codeHistory: {}
codeHistory: {},
tmp: {}
}
let userProfile = UTOOLS.getDB(
UTOOLS.DBPRE.CFG + "preferences"

View File

@ -22,7 +22,13 @@
></pre>
</q-card-section>
<q-card-actions align="right">
<q-btn flat label="关闭" color="primary" v-close-popup />
<q-btn
flat
label="关闭"
color="primary"
v-close-popup
@click="stopRun"
/>
</q-card-actions>
</q-card>
</q-dialog>
@ -52,6 +58,7 @@ export default {
isResultShow: false,
runResult: "",
runResultStatus: true,
subInputValue: "",
};
},
props: {
@ -67,7 +74,12 @@ export default {
},
methods: {
//
async runCurrentCommand(currentCommand) {
runCurrentCommand(currentCommand) {
if (currentCommand.cmd.includes("{{subinput"))
return this.setSubInput(currentCommand);
this.fire(currentCommand);
},
async fire(currentCommand) {
currentCommand.cmd = this.assignSpecialVars(currentCommand.cmd);
// currentCommand.cmd = await this.replaceTempInputVars(currentCommand.cmd);
let { hideWindow, outPlugin, action } =
@ -113,6 +125,31 @@ export default {
});
return cmd;
},
//
setSubInput(currentCommand) {
this.fromUtools && utools.setExpendHeight(0);
let matched = currentCommand.cmd.match(specialVars.subinput.match);
let placeholder = matched[1] || "请输入";
utools.setSubInput(({ text }) => {
this.subInputValue = text;
}, placeholder);
let querySubInput = () => {
let command = _.cloneDeep(currentCommand);
command.cmd = currentCommand.cmd.replace(
specialVars.subinput.match,
this.subInputValue
);
this.fire(command);
};
//
setTimeout(() => {
if (this.subInputValue) querySubInput();
}, 100);
this.$profile.tmp.handleEnter = (event) => {
if (event.keyCode == 13) querySubInput();
};
document.addEventListener("keydown", this.$profile.tmp.handleEnter);
},
//
async replaceTempInputVars(cmd) {
let tempInputVals = [];
@ -170,6 +207,13 @@ export default {
behavior: "smooth",
});
},
stopRun() {
if (this.$profile.tmp.handleEnter) {
this.subInputValue = "";
document.removeEventListener("keydown", this.$profile.tmp.handleEnter);
utools.removeSubInput();
}
},
},
};
</script>