zan-design
design 业务组件。
这个包是微商城内的一些 Design 组件,Design 组件的框架在 Zent 里面,不在这里维护。
代码演示
;;;; const components = type: ConfigEditordesignType preview: ConfigPreview // previewController: ConfigPreviewController, editor: ConfigEditor // 是否可以拖拽 dragable: false // 是否出现在底部的添加组件区域 appendable: false // 是否可以编辑,UMP里面有些地方config是不能编辑的 // editable: true, configurable: false highlightWhenSelect: false // 其他组件; state = value: type: ConfigEditordesignType ...ConfigEditor ; { this; }; { return <div> <DesignWithDnd ref=thissaveDesign cache cacheId="design-test" confirmUnsavedLeave=false components=components value=thisstatevalue onChange=thisonChange globalConfig=window_global /> <Row className="design-example-actions"> <Col span=3 offset=1> <Button type="primary" onClick=thissubmit> 上架 </Button> </Col> </Row> </div> ; } { thisdesign = instance; }; { return thisdesign; } { this ; }; ReactDOM;
如何实现新的 Design 组件
每个 Design 都分为两部分:Preview 以及 Editor。
Preview 比较简单,实现一个组件接受 { value: any, globalConfig: any, design: object }
这些 props即可。
Editor 请继承 zan-design/lib/base/editor/DesignEditor
,这个基类提供了一些常用的方法(例如 onChange
事件的处理函数),在子类里面可以直接使用。
Editor 接受如下props:{ value: any, onChange: func, showError: boolean, validation: object, design object }
。
Editor 必须提供这几个静态属性:designType, designDescription, getInitialValue, validate。
validate(value): Promise
有错误的时候 resolve 一个错误对象出来。
props.design
提供了一下可能有用的方法:例如触发组件的校验等。
一个例子
// Preview; { { const value = thisprops; return <div className="rc-design-component-notice-preview">value</div> ; }} // Editor;; ; const PLACEHOLDER = '请填写内容,如果过长,将会在手机上滚动显示'; { const value showError validation = thisprops; return <div className="rc-design-component-notice-editor"> <ControlGroup label="公告:" required showError=showError || this error=validationcontent > <Input name="content" placeholder=PLACEHOLDER value=valuecontent onChange=thisonInputChange onBlur=thisonInputBlur /> </ControlGroup> </div> ; } static designType = 'notice'; static designDescription = '公告'; static { return content: '' scrollable: false ; } static { return { const errors = {}; const content = value; if !content || !content errorscontent = '请填写公告内容'; ; }; }
更新日志
4.7.16 (2018-01-18)
- [bug fix] link 组件不支持微页面及商品
4.6.13 (2017-12-14)
- [bug fix] 富文本组件在上传视频之后在 preview 层无法展示的问题
4.6.6 (2017-12-01)
- [bug fix] 秒杀组件展示问题及图片广告组件去掉链接校验
4.4.8 (2017-11-09)
- [bug fix] audio 组件可配置 upload 的参数
4.3.10 (2017-10-28)
- [bug fix] 更正图片广告组件 preview 不能轮播的问题