mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-08 14:34:13 +08:00
修复MultiParams生成Code及解析参数失败的问题
This commit is contained in:
parent
4293f095ae
commit
7475b40a07
@ -54,7 +54,10 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="item.type === 'arrayEditor'">
|
<div v-else-if="item.type === 'arrayEditor'">
|
||||||
<ArrayEditor :model-value="argvs[index]" />
|
<ArrayEditor
|
||||||
|
:model-value="argvs[index]"
|
||||||
|
@update:model-value="updateArgv(index, $event)"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -66,11 +69,7 @@ import { defineComponent } from "vue";
|
|||||||
import VariableInput from "components/composer/common/VariableInput.vue";
|
import VariableInput from "components/composer/common/VariableInput.vue";
|
||||||
import NumberInput from "components/composer/common/NumberInput.vue";
|
import NumberInput from "components/composer/common/NumberInput.vue";
|
||||||
import ArrayEditor from "components/composer/common/ArrayEditor.vue";
|
import ArrayEditor from "components/composer/common/ArrayEditor.vue";
|
||||||
import {
|
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||||
stringifyArgv,
|
|
||||||
parseToHasType,
|
|
||||||
parseFunction,
|
|
||||||
} from "js/composer/formatString";
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "MultiParams",
|
name: "MultiParams",
|
||||||
@ -130,69 +129,27 @@ export default defineComponent({
|
|||||||
const newArgvs = argvs
|
const newArgvs = argvs
|
||||||
.map((argv) => stringifyArgv(argv))
|
.map((argv) => stringifyArgv(argv))
|
||||||
.filter((item) => item != null && item !== "");
|
.filter((item) => item != null && item !== "");
|
||||||
console.log(newArgvs);
|
|
||||||
return `${funcName}(${newArgvs.join(",")})`;
|
return `${funcName}(${newArgvs.join(",")})`;
|
||||||
},
|
},
|
||||||
parseCodeToArgvs(code) {
|
parseCodeToArgvs(code) {
|
||||||
const argvs = window.lodashM.cloneDeep(this.defaultArgvs);
|
const argvs = window.lodashM.cloneDeep(this.defaultArgvs);
|
||||||
if (!code) return argvs;
|
if (!code) return argvs;
|
||||||
|
|
||||||
// 匹配函数名和参数
|
const variableFormatPaths = [];
|
||||||
const pattern = new RegExp(`^${this.funcName}\\((.*?)\\)$`);
|
this.localConfig.forEach((item, index) => {
|
||||||
const match = code.match(pattern);
|
if (item.type === "varInput") {
|
||||||
if (match) {
|
variableFormatPaths.push(`arg${index}`);
|
||||||
try {
|
} else if (item.type === "arrayEditor") {
|
||||||
const paramStr = match[1].trim();
|
variableFormatPaths.push(`arg${index}[*]`);
|
||||||
if (!paramStr) return argvs;
|
|
||||||
|
|
||||||
// 分割参数,考虑括号嵌套
|
|
||||||
let params = [];
|
|
||||||
let bracketCount = 0;
|
|
||||||
let currentParam = "";
|
|
||||||
|
|
||||||
for (let i = 0; i < paramStr.length; i++) {
|
|
||||||
const char = paramStr[i];
|
|
||||||
if (char === "," && bracketCount === 0) {
|
|
||||||
params.push(currentParam.trim());
|
|
||||||
currentParam = "";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (char === "{") bracketCount++;
|
|
||||||
if (char === "}") bracketCount--;
|
|
||||||
currentParam += char;
|
|
||||||
}
|
|
||||||
if (currentParam) {
|
|
||||||
params.push(currentParam.trim());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据配置处理每个参数
|
|
||||||
params.forEach((param, index) => {
|
|
||||||
if (index >= this.localConfig.length) return;
|
|
||||||
|
|
||||||
const config = this.localConfig[index];
|
|
||||||
if (config.type === "varInput") {
|
|
||||||
// 对于 VariableInput 类型,解析为带有 __varInputVal__ 标记的对象
|
|
||||||
argvs[index] = parseToHasType(param);
|
|
||||||
} else if (config.type === "numInput") {
|
|
||||||
// 对于 NumberInput 类型,转换为数字
|
|
||||||
argvs[index] = Number(param) || 0;
|
|
||||||
} else if (config.type === "arrayEditor") {
|
|
||||||
let result = parseFunction(`${this.funcName}(${param})`, [
|
|
||||||
"arg0[*]",
|
|
||||||
]);
|
|
||||||
argvs[index] = result.argv;
|
|
||||||
} else {
|
|
||||||
// 其他类型直接使用值
|
|
||||||
argvs[index] = param;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
try {
|
||||||
return argvs;
|
const { args } = parseFunction(code, { variableFormatPaths });
|
||||||
|
return args;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("解析参数失败:", e);
|
console.error("解析参数失败:", e);
|
||||||
}
|
|
||||||
}
|
|
||||||
return argvs;
|
return argvs;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getSummary(argvs) {
|
getSummary(argvs) {
|
||||||
// 虽然header里对溢出做了处理,但是这里截断主要是为了节省存储空间
|
// 虽然header里对溢出做了处理,但是这里截断主要是为了节省存储空间
|
||||||
|
@ -145,30 +145,14 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
emits: ["update:modelValue"],
|
emits: ["update:modelValue"],
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
// 本地维护的数组数据
|
|
||||||
localItems: this.initializeItems(),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
items: {
|
items() {
|
||||||
get() {
|
return this.modelValue.length ? this.modelValue : this.initializeItems();
|
||||||
return this.localItems;
|
|
||||||
},
|
|
||||||
set(newItems) {
|
|
||||||
this.localItems = newItems;
|
|
||||||
this.$emit("update:modelValue", newItems);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initializeItems() {
|
initializeItems() {
|
||||||
if (this.modelValue.length) {
|
if (this.optionsKeys) {
|
||||||
return this.modelValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options?.keys) {
|
|
||||||
const item = {};
|
const item = {};
|
||||||
this.optionsKeys.forEach((key) => {
|
this.optionsKeys.forEach((key) => {
|
||||||
item[key] = {
|
item[key] = {
|
||||||
@ -193,6 +177,7 @@ export default defineComponent({
|
|||||||
* 根据配置创建相应的数据结构
|
* 根据配置创建相应的数据结构
|
||||||
*/
|
*/
|
||||||
addItem() {
|
addItem() {
|
||||||
|
let newItems = [];
|
||||||
if (this.optionsKeys) {
|
if (this.optionsKeys) {
|
||||||
const newItem = {};
|
const newItem = {};
|
||||||
this.optionsKeys.forEach((key) => {
|
this.optionsKeys.forEach((key) => {
|
||||||
@ -202,9 +187,9 @@ export default defineComponent({
|
|||||||
__varInputVal__: true,
|
__varInputVal__: true,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
this.items = [...this.items, newItem];
|
newItems = [...this.items, newItem];
|
||||||
} else {
|
} else {
|
||||||
this.items = [
|
newItems = [
|
||||||
...this.items,
|
...this.items,
|
||||||
{
|
{
|
||||||
value: "",
|
value: "",
|
||||||
@ -213,6 +198,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
this.$emit("update:modelValue", newItems);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 移除指定索引的数组项
|
* 移除指定索引的数组项
|
||||||
@ -240,7 +226,7 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.items = newItems;
|
this.$emit("update:modelValue", newItems);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 更新单值模式下的值
|
* 更新单值模式下的值
|
||||||
@ -248,7 +234,7 @@ export default defineComponent({
|
|||||||
updateItemValue(index, value) {
|
updateItemValue(index, value) {
|
||||||
const newItems = [...this.items];
|
const newItems = [...this.items];
|
||||||
newItems[index] = value;
|
newItems[index] = value;
|
||||||
this.items = newItems;
|
this.$emit("update:modelValue", newItems);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 更新多键模式下指定键的值
|
* 更新多键模式下指定键的值
|
||||||
@ -259,7 +245,7 @@ export default defineComponent({
|
|||||||
...newItems[index],
|
...newItems[index],
|
||||||
[key]: value,
|
[key]: value,
|
||||||
};
|
};
|
||||||
this.items = newItems;
|
this.$emit("update:modelValue", newItems);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -274,7 +260,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* 防止输入框换行 */
|
/* 防止输入框换行 */
|
||||||
:deep(.q-field__native) {
|
.array-editor :deep(.q-field__native) {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@ -309,11 +295,11 @@ export default defineComponent({
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.q-btn .q-icon) {
|
.array-editor :deep(.q-btn .q-icon) {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.q-btn.q-btn--dense) {
|
.array-editor :deep(.q-btn.q-btn--dense) {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
min-height: 16px;
|
min-height: 16px;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user