mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-06 21:14:09 +08:00
优化以下编排中以下功能生成的描述:AI问答、模拟按键、系统命令、ubrowser、按键序列、函数返回
This commit is contained in:
parent
8ea4bad14d
commit
2e94f7897c
@ -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 };
|
||||
|
@ -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);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@ -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);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@ -132,7 +132,7 @@
|
||||
|
||||
<script>
|
||||
import { defineComponent } from "vue";
|
||||
import { parseFunction, stringifyArgv } from "js/composer/formatString";
|
||||
import { stringifyArgv } from "js/composer/formatString";
|
||||
import { newVarInputVal } from "js/composer/varInputValManager";
|
||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||
import NumberInput from "components/composer/common/NumberInput.vue";
|
||||
@ -182,9 +182,7 @@ export default defineComponent({
|
||||
argvs: {
|
||||
get() {
|
||||
return (
|
||||
this.modelValue.argvs ||
|
||||
this.parseCodeToArgvs(this.modelValue.code) ||
|
||||
this.defaultArgvs
|
||||
this.modelValue.argvs || window.lodashM.cloneDeep(this.defaultArgvs)
|
||||
);
|
||||
},
|
||||
set(value) {
|
||||
@ -193,32 +191,6 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
parseCodeToArgvs(code) {
|
||||
if (!code) return null;
|
||||
|
||||
// 定义需要使用variable格式的路径
|
||||
const variableFormatPaths = [
|
||||
"arg0", // 命令字符串
|
||||
"arg1.cwd", // 工作目录
|
||||
"arg1.env.**", // 环境变量
|
||||
];
|
||||
|
||||
// 解析代码
|
||||
const result = parseFunction(code, { variableFormatPaths });
|
||||
if (!result) return this.defaultArgvs;
|
||||
|
||||
// 返回解析结果
|
||||
const [command, options = {}] = result.argvs;
|
||||
return {
|
||||
command: command || this.defaultArgvs.command,
|
||||
options: {
|
||||
...this.defaultArgvs.options,
|
||||
...options,
|
||||
cwd: options.cwd || this.defaultArgvs.options.cwd,
|
||||
env: options.env || this.defaultArgvs.options.env,
|
||||
},
|
||||
};
|
||||
},
|
||||
generateCode(argvs) {
|
||||
const args = [];
|
||||
|
||||
@ -260,7 +232,7 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
getSummary(argvs) {
|
||||
return argvs.command.value;
|
||||
return stringifyArgv(argvs.command);
|
||||
},
|
||||
updateModelValue(argvs) {
|
||||
this.$emit("update:modelValue", {
|
||||
@ -272,10 +244,7 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
const argvs = this.modelValue.argvs || this.defaultArgvs;
|
||||
if (!this.modelValue.code) {
|
||||
this.updateModelValue(argvs);
|
||||
}
|
||||
this.updateModelValue(this.argvs);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
@ -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: 实现代码解析逻辑
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user