multiparam参数名称调整

This commit is contained in:
fofolee 2025-01-29 15:34:20 +08:00
parent 70e01a53d8
commit ae8edfd710
3 changed files with 38 additions and 43 deletions

View File

@ -57,7 +57,7 @@
</template> </template>
<script> <script>
import { defineComponent, inject } from "vue"; import { defineComponent } from "vue";
import draggable from "vuedraggable"; import draggable from "vuedraggable";
import ComposerCard from "./ComposerCard.vue"; import ComposerCard from "./ComposerCard.vue";
import ChainStyles from "./flow/ChainStyles.vue"; import ChainStyles from "./flow/ChainStyles.vue";

View File

@ -2,8 +2,8 @@
<div class="multi-params"> <div class="multi-params">
<OperationCard <OperationCard
v-if="hasSubCommands" v-if="hasSubCommands"
:model-value="funcName" :model-value="subCommand"
@update:model-value="updateFuncName($event)" @update:model-value="updateSubCommand($event)"
:options="localCommand.subCommands" :options="localCommand.subCommands"
/> />
<ParamInput :configs="localConfig" :values="argvs" @update="updateArgv" /> <ParamInput :configs="localConfig" :values="argvs" @update="updateArgv" />
@ -63,8 +63,8 @@ export default defineComponent({
defaultArgvs() { defaultArgvs() {
return this.localConfig.map((item) => item.value); return this.localConfig.map((item) => item.value);
}, },
funcName() { subCommand() {
return this.modelValue.value; return this.modelValue.subCommand || this.modelValue.value;
}, },
argvs() { argvs() {
return ( return (
@ -76,18 +76,18 @@ export default defineComponent({
}, },
}, },
methods: { methods: {
getSelectSubCommand(funcName = this.funcName) { getSelectSubCommand(subCommand = this.subCommand) {
return this.modelValue.subCommands?.find( return this.modelValue.subCommands?.find(
(item) => item.value === funcName (item) => item.value === subCommand
); );
}, },
updateArgv(index, value) { updateArgv(index, value) {
const newArgvs = [...this.argvs]; const newArgvs = [...this.argvs];
newArgvs[index] = value; newArgvs[index] = value;
this.updateModelValue(this.funcName, newArgvs); this.updateModelValue(this.subCommand, newArgvs);
}, },
updateFuncName(value) { updateSubCommand(value) {
// //
const newArgvs = []; const newArgvs = [];
@ -103,7 +103,7 @@ export default defineComponent({
this.updateModelValue(value, newArgvs, true); this.updateModelValue(value, newArgvs, true);
}, },
generateCode(funcName, argvs) { generateCode(subCommand, argvs) {
if (this.localCommand.isExpression) { if (this.localCommand.isExpression) {
return argvs.join(""); return argvs.join("");
} }
@ -120,13 +120,13 @@ export default defineComponent({
* 5. 如果不想传递对应参数将varInput切为变量模式并留空 * 5. 如果不想传递对应参数将varInput切为变量模式并留空
* 6. 如果想传递空参数将varInput切为变量模式并设置为null或undefined * 6. 如果想传递空参数将varInput切为变量模式并设置为null或undefined
* [undefined, undefined] -> funcName() * [undefined, undefined] -> subCommand()
* [undefined, 1] -> '' * [undefined, 1] -> ''
* [1, undefined] -> funcName(1) * [1, undefined] -> subCommand(1)
* [null, 1] -> funcName(null, 1) * [null, 1] -> subCommand(null, 1)
* [1, 字符串模式下varInput留空] -> funcName(1, "") * [1, 字符串模式下varInput留空] -> subCommand(1, "")
* [1, 变量模式下varInput留空] -> funcName(1) * [1, 变量模式下varInput留空] -> subCommand(1)
* [1, 变量模式下varInput设置为null] -> funcName(1, null) * [1, 变量模式下varInput设置为null] -> subCommand(1, null)
*/ */
// //
const isEmpty = (v) => v === undefined || v === "" || v === null; const isEmpty = (v) => v === undefined || v === "" || v === null;
@ -139,7 +139,7 @@ export default defineComponent({
// //
const finalArgvs = stringifiedArgvs.filter((v) => !isEmpty(v)); const finalArgvs = stringifiedArgvs.filter((v) => !isEmpty(v));
return `${funcName}(${finalArgvs.join(",")})`; return `${subCommand}(${finalArgvs.join(",")})`;
}, },
parseCodeToArgvs(code) { parseCodeToArgvs(code) {
let argvs = window.lodashM.cloneDeep(this.defaultArgvs); let argvs = window.lodashM.cloneDeep(this.defaultArgvs);
@ -199,10 +199,10 @@ export default defineComponent({
}); });
return flatArgvs; return flatArgvs;
}, },
getSummary(funcName, argvs) { getSummary(subCommand, argvs) {
// header // header
const funcNameLabel = this.getSelectSubCommand(funcName)?.label; const subCommandLabel = this.getSelectSubCommand(subCommand)?.label;
const subFeature = funcNameLabel ? `${funcNameLabel} ` : ""; const subFeature = subCommandLabel ? `${subCommandLabel} ` : "";
const allArgvs = this.getAllInputValues(argvs).map((item) => const allArgvs = this.getAllInputValues(argvs).map((item) =>
window.lodashM.truncate(item, { window.lodashM.truncate(item, {
length: 30, length: 30,
@ -211,13 +211,13 @@ export default defineComponent({
); );
return `${subFeature}${allArgvs.join(",")}`; return `${subFeature}${allArgvs.join(",")}`;
}, },
updateModelValue(funcName, argvs, resetOutputVariable = false) { updateModelValue(subCommand, argvs, resetOutputVariable = false) {
const newModelValue = { const newModelValue = {
...this.modelValue, ...this.modelValue,
value: funcName, subCommand,
argvs, argvs,
summary: this.getSummary(funcName, argvs), summary: this.getSummary(subCommand, argvs),
code: this.generateCode(funcName, argvs), code: this.generateCode(subCommand, argvs),
}; };
if (resetOutputVariable) { if (resetOutputVariable) {
delete newModelValue.outputVariable; delete newModelValue.outputVariable;
@ -234,7 +234,7 @@ export default defineComponent({
mounted() { mounted() {
const argvs = this.modelValue.argvs || this.defaultArgvs; const argvs = this.modelValue.argvs || this.defaultArgvs;
if (!this.modelValue.code && Array.isArray(argvs)) { if (!this.modelValue.code && Array.isArray(argvs)) {
this.updateModelValue(this.funcName, argvs); this.updateModelValue(this.subCommand, argvs);
} }
}, },
}); });

View File

@ -1,26 +1,21 @@
export { import { commandCategories } from "./commands";
ubrowserOperationConfigs,
defaultUBrowserConfigs,
} from "./ubrowserConfig";
import { commandCategories as categories } from "./commands"; let availableCommands = [];
let commandValueMap = {};
// 从commandCategories中提取所有命令 // 从commandCategories中提取所有命令
export const availableCommands = categories.reduce((commands, category) => { commandCategories.forEach((category) => {
return commands.concat( category.commands.forEach((cmd) => {
category.commands.map((cmd) => ({ availableCommands.push({
type: category.label, type: category.label,
...cmd, ...cmd,
})) });
); commandValueMap[cmd.value] = cmd;
}, []); });
});
export const findCommandByValue = (value) => { const findCommandByValue = (value) => {
return availableCommands.find( return commandValueMap[value];
(cmd) =>
cmd.value === value ||
cmd.subCommands?.find((subCmd) => subCmd.value === value)
);
}; };
export const commandCategories = categories; export { availableCommands, commandCategories, findCommandByValue };