编排卡片收缩时显示摘要

This commit is contained in:
fofolee
2025-01-05 14:40:00 +08:00
parent 923fc9e4de
commit 54bb43dcc8
21 changed files with 325 additions and 213 deletions

View File

@@ -124,6 +124,49 @@ const customComponentGuide = {
`,
},
},
getSummary: {
description: "生成命令的简短描述,用于在命令列表中显示",
parameters: "argvs - 当前参数对象",
implementation: {
simpleCase: `
// 返回操作类型的标签
return this.operations.find(op => op.name === argvs.operation).label;
`,
complexCase: `
// 返回关键参数的值
return argvs.command.value;
`,
},
notes: [
"返回值应该简洁明了,帮助用户快速识别命令的功能",
"对于复杂命令,应该返回最关键的参数信息",
"返回的文本长度应该适中,避免过长",
],
},
updateModelValue: {
description: "更新组件的值并触发更新事件",
parameters: "argvs - 当前参数对象",
implementation: `
this.$emit("update:modelValue", {
...this.modelValue,
summary: this.getSummary(argvs),
code: this.generateCode(argvs),
argvs,
});
`,
notes: [
"必须保留原有的 modelValue 属性",
"必须包含 summary、code 和 argvs 三个字段",
"summary 用于在命令列表中显示",
"code 是生成的代码字符串",
"argvs 是当前的参数对象",
],
usage: [
"在 mounted 钩子中初始化组件值",
"在 argvs setter 中更新组件值",
"在任何需要更新组件值的地方调用",
],
},
},
mounted: {
description: "组件初始化时的处理",

View File

@@ -30,13 +30,13 @@ export const stringifyWithType = (argv) => {
*/
const removeEmptyValues = (obj) => {
return window.lodashM.omitBy(obj, (value) => {
if (
window.lodashM.isNil(value) ||
value === "" ||
(value.isString && value.value === "")
)
return true;
if (typeof value === "object")
// 如果value是VariableInput的输出则取其value值
const realValue = value?.hasOwnProperty("__varInputVal__")
? value.value
: value;
if (window.lodashM.isNil(realValue) || realValue === "") return true;
// 如果value是对象并且不是VariableInput的输出则递归移除空值
if (typeof value === "object" && !value.hasOwnProperty("__varInputVal__"))
return window.lodashM.isEmpty(removeEmptyValues(value));
return false;
});
@@ -52,7 +52,7 @@ const processObject = (obj, parentPath = "") => {
// 移除空值
obj = removeEmptyValues(obj);
// 如果是 VariableInput 的输出,直接用 stringifyWithType 处理
if (obj && typeof obj === "object" && obj.hasOwnProperty("__varInputVal__")) {
if (obj?.hasOwnProperty("__varInputVal__")) {
return stringifyWithType(obj);
}
@@ -95,6 +95,9 @@ const processObject = (obj, parentPath = "") => {
* @returns {string} 格式化后的JSON字符串
*/
export const stringifyObject = (jsonObj) => {
if (jsonObj?.hasOwnProperty("__varInputVal__")) {
return stringifyWithType(jsonObj);
}
try {
return processObject(jsonObj);
} catch (e) {