0.7.3 • Published 4 years ago

antd-page-config v0.7.3

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

antd-page-config

这是通过拖拽组件,配置元素来实现业务级的页面配置。

开始

安装

npm install antd-page-config --save

如何导入

import AntdPageConfig, { transformElements } from 'antd-page-config';
import 'antd-page-config/style/css';

如何使用

// 获取元素Map

let elements
function onSave(elementsMap) {
  elements = elementsMap;
}
<AntdPageConfig onSave={onSave} />

// 渲染

transformElements(elements).map(n => n.render())

// 编辑

<AntdPageConfig defaultElementMap={elements} onSave={onSave} />

如何使用自定义id设置属性

// 使用transformElements第二参数

const expandElementMap = {
  'custom_button': {
    attribute: {
      type: 'primary'
    },
    style: {
      color: 'red',
    },
    className: 'custom_button_class',
  }
}

transformElements(elements,expandElementMap).map(n => n.render())


// 在循环使用render渲染元素时,通过customId设置

transformElements(elements).map(n => {
  if(n.customId === 'custom_button') {
    n.setAttribute({
      type: 'primary'
    })
    n.setClassName('custom_button_class')
    n.setStyle({
      color: 'red'
    })
  }
  return n.render()
})

API

AntdPageConfig

参数说明类型默认值
style样式CSSProperties-
saveable保存按钮是否可见booleantrue
saveText保存按钮文本string'保存'
closeable关闭按钮是否可见booleanfalse
closeText关闭按钮文本string'关闭'
defaultElementMap默认元素集elementMap: ElementMap-
antdTableColumnMode设置Table的Column的模式,可选 input selectstring'input'
antdTableColumnOptionsantdTableColumnMode='select' ,可以设置列的下拉选项ColumnOptions -
onSave按钮保存的回调Function(elementMap: ElementMap)-
onClose按钮关闭的回调Function-
mode配置模式 standardstring-

ConfigurableElement

参数说明类型默认值
id可配置元素的idstring-
tagNamehtml标签和react组件标签string-
type元素的所属类型string-
customId自定义idstring-
element元素ReactNode-
childrenelement的子元素ReactChild | ElementMap | null-
style元素的样式CSSProperties-
className元素的css名string-
attribute元素的属性Attributes-
elementMapAttribute属性映射元素object | null-
dndIncludeAttr在拖拽时的属性object-
layout坐标布局,元素大小object-
containerClassName包裹元素容器的css名string-
dndType拖拽放置的类型string'all'
extraValue额外的数据object-
behave元素的表现形式 block inlinestring-
location最终决定渲染的坐标布局object-
packInsideComp包含内部组件,无需定位booleanfalse
renderHandle渲染时处理方法object-
parent元素属于哪个元素string-
hidden是否隐藏booleanfalse
setStyle设置元素样式Function(style: object)-
setClassName设置元素css名Function(className: string)-
setAttribute设置元素属性Function(attribute: object)-
render渲染元素Function-

ElementMap

参数说明类型默认值
id配置元素以id为key的集合object-

ColumnOptions

参数说明类型默认值
dataIndex列数据在数据项中对应的 keystring-
title列头显示文字string-

常见问题

关于组件样式问题

使用 babel-plugin-import , 没有引入 AntdPageConfig 使用的组件,那会造成样式不生效问题。

使用 import 'antd/dist/antd.css' ,打包程序会出现组件样式重复问题。

综上考虑, 引入 antd 组件方式是按手动按需加载。

那打包组件样式重复的问题怎么解决呢?

建议使用 webpack的分割代码功能,详细代码如下

optimization: {
  splitChunks: {
    cacheGroups: {
      antdUI: {
        name: 'chunk-antd',
        priority: 20,
        test: /[\\/]node_modules[\\/]antd[\\/]/,
      }
    }
  }
}

参与贡献

非常欢迎你的贡献,你可以通过以下方式和我们一起共建:

  • 通过 Issue bug 或进行咨询。
  • 提交 Pull Request 改进代码。
0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

5 years ago

0.3.11

5 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.1

5 years ago