diff --git a/src/components/composer/ai/AskAIEditor.vue b/src/components/composer/ai/AskAIEditor.vue index eaeb35e..b58d111 100644 --- a/src/components/composer/ai/AskAIEditor.vue +++ b/src/components/composer/ai/AskAIEditor.vue @@ -29,7 +29,7 @@ import { defineComponent } from "vue"; import ButtonGroup from "components/composer/common/ButtonGroup.vue"; import { newVarInputVal } from "js/composer/varInputValManager"; import VariableInput from "components/composer/common/VariableInput.vue"; -import { parseFunction, stringifyArgv } from "js/composer/formatString"; +import { stringifyArgv } from "js/composer/formatString"; import AISelector from "components/ai/AISelector.vue"; export default defineComponent({ name: "AskAIEditor", @@ -69,30 +69,18 @@ export default defineComponent({ computed: { argvs() { return ( - this.modelValue.argvs || this.parseCodeToArgvs(this.modelValue.code) + this.modelValue.argvs || window.lodashM.cloneDeep(this.defaultArgvs) ); }, }, methods: { - parseCodeToArgvs(code) { - const argvs = window.lodashM.cloneDeep(this.defaultArgvs); - if (!code) return argvs; - try { - const variableFormatPaths = ["arg0.prompt"]; - const params = parseFunction(code, { variableFormatPaths }); - return params; - } catch (e) { - console.error("解析参数失败:", e); - } - return argvs; - }, generateCode(argvs = this.argvs) { return `${this.modelValue.value}(${stringifyArgv( argvs.content )}, ${JSON.stringify(argvs.apiConfig)})`; }, getSummary(argvs) { - return "问AI:" + argvs.content.prompt; + return "问AI:" + stringifyArgv(argvs.content.prompt); }, updateArgvs(keyPath, newValue) { const newArgvs = { ...this.argvs }; diff --git a/src/components/composer/simulate/KeyEditor.vue b/src/components/composer/simulate/KeyEditor.vue index 6ff60ff..a4896f5 100644 --- a/src/components/composer/simulate/KeyEditor.vue +++ b/src/components/composer/simulate/KeyEditor.vue @@ -438,7 +438,7 @@ export default defineComponent({ computed: { argvs() { return ( - this.modelValue.argvs || this.parseCodeToArgvs(this.modelValue.code) + this.modelValue.argvs || window.lodashM.cloneDeep(this.defaultArgvs) ); }, mainKeyDisplay() { @@ -622,44 +622,7 @@ export default defineComponent({ ...this.argvs, ...argv, }; - this.$emit("update:modelValue", { - ...this.modelValue, - argvs: newArgvs, - code: this.generateCode(newArgvs), - }); - }, - parseCodeToArgvs(code) { - const argvs = window.lodashM.cloneDeep(this.defaultArgvs); - if (!code) return argvs; - try { - const result = parseFunction(code); - if (!result || !result.argvs || !result.argvs[0]) return argvs; - - const keys = result.argvs[0]; - const options = result.argvs[1] || {}; - - if (keys.length > 0) { - argvs.mainKey = keys[0]; - Object.keys(argvs.modifiers).forEach((key) => { - // 在非 Mac 系统上,将 meta 转换为 command - const modKey = !isMac && key === "command" ? "meta" : key; - argvs.modifiers[key] = keys.slice(1).includes(modKey); - }); - } - - // 解析选项对象 - if (options) { - if (options.repeatCount) argvs.repeatCount = options.repeatCount; - if (options.repeatInterval) - argvs.repeatInterval = options.repeatInterval; - if (options.keyDelay) argvs.keyDelay = options.keyDelay; - } - - return argvs; - } catch (e) { - console.error("Failed to parse key string:", e); - return argvs; - } + this.updateModelValue(newArgvs); }, handleKeyInput(val) { let newMainKey; @@ -703,16 +666,24 @@ export default defineComponent({ .join(" + "); return `${modifiers} + ${shortcut.mainKey}`; }, - }, - mounted() { - const argvs = this.modelValue.argvs || this.defaultArgvs; - if (!this.modelValue.code) { + getSummary(argvs) { + const modifiers = Object.entries(argvs.modifiers) + .filter(([_, active]) => active) + .map(([key]) => this.modifierLabels[key]) + .join(" + "); + return modifiers ? `${modifiers} + ${argvs.mainKey}` : argvs.mainKey; + }, + updateModelValue(argvs) { this.$emit("update:modelValue", { ...this.modelValue, - argvs, + argvs: argvs, code: this.generateCode(argvs), + summary: this.getSummary(argvs), }); - } + }, + }, + mounted() { + this.updateModelValue(this.argvs); }, }); diff --git a/src/components/composer/simulate/KeySequenceEditor.vue b/src/components/composer/simulate/KeySequenceEditor.vue index 99cd59e..cdd37ef 100644 --- a/src/components/composer/simulate/KeySequenceEditor.vue +++ b/src/components/composer/simulate/KeySequenceEditor.vue @@ -459,7 +459,7 @@ export default defineComponent({ computed: { argvs() { return ( - this.modelValue.argvs || this.parseCodeToArgvs(this.modelValue.code) + this.modelValue.argvs || window.lodashM.cloneDeep(this.defaultArgvs) ); }, }, @@ -608,15 +608,26 @@ export default defineComponent({ } return `${this.modelValue.value}(${JSON.stringify(keySequence)})`; }, - updateValue(newArgvs) { + updateValue(newArgvs = this.argvs) { const updatedModelValue = { ...this.modelValue, - argvs: newArgvs || this.argvs, - code: this.generateCode(newArgvs || this.argvs), + argvs: newArgvs, + code: this.generateCode(newArgvs), + summary: this.getSummary(newArgvs), }; this.$emit("update:modelValue", updatedModelValue); }, + getSingleSummary(item) { + const modifiers = Object.entries(item.modifiers) + .filter(([_, active]) => active) + .map(([key]) => this.modifierLabels[key]) + .join(" + "); + return modifiers ? `${modifiers} + ${item.mainKey}` : item.mainKey; + }, + getSummary(argvs) { + return argvs.sequence.map(this.getSingleSummary).join("; "); + }, appendSequence(newSequence) { const startId = Date.now(); this.argvs.sequence.push( @@ -627,37 +638,6 @@ export default defineComponent({ ); this.updateValue(); }, - parseCodeToArgvs(code) { - const argvs = window.lodashM.cloneDeep(this.defaultArgvs); - if (!code) return argvs; - try { - const match = code.match(/\((.*)\)/s); - if (match) { - const args = eval(`[${match[1]}]`); - if (Array.isArray(args[0])) { - argvs.sequence = args[0].map((keys) => { - const mainKey = keys[0]; - const modifiers = { - control: keys.includes("control"), - alt: keys.includes("alt"), - shift: keys.includes("shift"), - command: - !isMac && keys.includes("meta") - ? true - : keys.includes("command"), - }; - return { mainKey, modifiers, id: Date.now() + Math.random() }; - }); - if (args[1] && args[1].interval) { - argvs.interval = args[1].interval; - } - } - } - } catch (e) { - console.error("Failed to parse existing code:", e); - } - return argvs; - }, toggleModifier(index, key) { // 创建新的 argvs 对象 const newArgvs = { @@ -678,10 +658,7 @@ export default defineComponent({ }, }, mounted() { - const argvs = this.modelValue.argvs || this.defaultArgvs; - if (!this.modelValue.code) { - this.updateValue(argvs); - } + this.updateValue(this.argvs); }, }); diff --git a/src/components/composer/system/SystemCommandEditor.vue b/src/components/composer/system/SystemCommandEditor.vue index 9e9c73f..b3cd799 100644 --- a/src/components/composer/system/SystemCommandEditor.vue +++ b/src/components/composer/system/SystemCommandEditor.vue @@ -132,7 +132,7 @@ diff --git a/src/components/composer/ubrowser/UBrowserEditor.vue b/src/components/composer/ubrowser/UBrowserEditor.vue index 8ca5f05..f562476 100644 --- a/src/components/composer/ubrowser/UBrowserEditor.vue +++ b/src/components/composer/ubrowser/UBrowserEditor.vue @@ -50,6 +50,7 @@ import UBrowserBasic from "components/composer/ubrowser/UBrowserBasic.vue"; import UBrowserOperations from "components/composer/ubrowser/UBrowserOperations.vue"; import UBrowserRun from "components/composer/ubrowser/UBrowserRun.vue"; import { generateUBrowserCode } from "js/composer/generateUBrowserCode"; +import { stringifyArgv } from "src/js/composer/formatString"; export default { name: "UBrowserEditor", @@ -83,7 +84,7 @@ export default { return this.modelValue.argvs || this.defaultArgvs; }, summary() { - const goto = this.argvs.goto?.url || ""; + const goto = stringifyArgv(this.argvs.goto?.url || ""); return `访问 ${goto}`; }, }, @@ -112,9 +113,6 @@ export default { code: this.generateCode(), }); }, - parseCodeToArgvs(code) { - // TODO: 实现代码解析逻辑 - }, }, };