mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-28 20:02:44 +08:00
优化命令概览的生成逻辑,只显示输入框的值
This commit is contained in:
parent
4461619a39
commit
17cec93767
@ -3,7 +3,7 @@
|
|||||||
<OperationCard
|
<OperationCard
|
||||||
v-if="hasSubCommands"
|
v-if="hasSubCommands"
|
||||||
:model-value="funcName"
|
:model-value="funcName"
|
||||||
@update:model-value="funcName = $event"
|
@update:model-value="updateFuncName($event)"
|
||||||
:options="localCommand.subCommands"
|
:options="localCommand.subCommands"
|
||||||
/>
|
/>
|
||||||
<ParamInput :configs="localConfig" :values="argvs" @update="updateArgv" />
|
<ParamInput :configs="localConfig" :values="argvs" @update="updateArgv" />
|
||||||
@ -15,7 +15,11 @@ import { defineComponent } from "vue";
|
|||||||
import OperationCard from "components/composer/common/OperationCard.vue";
|
import OperationCard from "components/composer/common/OperationCard.vue";
|
||||||
import ParamInput from "components/composer/param/ParamInput.vue";
|
import ParamInput from "components/composer/param/ParamInput.vue";
|
||||||
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
import { stringifyArgv, parseFunction } from "js/composer/formatString";
|
||||||
import { newVarInputVal } from "js/composer/varInputValManager";
|
import {
|
||||||
|
newVarInputVal,
|
||||||
|
isVarInputVal,
|
||||||
|
stringifyVarInputVal,
|
||||||
|
} from "js/composer/varInputValManager";
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "MultiParams",
|
name: "MultiParams",
|
||||||
@ -59,26 +63,8 @@ export default defineComponent({
|
|||||||
defaultArgvs() {
|
defaultArgvs() {
|
||||||
return this.localConfig.map((item) => item.value);
|
return this.localConfig.map((item) => item.value);
|
||||||
},
|
},
|
||||||
funcName: {
|
funcName() {
|
||||||
get() {
|
return this.modelValue.value;
|
||||||
return this.modelValue.value;
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
// 构建新的参数数组
|
|
||||||
const newArgvs = [];
|
|
||||||
|
|
||||||
// 保留通用配置的参数值
|
|
||||||
this.commonConfig.forEach((_, index) => {
|
|
||||||
newArgvs[index] = this.argvs[index];
|
|
||||||
});
|
|
||||||
|
|
||||||
// 使用新选择的函数独有配置的默认值
|
|
||||||
this.getSelectSubCommand(value)?.config?.forEach((config, index) => {
|
|
||||||
newArgvs[this.commonConfig.length + index] = config.defaultValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.updateModelValue(value, newArgvs, true);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
argvs() {
|
argvs() {
|
||||||
return (
|
return (
|
||||||
@ -101,6 +87,22 @@ export default defineComponent({
|
|||||||
|
|
||||||
this.updateModelValue(this.funcName, newArgvs);
|
this.updateModelValue(this.funcName, newArgvs);
|
||||||
},
|
},
|
||||||
|
updateFuncName(value) {
|
||||||
|
// 构建新的参数数组
|
||||||
|
const newArgvs = [];
|
||||||
|
|
||||||
|
// 保留通用配置的参数值
|
||||||
|
this.commonConfig.forEach((_, index) => {
|
||||||
|
newArgvs[index] = this.argvs[index];
|
||||||
|
});
|
||||||
|
|
||||||
|
// 使用新选择的函数独有配置的默认值
|
||||||
|
this.getSelectSubCommand(value)?.config?.forEach((config, index) => {
|
||||||
|
newArgvs[this.commonConfig.length + index] = config.defaultValue;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.updateModelValue(value, newArgvs, true);
|
||||||
|
},
|
||||||
generateCode(funcName, argvs) {
|
generateCode(funcName, argvs) {
|
||||||
if (this.localCommand.isExpression) {
|
if (this.localCommand.isExpression) {
|
||||||
return argvs.join("");
|
return argvs.join("");
|
||||||
@ -175,18 +177,31 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
return argvs;
|
return argvs;
|
||||||
},
|
},
|
||||||
getSummary(argvs) {
|
getAllInputValues(argvs) {
|
||||||
|
const flatArgvs = [];
|
||||||
|
argvs.forEach((item) => {
|
||||||
|
if (isVarInputVal(item) && item.value) {
|
||||||
|
flatArgvs.push(stringifyVarInputVal(item));
|
||||||
|
} else if (typeof item === "number") {
|
||||||
|
flatArgvs.push(item.toString());
|
||||||
|
} else if (Array.isArray(item)) {
|
||||||
|
flatArgvs.push(...this.getAllInputValues(item));
|
||||||
|
} else if (typeof item === "object") {
|
||||||
|
flatArgvs.push(...this.getAllInputValues(Object.values(item)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return flatArgvs;
|
||||||
|
},
|
||||||
|
getSummary(funcName, argvs) {
|
||||||
// 虽然header里对溢出做了处理,但是这里截断主要是为了节省存储空间
|
// 虽然header里对溢出做了处理,但是这里截断主要是为了节省存储空间
|
||||||
const funcNameLabel = this.getSelectSubCommand()?.label;
|
const funcNameLabel = this.getSelectSubCommand(funcName)?.label;
|
||||||
const subFeature = funcNameLabel ? `${funcNameLabel} ` : "";
|
const subFeature = funcNameLabel ? `${funcNameLabel} ` : "";
|
||||||
const allArgvs = argvs
|
const allArgvs = this.getAllInputValues(argvs).map((item) =>
|
||||||
.filter((item) => item != null && item != "")
|
window.lodashM.truncate(item, {
|
||||||
.map((item) =>
|
length: 30,
|
||||||
window.lodashM.truncate(stringifyArgv(item).toString(), {
|
omission: "...",
|
||||||
length: 30,
|
})
|
||||||
omission: "...",
|
);
|
||||||
})
|
|
||||||
);
|
|
||||||
return `${subFeature}${allArgvs.join(",")}`;
|
return `${subFeature}${allArgvs.join(",")}`;
|
||||||
},
|
},
|
||||||
updateModelValue(funcName, argvs, resetOutputVariable = false) {
|
updateModelValue(funcName, argvs, resetOutputVariable = false) {
|
||||||
@ -194,7 +209,7 @@ export default defineComponent({
|
|||||||
...this.modelValue,
|
...this.modelValue,
|
||||||
value: funcName,
|
value: funcName,
|
||||||
argvs,
|
argvs,
|
||||||
summary: this.getSummary(argvs),
|
summary: this.getSummary(funcName, argvs),
|
||||||
code: this.generateCode(funcName, argvs),
|
code: this.generateCode(funcName, argvs),
|
||||||
};
|
};
|
||||||
if (resetOutputVariable) {
|
if (resetOutputVariable) {
|
||||||
|
@ -37,7 +37,7 @@ export const newEmptyVarInputVal = (type = "str") => {
|
|||||||
* @returns {string} 处理后的字符串
|
* @returns {string} 处理后的字符串
|
||||||
*/
|
*/
|
||||||
export const stringifyVarInputVal = (argv) => {
|
export const stringifyVarInputVal = (argv) => {
|
||||||
if (!argv.isString) return argv.value;
|
if (!argv.isString) return argv.value.toString();
|
||||||
try {
|
try {
|
||||||
return JSON.stringify(argv.value);
|
return JSON.stringify(argv.value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user