Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Schema] 低代码业务组件默认属性(defaultProps)在编辑态、生成代码时无效 #2712

Closed
charmtiger opened this issue Nov 30, 2023 · 15 comments
Assignees
Labels
insufficient information Further information is requested / 信息不足,请补充信息

Comments

@charmtiger
Copy link

charmtiger commented Nov 30, 2023

问题描述

背景:我在使用lce的低代码组件相关能力,实现自定义组件的功能,也实现了定义configure.props配置等等,目前自定义组件拖拽到Page中是可以正常使用的。

问题:通过props的配置,现在拖拽组件到Page中使用,属性区表单都正常。包括本主题主要关注的某个prop的默认值,都正常使用。
但是,组件已经配置了props的默认值了,在编辑这个低码组件的时候,上下文中却拿不到 this.props.xxx 的默认值,这样调试起来比较麻烦,得写 this.props.xxx || '默认值' 才可以。我看到协议中有本贴顶部所copy 的 defaultProps 参数,觉得应该是用来解决这个问题,但是没有效果。

协议文档地址

image

这是我的使用了 defaultProps 的Schema

{
    "componentName": "Component",
    "id": "node_oclnifzvpc1",
    "props": {
        "fill": true
    },
    "fileName": "ExaminationDetails",
    "title": "考试详情",
    "meta": {
        "title": "考试详情",
        "folder": "questionEditor"
    },
    "isLocked": false,
    "condition": true,
    "conditionGroup": "",
    "lifeCycles": {},
    "methods": {},
    "dataSource": {
        "list": []
    },
    "state": {
    },
    "defaultProps": {
        "examId": "6567ecbd65bf0ed561ba78d5"
    },
    "propDefinitions": [
        {
            "name": "examId",
            "propType": "string",
            "defaultValue": "6567ecbd65bf0ed561ba78d5"
        }
    ],
    "children": [
        {
            "componentName": "Text",
            "props": {
                "children": {
                    "type": "JSExpression",
                    "value": "this.props?.examId",
                    "mock": "考试ID"
                },
            }
        }
    ]
}

当前效果

绑定了this.props.examId的Text组件无法显示文字,其值为undefined

期望效果

可以在openDocument时将defaultProps中的数据赋值给this.props,方便调试

@eternalsky
Copy link
Collaborator

没看懂问题描述,请再重新组织一下 issue 内容。描述一下问题的上下文。

@eternalsky eternalsky added the insufficient information Further information is requested / 信息不足,请补充信息 label Nov 30, 2023
Copy link

你好 @charmtiger,由于缺乏必要的信息(如 bug 重现步骤、引擎版本信息 等),无法定位问题,请按照 issue bug 模板 补全信息,也可以通过阅读 引擎的 issue 说明 了解什么类型的 issue 可以获得更好、更快的支持。

@charmtiger
Copy link
Author

没看懂问题描述,请再重新组织一下 issue 内容。描述一下问题的上下文。

已修改问题描述,帮忙看看,如果还无法了解,我再改

@eternalsky
Copy link
Collaborator

问题描述上面一段的意义不明,最好放在问题描述里,结合着你的描述来,最上面的貌似是个 md 的表格,但是格式乱了,也是意义不明。

@charmtiger
Copy link
Author

@eternalsky
Copy link
Collaborator

eternalsky commented Nov 30, 2023

@eternalsky https://lowcode-engine.cn/site/docs/specs/lowcode-spec#233%E5%AE%B9%E5%99%A8%E7%BB%93%E6%9E%84%E6%8F%8F%E8%BF%B0-a 那是我摘录协议中的内容

摘录可以是以图片形式,或者把格式调整为可以阅读的(并且标注是协议内容),放在最上面无法理解是协议内容,还是自己希望修改的内容

@charmtiger
Copy link
Author

@eternalsky 已修改,不好意思 😁

@eternalsky
Copy link
Collaborator

大致明白你的问题了,据我的理解,属性的默认值应该出现在物料描述当中,而不是在组件的 schema 当中,搭建协议中的 defaultProps 应该是没有实现的吧? 这点需要 @liujuping 确认一下。正常来讲,应该是放在物料描述协议当中,和使用源码开发的组件同样的配置方式。

@eternalsky
Copy link
Collaborator

物料描述可以参考:低代码引擎物料协议规范 。尤其是其中 configure 章节里里的 props,这里的 defaultValue 目前是实现属性默认值的最佳路径。

@charmtiger
Copy link
Author

物料描述中我目前使用的是 setter.initialValue ,在使用这个低代码组件是正常的。但是在编辑态,我们openDocument或createDocument 时,所传入的schema,并不包含configure信息,协议中 Page/Component 容器schema中也并不包含configure 字段。所以我认为编辑态,用不到configure组件描述

@eternalsky
Copy link
Collaborator

eternalsky commented Nov 30, 2023

物料描述中我目前使用的是 setter.initialValue ,在使用这个低代码组件是正常的。但是在编辑态,我们openDocument或createDocument 时,所传入的schema,并不包含configure信息,协议中 Page/Component 容器schema中也并不包含configure 字段。所以我认为编辑态,用不到configure组件描述

schema 里没有,但是资产包里有,不是所有信息都描述在搭建 schema 里的,尤其是和物料相关的,基本都是描述在物料协议当中,可以看下开源协议里,关于资产包和物料协议的部分。

@charmtiger
Copy link
Author

image

嗯嗯,只是我现在就是不知道怎样才能影响低代码组件在设计模式下 如何预设 props 默认值,方便调试。

不急,快下班了,得空再看😁

@eternalsky
Copy link
Collaborator

image 嗯嗯,只是我现在就是不知道怎样才能影响低代码组件在设计模式下 如何预设 props 默认值,方便调试。

不急,快下班了,得空再看😁

我们的实现里,这部分也不是直接响应,毕竟在设计器里直接响应有太多的不确定性,我们通常是在调试或者预览当中才会有反应。

@charmtiger
Copy link
Author

明白了,我以为是我用错了,谢谢!

@liujuping
Copy link
Collaborator

低代码组件中的 defaultProps 目前还没有实现。我提一个新的 issue,后面继续跟进。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
insufficient information Further information is requested / 信息不足,请补充信息
Projects
None yet
Development

No branches or pull requests

3 participants