不再在command上添加funcName键,使用value

This commit is contained in:
fofolee 2025-01-05 23:31:43 +08:00
parent 296c231c44
commit 5ac107d4b6

View File

@ -9,14 +9,14 @@
<div
v-for="option in localCommand.functionSelector?.options"
:key="option.value"
:class="['operation-card', { active: functionName === option.value }]"
:class="['operation-card', { active: funcName === option.value }]"
:data-value="option.value"
@click="functionName = option.value"
@click="funcName = option.value"
>
<q-icon
:name="option.icon || localCommand.icon || 'functions'"
size="16px"
:color="functionName === option.value ? 'primary' : 'grey'"
:color="funcName === option.value ? 'primary' : 'grey'"
/>
<div class="text-caption">{{ option.label }}</div>
</div>
@ -85,13 +85,9 @@ export default defineComponent({
defaultArgvs() {
return this.localConfig.map((item) => item.value);
},
functionName: {
funcName: {
get() {
return (
this.modelValue.functionName ||
this.modelValue.functionSelector?.options[0]?.value ||
this.modelValue.value
);
return this.modelValue.value;
},
set(value) {
this.updateModelValue(value, this.defaultArgvs);
@ -111,18 +107,18 @@ export default defineComponent({
const newArgvs = [...this.argvs];
newArgvs[index] = value;
this.updateModelValue(this.functionName, newArgvs);
this.updateModelValue(this.funcName, newArgvs);
},
generateCode(functionName, argvs) {
generateCode(funcName, argvs) {
const newArgvs = argvs.map((argv) => stringifyWithType(argv));
return `${functionName}(${newArgvs.join(",")})`;
return `${funcName}(${newArgvs.join(",")})`;
},
parseCodeToArgvs(code) {
const argvs = window.lodashM.cloneDeep(this.defaultArgvs);
if (!code) return argvs;
//
const pattern = new RegExp(`^${this.functionName}\\((.*?)\\)$`);
const pattern = new RegExp(`^${this.funcName}\\((.*?)\\)$`);
const match = code.match(pattern);
if (match) {
try {
@ -176,7 +172,7 @@ export default defineComponent({
getSummary(argvs) {
// header
const funcNameLabel = this.localCommand.functionSelector?.options.find(
(option) => option.value === this.functionName
(option) => option.value === this.funcName
)?.label;
const subFeature = funcNameLabel ? `${funcNameLabel} ` : "";
const allArgvs = argvs
@ -191,27 +187,23 @@ export default defineComponent({
.filter((item) => item != null && item != "");
return `${subFeature}${allArgvs.join(",")}`;
},
updateModelValue(functionName, argvs) {
updateModelValue(funcName, argvs) {
this.$emit("update:modelValue", {
...this.modelValue,
functionName,
summary: this.getSummary(argvs),
value: funcName,
argvs,
code: this.generateCode(functionName, argvs),
summary: this.getSummary(argvs),
code: this.generateCode(funcName, argvs),
});
},
},
mounted() {
if (
!this.modelValue.argvs &&
!this.modelValue.code &&
!this.modelValue.functionName
) {
this.updateModelValue(this.functionName, this.defaultArgvs);
if (!this.modelValue.argvs && !this.modelValue.code) {
this.updateModelValue(this.funcName, this.defaultArgvs);
}
},
watch: {
functionName: {
funcName: {
immediate: true,
handler(newVal) {
//