diff --git a/src/App.vue b/src/App.vue index 5ddbe7e..b013ec3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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), diff --git a/src/boot/global.js b/src/boot/global.js index d934851..c73537a 100644 --- a/src/boot/global.js +++ b/src/boot/global.js @@ -10,7 +10,8 @@ let defaultProfile = { primaryColor: "#009688", defaultPrimaryColor: "#009688", backgroundImg: null, - codeHistory: {} + codeHistory: {}, + tmp: {} } let userProfile = UTOOLS.getDB( UTOOLS.DBPRE.CFG + "preferences" diff --git a/src/components/CommandRunResult.vue b/src/components/CommandRunResult.vue index b6c1609..e7446c2 100644 --- a/src/components/CommandRunResult.vue +++ b/src/components/CommandRunResult.vue @@ -22,7 +22,13 @@ > - + @@ -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(); + } + }, }, };