網(wǎng)站首頁 編程語言 正文
前言
之前我們介紹了lowcode-engine一些基礎(chǔ)相關(guān)內(nèi)容,接下來我們通過引擎實(shí)戰(zhàn)一些內(nèi)容,在一些場景當(dāng)中,我們的默認(rèn)容器不是頁面,而是需要自定義容器。例如,在常見的低代碼平臺中默認(rèn)容器是表單容器,通過表單容器類提供布局能力。接下來我們就去實(shí)現(xiàn)這個(gè)功能。
物料【FormContainer】開發(fā)
該物料組件主要是用來存放所有FormItem
,可以設(shè)置列數(shù)。
物料組件
接下來我們看代碼內(nèi)容
export interface IFormContainerProps { // 列數(shù) cols: number; } /** * Form容器包裝器。lowcode-engine不支持直接使用hooks組件,需要包裹一層,要不內(nèi)容元素沒辦法直接嵌入 */ export const FormContainerWrapper = forwardRef<IFormRef | undefined, IFormContainerProps>(function FormContainer({ cols, children }, ref) { const [form] = Form.useForm(); React.useImperativeHandle(ref, () => { return { formRef: form } }, []) const getChildren = () => { if (React.Children.count(children) <= 1) { return children; } const newArray = groupArray(React.Children.toArray(children), cols); return newArray.map(childs => { return <Row key={childs?.[0]?.key} gutter={[16, 24]} className={generatorClass('form-container-row')}> { childs.map(child => { const { props } = child; const name = props.componentId || props.__id; return <Col key={name} span={24 / cols}> <Form.Item label="" name={name} rules={[{ required: props.isRequired, message: `${props.title}不能為空!` }]} > {child} </Form.Item> </Col>; }) } </Row> }) } const rootClassNames = classNames(generatorClass('form-container')); return ( <Form form={form} className={rootClassNames}> {getChildren()} </Form> ) }); /** * 容器組件 */ export class FormContainer extends React.Component<IFormContainerProps, any> { render() { return ( <FormContainerWrapper {...this.props} /> ) } }
在實(shí)現(xiàn)的過程中開始使用的hooks組件,發(fā)現(xiàn)會有問題,我們用class組件包裝了下,就沒什么問題了。后續(xù)遷去看看源碼引擎是怎么加載物料的,再來回答這個(gè)問題。
物料Meta信息
上面的物料組件就有一個(gè)cols
需要配置,對用的setter我們可以使用官方提供的RadioGroupSetter
. 由于整個(gè)配置模版內(nèi)容比較多,我只把關(guān)鍵點(diǎn)configure
配置內(nèi)容說下。
"configure": { "props": [ { "title": { "label": { "type": "i18n", "en-US": "cols", "zh-CN": "列數(shù)" } }, "name": "cols", "setter": { "title": "列數(shù)", "componentName": "RadioGroupSetter", "isRequired": true, "props": { "options": [{ "label": "1列", "value": 1, }, { "label": "2列", "value": 2, }, { "label": "3列", "value": 3, }, { "label": "4列", "value": 4 }] }, "initialValue": 1 } } ], "supports": { }, "component": { // 是否是容器組件,如果是容器組件,別的組件可以放置內(nèi)容 isContainer: true }, }
我們看配置內(nèi)容,一個(gè)是設(shè)置setter
, 還有比較重要的一點(diǎn)就是在component
下需要配置isContainer
。如果為true,表示內(nèi)容其它組件可以拖到該容器內(nèi)。
模版內(nèi)容修改
通過研究lowcode-engine,我們可以知道內(nèi)容的渲染是通過schema.json
來渲染內(nèi)容。我們只需修改下初始的 schema.json
。加上容器組件,模版內(nèi)容為
"componentName": "Page", "id": "node_dockcviv8fo1", ... "title": "頁面", "isLocked": false, "condition": true, "conditionGroup": "", "children": [ { // 容器組件 "componentName": "FormContainer", "id": "node_oclcdgs7nr1", "props": { "cols": 2 }, "hidden": false, "title": "", "isLocked": false, "condition": true, "conditionGroup": "" } ]
我們看引擎的大綱內(nèi)容,默認(rèn)就有表單組件了。
這里有一點(diǎn)需要注意,有些場景,我們需要把容器組件toolbar上的操作給禁用掉,這塊比較簡單,可以看下官網(wǎng)怎么設(shè)置。
案例展示
我們看一個(gè)完整的例子。
結(jié)束語
以上就是lowcode-engine
設(shè)置默認(rèn)容器。后續(xù)我們會接著把案例完善起來。能做到創(chuàng)建表單,表單預(yù)覽,數(shù)據(jù)的提交等功能。
原文鏈接:https://juejin.cn/post/7204450037031534651
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-10-21 React配置多個(gè)代理實(shí)現(xiàn)數(shù)據(jù)請求返回問題_React
- 2022-07-02 golang通過node_exporter監(jiān)控GPU及cpu頻率、溫度的代碼_Golang
- 2022-07-09 Python二分查找+字符串模板+textwrap模塊,_python
- 2022-11-07 React?全面解析excel文件_React
- 2022-07-03 el-cascader回顯失敗;el-cascader回顯不出來
- 2024-02-28 UNI-APP,text、rich-text控件顯示字符串,當(dāng)字符串過長時(shí),實(shí)現(xiàn)自動換行
- 2022-12-10 Go?web中cookie值安全securecookie庫使用原理_Golang
- 2022-05-19 ASP.NET?Core框架探索之Authentication的權(quán)限認(rèn)證過程解析_實(shí)用技巧
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支