cloud-b2b 1.1.46 → 1.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/package.json +44 -22
  2. package/src/Area/Area.js +94 -0
  3. package/src/Card/Card.js +16 -0
  4. package/src/CodeInput/CodeInput.js +76 -0
  5. package/src/Control/Control.js +338 -0
  6. package/src/Control/event.js +45 -0
  7. package/src/Enhance/Dialogs.js +24 -0
  8. package/src/Enhance/Loading.js +83 -0
  9. package/{es → src}/Enhance/index.js +8 -6
  10. package/src/Header/Header.js +149 -0
  11. package/src/Header/Vertical.js +74 -0
  12. package/src/ImageView/ImageView.js +62 -0
  13. package/src/Indent/Indent.js +12 -0
  14. package/src/InpurCascader/InputCascader.js +83 -0
  15. package/src/InputEditor/InputEditor.js +93 -0
  16. package/src/InputSearch/InputSearch.js +186 -0
  17. package/src/InputSelect/InputSelect.js +103 -0
  18. package/src/InputTreeSelect/InputTreeSelect.js +87 -0
  19. package/src/InputTreeSelect/package.json +6 -0
  20. package/src/InputWriting/InputWriting.js +65 -0
  21. package/src/Layout/Layout.js +121 -0
  22. package/src/LayoutLink/LayoutLink.js +59 -0
  23. package/src/Link/Link.js +57 -0
  24. package/src/Loading/Loading.js +15 -0
  25. package/src/Loading2/Loading2.js +15 -0
  26. package/src/ModalWithDrag/ModalWithDrag.js +17 -0
  27. package/{es → src}/ModalWithDrag/drag.js +128 -116
  28. package/src/NumberInput/NumberInput.js +137 -0
  29. package/src/Search/Search.js +368 -0
  30. package/src/Sidebar/Sidebar.js +111 -0
  31. package/src/Sidebar2/Sidebar.js +143 -0
  32. package/src/SuperForm/SuperForm.js +516 -0
  33. package/src/SuperForm2/SuperForm.js +588 -0
  34. package/src/SuperIcon/SuperIcon.js +14 -0
  35. package/src/SuperPagination/SuperPagination.js +65 -0
  36. package/src/SuperTab/SuperTab.js +84 -0
  37. package/src/SuperTab2/SuperTab2.js +94 -0
  38. package/src/SuperTable/DragSortRow.js +62 -0
  39. package/src/SuperTable/FilterDropDown.js +111 -0
  40. package/src/SuperTable/SuperTable.js +590 -0
  41. package/src/SuperTable/fixed.js +34 -0
  42. package/src/SuperTable2/SuperTable2.js +600 -0
  43. package/src/SuperTable2/SuperTableCell.js +144 -0
  44. package/src/SuperTable3/FilterDropDown.js +111 -0
  45. package/src/SuperTable3/SuperTable.js +498 -0
  46. package/src/SuperTable3/fixed.js +34 -0
  47. package/src/SuperToolbar/SuperToolbar.js +128 -0
  48. package/src/SuperUpload/SuperUpload.js +137 -0
  49. package/src/Title/Title.js +18 -0
  50. package/src/Viewer/ImageViews.js +220 -0
  51. package/src/Viewer/Viewer.js +97 -0
  52. package/src/WingBlank/WingBlank.js +14 -0
  53. package/src/helper.js +185 -0
  54. package/{es → src}/history.js +6 -6
  55. package/src/index.js +38 -0
  56. package/src/variables.js +5 -0
  57. package/test/index.html +10 -0
  58. package/test/test.js +16 -0
  59. package/test/test.less +12 -0
  60. package/test/webpack.config.js +71 -0
  61. package/tools/babel.config.js +14 -0
  62. package/tools/build.js +70 -0
  63. package/tools/publish.js +9 -0
  64. package/tools/util.js +53 -0
  65. package/es/Area/Area.js +0 -141
  66. package/es/Card/Card.js +0 -19
  67. package/es/CodeInput/CodeInput.js +0 -123
  68. package/es/Control/Control.js +0 -437
  69. package/es/Control/event.js +0 -43
  70. package/es/Enhance/Dialogs.js +0 -52
  71. package/es/Enhance/Loading.js +0 -131
  72. package/es/Header/Header.js +0 -162
  73. package/es/Header/Vertical.js +0 -106
  74. package/es/ImageView/ImageView.js +0 -100
  75. package/es/Indent/Indent.js +0 -19
  76. package/es/InpurCascader/InputCascader.js +0 -109
  77. package/es/InputEditor/InputEditor.js +0 -114
  78. package/es/InputSearch/InputSearch.js +0 -266
  79. package/es/InputSelect/InputSelect.js +0 -160
  80. package/es/InputWriting/InputWriting.js +0 -85
  81. package/es/Layout/Layout.js +0 -201
  82. package/es/LayoutLink/LayoutLink.js +0 -73
  83. package/es/Link/Link.js +0 -85
  84. package/es/Loading/Loading.js +0 -13
  85. package/es/Loading2/Loading2.js +0 -9
  86. package/es/ModalWithDrag/ModalWithDrag.js +0 -29
  87. package/es/NumberInput/NumberInput.js +0 -200
  88. package/es/Search/Search.js +0 -485
  89. package/es/Sidebar/Sidebar.js +0 -144
  90. package/es/Sidebar2/Sidebar.js +0 -165
  91. package/es/SuperForm/SuperForm.js +0 -583
  92. package/es/SuperForm2/SuperForm.js +0 -677
  93. package/es/SuperIcon/SuperIcon.js +0 -27
  94. package/es/SuperPagination/SuperPagination.js +0 -109
  95. package/es/SuperTab/SuperTab.js +0 -107
  96. package/es/SuperTab2/SuperTab2.js +0 -145
  97. package/es/SuperTable/DragSortRow.js +0 -97
  98. package/es/SuperTable/FilterDropDown.js +0 -164
  99. package/es/SuperTable/SuperTable.js +0 -808
  100. package/es/SuperTable/fixed.js +0 -34
  101. package/es/SuperTable2/SuperTable2.js +0 -894
  102. package/es/SuperTable2/SuperTableCell.js +0 -198
  103. package/es/SuperTable3/FilterDropDown.js +0 -164
  104. package/es/SuperTable3/SuperTable.js +0 -665
  105. package/es/SuperTable3/fixed.js +0 -34
  106. package/es/SuperToolbar/SuperToolbar.js +0 -195
  107. package/es/SuperUpload/SuperUpload.js +0 -357
  108. package/es/Title/Title.js +0 -33
  109. package/es/Viewer/ImageViews.js +0 -258
  110. package/es/Viewer/Viewer.js +0 -122
  111. package/es/WingBlank/WingBlank.js +0 -16
  112. package/es/helper.js +0 -147
  113. package/es/index.js +0 -37
  114. package/es/variables.js +0 -4
  115. package/lib/Area/Area.js +0 -150
  116. package/lib/Area/package.json +0 -6
  117. package/lib/Card/Card.js +0 -28
  118. package/lib/Card/package.json +0 -6
  119. package/lib/CodeInput/CodeInput.js +0 -132
  120. package/lib/CodeInput/package.json +0 -6
  121. package/lib/Control/Control.js +0 -446
  122. package/lib/Control/event.js +0 -52
  123. package/lib/Control/package.json +0 -6
  124. package/lib/Enhance/Dialogs.js +0 -61
  125. package/lib/Enhance/Loading.js +0 -139
  126. package/lib/Enhance/index.js +0 -26
  127. package/lib/Enhance/package.json +0 -6
  128. package/lib/Header/Header.js +0 -170
  129. package/lib/Header/Header.less +0 -95
  130. package/lib/Header/Vertical.js +0 -115
  131. package/lib/Header/Vertical.less +0 -60
  132. package/lib/Header/package.json +0 -6
  133. package/lib/ImageView/ImageView.js +0 -109
  134. package/lib/ImageView/ImageView.less +0 -14
  135. package/lib/ImageView/package.json +0 -6
  136. package/lib/Indent/Indent.js +0 -28
  137. package/lib/Indent/package.json +0 -6
  138. package/lib/InpurCascader/InputCascader.js +0 -117
  139. package/lib/InpurCascader/package.json +0 -6
  140. package/lib/InputEditor/InputEditor.js +0 -123
  141. package/lib/InputEditor/inputEditor.less +0 -8
  142. package/lib/InputEditor/package.json +0 -6
  143. package/lib/InputSearch/InputSearch.js +0 -275
  144. package/lib/InputSearch/package.json +0 -6
  145. package/lib/InputSelect/InputSelect.js +0 -169
  146. package/lib/InputSelect/package.json +0 -6
  147. package/lib/InputWriting/InputWriting.js +0 -94
  148. package/lib/InputWriting/package.json +0 -6
  149. package/lib/Layout/Layout.js +0 -210
  150. package/lib/Layout/Layout.less +0 -28
  151. package/lib/Layout/package.json +0 -6
  152. package/lib/LayoutLink/LayoutLink.js +0 -87
  153. package/lib/LayoutLink/LayoutLink.less +0 -53
  154. package/lib/LayoutLink/package.json +0 -6
  155. package/lib/Link/Link.js +0 -94
  156. package/lib/Link/package.json +0 -6
  157. package/lib/Loading/Loading.js +0 -22
  158. package/lib/Loading/Loading.less +0 -13
  159. package/lib/Loading/package.json +0 -6
  160. package/lib/Loading2/Loading2.js +0 -18
  161. package/lib/Loading2/Loading2.less +0 -19
  162. package/lib/Loading2/package.json +0 -6
  163. package/lib/ModalWithDrag/ModalWithDrag.js +0 -38
  164. package/lib/ModalWithDrag/ModalWithDrag.less +0 -6
  165. package/lib/ModalWithDrag/drag.js +0 -125
  166. package/lib/ModalWithDrag/package.json +0 -6
  167. package/lib/NumberInput/NumberInput.js +0 -209
  168. package/lib/NumberInput/package.json +0 -6
  169. package/lib/Search/Search.js +0 -499
  170. package/lib/Search/Search.less +0 -63
  171. package/lib/Search/package.json +0 -6
  172. package/lib/Sidebar/Sidebar.js +0 -153
  173. package/lib/Sidebar/Sidebar.less +0 -78
  174. package/lib/Sidebar/package.json +0 -6
  175. package/lib/Sidebar2/Sidebar.js +0 -174
  176. package/lib/Sidebar2/Sidebar.less +0 -153
  177. package/lib/Sidebar2/package.json +0 -6
  178. package/lib/SuperForm/SuperForm.js +0 -596
  179. package/lib/SuperForm/SuperForm.less +0 -52
  180. package/lib/SuperForm/package.json +0 -6
  181. package/lib/SuperForm2/SuperForm.js +0 -690
  182. package/lib/SuperForm2/SuperForm.less +0 -52
  183. package/lib/SuperForm2/package.json +0 -6
  184. package/lib/SuperIcon/SuperIcon.js +0 -36
  185. package/lib/SuperIcon/package.json +0 -6
  186. package/lib/SuperPagination/SuperPagination.js +0 -118
  187. package/lib/SuperPagination/package.json +0 -6
  188. package/lib/SuperTab/SuperTab.js +0 -116
  189. package/lib/SuperTab/SuperTab.less +0 -43
  190. package/lib/SuperTab/package.json +0 -6
  191. package/lib/SuperTab2/SuperTab2.js +0 -154
  192. package/lib/SuperTab2/SuperTab2.less +0 -18
  193. package/lib/SuperTab2/package.json +0 -6
  194. package/lib/SuperTable/DragSortRow.js +0 -106
  195. package/lib/SuperTable/DragSortRow.less +0 -17
  196. package/lib/SuperTable/FilterDropDown.js +0 -173
  197. package/lib/SuperTable/FilterDropDown.less +0 -30
  198. package/lib/SuperTable/SuperTable.js +0 -817
  199. package/lib/SuperTable/SuperTable.less +0 -132
  200. package/lib/SuperTable/fixed.js +0 -43
  201. package/lib/SuperTable/package.json +0 -6
  202. package/lib/SuperTable2/SuperTable2.js +0 -908
  203. package/lib/SuperTable2/SuperTable2.less +0 -118
  204. package/lib/SuperTable2/SuperTableCell.js +0 -204
  205. package/lib/SuperTable2/package.json +0 -6
  206. package/lib/SuperTable3/FilterDropDown.js +0 -173
  207. package/lib/SuperTable3/FilterDropDown.less +0 -29
  208. package/lib/SuperTable3/SuperTable.js +0 -674
  209. package/lib/SuperTable3/SuperTable.less +0 -99
  210. package/lib/SuperTable3/fixed.js +0 -43
  211. package/lib/SuperTable3/package.json +0 -6
  212. package/lib/SuperToolbar/SuperToolbar.js +0 -204
  213. package/lib/SuperToolbar/SuperToolbar.less +0 -17
  214. package/lib/SuperToolbar/package.json +0 -6
  215. package/lib/SuperUpload/SuperUpload.js +0 -370
  216. package/lib/SuperUpload/SuperUpload.less +0 -28
  217. package/lib/SuperUpload/package.json +0 -6
  218. package/lib/Title/Title.js +0 -42
  219. package/lib/Title/Title.less +0 -35
  220. package/lib/Title/package.json +0 -6
  221. package/lib/Viewer/ImageViews.js +0 -267
  222. package/lib/Viewer/Viewer.js +0 -131
  223. package/lib/Viewer/Viewer.less +0 -67
  224. package/lib/Viewer/imgView.less +0 -59
  225. package/lib/Viewer/package.json +0 -7
  226. package/lib/WingBlank/WingBlank.js +0 -25
  227. package/lib/WingBlank/WingBlank.less +0 -12
  228. package/lib/WingBlank/package.json +0 -6
  229. package/lib/adjust.less +0 -89
  230. package/lib/helper.js +0 -163
  231. package/lib/history.js +0 -13
  232. package/lib/index.js +0 -271
  233. package/lib/index.less +0 -31
  234. package/lib/style.less +0 -30
  235. package/lib/variables.js +0 -12
  236. package/lib/variables.less +0 -73
  237. /package/{es → src}/Area/package.json +0 -0
  238. /package/{es → src}/Card/package.json +0 -0
  239. /package/{es → src}/CodeInput/package.json +0 -0
  240. /package/{es → src}/Control/package.json +0 -0
  241. /package/{es → src}/Enhance/package.json +0 -0
  242. /package/{es → src}/Header/Header.less +0 -0
  243. /package/{es → src}/Header/Vertical.less +0 -0
  244. /package/{es → src}/Header/package.json +0 -0
  245. /package/{es → src}/ImageView/ImageView.less +0 -0
  246. /package/{es → src}/ImageView/package.json +0 -0
  247. /package/{es → src}/Indent/package.json +0 -0
  248. /package/{es → src}/InpurCascader/package.json +0 -0
  249. /package/{es → src}/InputEditor/inputEditor.less +0 -0
  250. /package/{es → src}/InputEditor/package.json +0 -0
  251. /package/{es → src}/InputSearch/package.json +0 -0
  252. /package/{es → src}/InputSelect/package.json +0 -0
  253. /package/{es → src}/InputWriting/package.json +0 -0
  254. /package/{es → src}/Layout/Layout.less +0 -0
  255. /package/{es → src}/Layout/package.json +0 -0
  256. /package/{es → src}/LayoutLink/LayoutLink.less +0 -0
  257. /package/{es → src}/LayoutLink/package.json +0 -0
  258. /package/{es → src}/Link/package.json +0 -0
  259. /package/{es → src}/Loading/Loading.less +0 -0
  260. /package/{es → src}/Loading/package.json +0 -0
  261. /package/{es → src}/Loading2/Loading2.less +0 -0
  262. /package/{es → src}/Loading2/package.json +0 -0
  263. /package/{es → src}/ModalWithDrag/ModalWithDrag.less +0 -0
  264. /package/{es → src}/ModalWithDrag/package.json +0 -0
  265. /package/{es → src}/NumberInput/package.json +0 -0
  266. /package/{es → src}/Search/Search.less +0 -0
  267. /package/{es → src}/Search/package.json +0 -0
  268. /package/{es → src}/Sidebar/Sidebar.less +0 -0
  269. /package/{es → src}/Sidebar/package.json +0 -0
  270. /package/{es → src}/Sidebar2/Sidebar.less +0 -0
  271. /package/{es → src}/Sidebar2/package.json +0 -0
  272. /package/{es → src}/SuperForm/SuperForm.less +0 -0
  273. /package/{es → src}/SuperForm/package.json +0 -0
  274. /package/{es → src}/SuperForm2/SuperForm.less +0 -0
  275. /package/{es → src}/SuperForm2/package.json +0 -0
  276. /package/{es → src}/SuperIcon/package.json +0 -0
  277. /package/{es → src}/SuperPagination/package.json +0 -0
  278. /package/{es → src}/SuperTab/SuperTab.less +0 -0
  279. /package/{es → src}/SuperTab/package.json +0 -0
  280. /package/{es → src}/SuperTab2/SuperTab2.less +0 -0
  281. /package/{es → src}/SuperTab2/package.json +0 -0
  282. /package/{es → src}/SuperTable/DragSortRow.less +0 -0
  283. /package/{es → src}/SuperTable/FilterDropDown.less +0 -0
  284. /package/{es → src}/SuperTable/SuperTable.less +0 -0
  285. /package/{es → src}/SuperTable/package.json +0 -0
  286. /package/{es → src}/SuperTable2/SuperTable2.less +0 -0
  287. /package/{es → src}/SuperTable2/package.json +0 -0
  288. /package/{es → src}/SuperTable3/FilterDropDown.less +0 -0
  289. /package/{es → src}/SuperTable3/SuperTable.less +0 -0
  290. /package/{es → src}/SuperTable3/package.json +0 -0
  291. /package/{es → src}/SuperToolbar/SuperToolbar.less +0 -0
  292. /package/{es → src}/SuperToolbar/package.json +0 -0
  293. /package/{es → src}/SuperUpload/SuperUpload.less +0 -0
  294. /package/{es → src}/SuperUpload/package.json +0 -0
  295. /package/{es → src}/Title/Title.less +0 -0
  296. /package/{es → src}/Title/package.json +0 -0
  297. /package/{es → src}/Viewer/Viewer.less +0 -0
  298. /package/{es → src}/Viewer/imgView.less +0 -0
  299. /package/{es → src}/Viewer/package.json +0 -0
  300. /package/{es → src}/WingBlank/WingBlank.less +0 -0
  301. /package/{es → src}/WingBlank/package.json +0 -0
  302. /package/{es → src}/adjust.less +0 -0
  303. /package/{es → src}/style.less +0 -0
  304. /package/{es → src}/variables.less +0 -0
@@ -0,0 +1,516 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ReactDOM from 'react-dom';
4
+ import helper from '../helper';
5
+ import Control, {getTitle, makeString} from '../Control';
6
+ import {Icon, Form, Row, Col,Checkbox} from 'antd';
7
+ import variables from '../variables';
8
+
9
+ const FormItem = Form.Item;
10
+ const defaultSize = 'small';
11
+ const defaultColNum = 4;
12
+
13
+ const TYPE = [
14
+ 'readonly',
15
+ 'text',
16
+ 'search',
17
+ 'searchText',
18
+ 'select',
19
+ 'selectText',
20
+ 'radioGroup',
21
+ 'number',
22
+ 'date',
23
+ 'textArea',
24
+ 'password',
25
+ 'editor',
26
+ 'selectWriting',
27
+ 'selectSearch',
28
+ 'empty',
29
+ 'area',
30
+ 'uploadImg',
31
+ 'cascader',
32
+ 'treeSelect'
33
+ ];
34
+
35
+ /**
36
+ * key:[必须],用于唯一标识该Form下的一个表单元素
37
+ * title:[必须],表单元素的标签
38
+ * type:[必须],表单元素类型
39
+ * required: [可选],是否为必填项
40
+ * options: [可选],对象数组(type为readonly,radio,search, searchText,select, selectText时有效)
41
+ * span: [可选],占据的列数,默认为1
42
+ * showAdd: [可选],是否显示+号,点击+号会触发onAdd事件,默认为false
43
+ * rule: [可选],用于设置校验规则
44
+ * highLightKeys: [可选],用于设置高亮样式,仅只读字段生效
45
+ */
46
+ const ControlType = {
47
+ key: PropTypes.string.isRequired,
48
+ title: PropTypes.string,
49
+ type: PropTypes.oneOf(TYPE).isRequired,
50
+ required: PropTypes.bool,
51
+ options: PropTypes.array,
52
+ span: PropTypes.number,
53
+ onCheckItem: PropTypes.any,
54
+ showAdd: PropTypes.any,
55
+ rule: PropTypes.object,
56
+ props: PropTypes.object
57
+ };
58
+
59
+ class Controlled extends React.Component {
60
+ constructor(props) {
61
+ super(props);
62
+ this.state = {value: props.value};
63
+ }
64
+
65
+ componentWillReceiveProps(nextProps) {
66
+ if (this.props.value !== nextProps.value) {
67
+ this.setState({value: nextProps.value});
68
+ }
69
+ }
70
+
71
+ onChange = (value) => {
72
+ const {onChange} = this.props;
73
+ this.setState({value});
74
+ onChange && onChange(value);
75
+ };
76
+
77
+ render() {
78
+ const props = {
79
+ ...this.props,
80
+ value: this.state.value,
81
+ onChange: this.onChange
82
+ };
83
+ return <Control {...props} />;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * colNum:[可选],表单的列数,默认为4
89
+ * readonly: [可选],为true时,所有表单元素都是只读的; 为字符串数组时,用于指定key的表单元素是只读的
90
+ * hideControls: [可选],指定key的表单元素被隐藏
91
+ * options: [可选],键值对,值与ControlType中options作用相同,但优先级更高
92
+ * onChange:内容改变时触发,原型为func(key, value)
93
+ * onSearch:搜索框中用户输入时触发,原型为func(key, title, control)
94
+ * onAdd: 点击+号时触发,原型为func(key)
95
+ * checkable:是否显示checkbox选择框
96
+ * onOpenChange:控制日期框显示隐藏回调func(key, open)
97
+ * onAreaSearch:联级选择器触发,原型为func(key - 当前联级key, title - 输入值, parentKey - 主体联级key)
98
+ * OnFileChange:上传组件触发,原型为func(key,{fileList, fileDeleteList})
99
+ */
100
+ class SuperForm extends React.Component {
101
+ static propTypes = {
102
+ controls: PropTypes.arrayOf(PropTypes.shape(ControlType)).isRequired,
103
+ value: PropTypes.object,
104
+ colNum: PropTypes.number,
105
+ valid: PropTypes.bool,
106
+ readonly: PropTypes.oneOfType([PropTypes.bool, PropTypes.array]),
107
+ hideControls: PropTypes.array,
108
+ options: PropTypes.object,
109
+ onChange: PropTypes.func,
110
+ onSearch: PropTypes.func,
111
+ onExitValid: PropTypes.func,
112
+ onAdd: PropTypes.func,
113
+ checkable: PropTypes.bool,
114
+ onOpenChange: PropTypes.func,
115
+ onAreaSearch: PropTypes.func,
116
+ OnFileChange: PropTypes.func
117
+ };
118
+
119
+ onAdd = (key, title) => {
120
+ const {onAdd} = this.props;
121
+ onAdd && onAdd(key, title);
122
+ };
123
+
124
+ onChange = (key, value) => {
125
+ const {onChange} = this.props;
126
+ if (onChange) {
127
+ this.onExitValid(key);
128
+ onChange(key, value);
129
+ }
130
+ };
131
+
132
+ onBlur = (key, value) => {
133
+ const {onChange} = this.props;
134
+ if (onChange) {
135
+ this.onExitValid(key);
136
+ onChange(key, value);
137
+ }
138
+ };
139
+
140
+ onExitValid = (key,value) => {
141
+ if (key === this.validKey) {
142
+ this.validKey = '';
143
+ this.props.onExitValid();
144
+ }
145
+ this.props.onChangeOperate && this.props.onChangeOperate(key,value);
146
+ };
147
+
148
+ // 动态生成getValidState方法
149
+ initValidState = () => {
150
+ const {value, valid} = this.props;
151
+ const invalid = () => null;
152
+ const _valid = ({key, required}) => {
153
+ if (required) {
154
+ if (!value || helper.isEmpty2(value[key]) || ( !Array.isArray(value[key]) && typeof value[key] === 'object' && helper.isEmpty(value[key].value))) {
155
+ this.getValidState = invalid;
156
+ this.validKey = key;
157
+ return 'error';
158
+ }
159
+ }
160
+ return null;
161
+ };
162
+ this.getValidState = valid ? _valid : invalid;
163
+ };
164
+
165
+ validDate = ({key, type}) => (date) => {
166
+ const {value={}} = this.props;
167
+ if (!date || !value[key]) {
168
+ return false;
169
+ } else {
170
+ if (type === '>') {
171
+ return date.format('YYYY-MM-DD') <= value[key];
172
+ } else if (type === '<') {
173
+ return date.format('YYYY-MM-DD') >= value[key];
174
+ } else {
175
+ return false;
176
+ }
177
+ }
178
+ };
179
+
180
+ getPopupContainer = () => {
181
+ const {container} = this.props;
182
+ if (typeof container === 'undefined') {
183
+ return ReactDOM.findDOMNode(this);
184
+ } else if (typeof container === 'boolean') {
185
+ return document.body;
186
+ } else {
187
+ return ReactDOM.findDOMNode(container);
188
+ }
189
+ };
190
+
191
+ getMaxWidth = () => {
192
+ const {colNum=defaultColNum} = this.props;
193
+ return colNum * 250;
194
+ };
195
+
196
+ getContainer = () => {
197
+ return this.props.getContainer;
198
+ };
199
+
200
+ getControls = () => {
201
+ const {hideControls, controls} = this.props;
202
+ if (!hideControls) {
203
+ return controls;
204
+ } else {
205
+ return controls.filter(control => !hideControls.some(key => control.key === key));
206
+ }
207
+ };
208
+
209
+ getType = ({key, type}) => {
210
+ const {readonly} = this.props;
211
+ if (['area', 'uploadImg'].includes(type)){
212
+ return type;
213
+ }else if (!readonly) {
214
+ return type;
215
+ } else if (readonly === true) {
216
+ return 'readonly';
217
+ } else if (Array.isArray(readonly) && readonly.some(readonlyKey => readonlyKey === key)) {
218
+ return 'readonly';
219
+ } else {
220
+ return type;
221
+ }
222
+ };
223
+
224
+ specialProps = (type, {key, props={}, type:originType}) => {
225
+ if (type === 'readonly') {
226
+ const {highLightKeys=[]} = this.props;
227
+ const style = highLightKeys.includes(key) ? {backgroundColor: 'red', color: 'white'} : {backgroundColor: '#f0f0f0'};
228
+ if (originType === 'textArea') {
229
+ return {
230
+ type: 'textArea',
231
+ readonly: true,
232
+ style,
233
+ onBlur: this.onExitValid.bind(this, key)
234
+ }
235
+ } else {
236
+ return {
237
+ style,
238
+ onBlur: this.onExitValid.bind(this, key)
239
+ };
240
+ }
241
+ } else if (type === 'text' || type === 'textArea') {
242
+ return {
243
+ ...props,
244
+ onChange: this.onExitValid.bind(this, key),
245
+ onBlur: this.onChange.bind(this, key)
246
+ }
247
+ } else if (type === 'date') {
248
+ const propsObj = {
249
+ ...props,
250
+ onChange: this.onBlur.bind(this, key),
251
+ onBlur: this.onExitValid.bind(this, key)
252
+ };
253
+ if (this.props.onOpenChange && typeof this.props.onOpenChange === 'function') {
254
+ propsObj.onOpenChange = this.props.onOpenChange.bind(this, key);
255
+ }
256
+ return propsObj;
257
+ }else if (type === 'area'){
258
+ return {
259
+ ...props,
260
+ onChange: this.onBlur.bind(this, key),
261
+ onBlur: this.onExitValid.bind(this, key),
262
+ onAreaSearch: this.props.onAreaSearch
263
+ }
264
+ } else {
265
+ return {
266
+ ...props,
267
+ onChange: this.onBlur.bind(this, key),
268
+ onBlur: this.onExitValid.bind(this, key)
269
+ };
270
+ }
271
+ };
272
+
273
+ getControlProps = (control, status) => {
274
+ const {value={}} = this.props;
275
+ const type = this.getType(control);
276
+ const props = this.specialProps(type, control);
277
+ return {
278
+ autoFocus: !!status,
279
+ type, ...props,
280
+ size: defaultSize,
281
+ value: makeString(value[control.key])
282
+ };
283
+ };
284
+
285
+ getOptions = (key, options) => {
286
+ const higher = this.props.options || {};
287
+ return higher[key] || options;
288
+ };
289
+
290
+ toEmpty = (props) => {
291
+
292
+ };
293
+
294
+ toText = (props) => {
295
+ return <Controlled {...props} />;
296
+ };
297
+
298
+ toPassword = (props) => {
299
+ return <Controlled {...props} />;
300
+ };
301
+
302
+ toEditor = (props,control) => {
303
+ props.inputKey =control.key
304
+ return <Controlled {...props} />;
305
+ };
306
+
307
+ toSelectWriting = (props,control) => {
308
+ return <Controlled {...props} />;
309
+ };
310
+
311
+
312
+ toTextArea = (props, control) => {
313
+ if(control.allFullFather){
314
+ props.rows = control.rows;
315
+ props.maxLength = control.maxLength;
316
+ props.style = {
317
+ 'resize': 'none'
318
+ };
319
+ }else{
320
+ props.autoSize = {minRows: 1, maxRows: 5};
321
+ }
322
+ return <Controlled {...props} />;
323
+ };
324
+
325
+ toNumber = (props) => {
326
+ props.defaultValue = props.value;
327
+ delete props.value;
328
+ return <Control {...props} />;
329
+ };
330
+
331
+ toSelect = (props, {options, key}) => {
332
+ props.getPopupContainer = this.getPopupContainer;
333
+ props.options = this.getOptions(key, options);
334
+ props.dropdownMatchSelectWidth = false;
335
+ return <Control {...props} />;
336
+ };
337
+
338
+ createSearchEvent = (control) => {
339
+ if (this.props.onSearch) {
340
+ return value => this.props.onSearch(control.key, value, control);
341
+ } else {
342
+ return null;
343
+ }
344
+ };
345
+
346
+ toSearch = (props, control) => {
347
+ props.getPopupContainer = this.getPopupContainer;
348
+ props.options = this.getOptions(control.key, control.options);
349
+ props.onSearch = this.createSearchEvent(control);
350
+ props.dropdownMatchSelectWidth = false;
351
+ return <Control {...props} />;
352
+ };
353
+
354
+ toDate = (props, {rule}) => {
355
+ props.getCalendarContainer = this.getPopupContainer;
356
+ props.style = {width: '100%'};
357
+ rule && (props.disabledDate = this.validDate(rule));
358
+ return <Control {...props} />;
359
+ };
360
+
361
+ toRadioGroup = (props, {key, options}) => {
362
+ props.options = this.getOptions(key, options);
363
+ return <Control {...props} />;
364
+ };
365
+
366
+ toReadonly = (props, {options, key}) => {
367
+ props.value = getTitle(props.value, this.getOptions(key, options));
368
+ return <Control {...props} />;
369
+ };
370
+
371
+ selectSearch = (props, control) => {
372
+ props.getPopupContainer = this.getPopupContainer;
373
+ props.options = this.getOptions(control.key, control.options);
374
+ props.onSearch = this.createSearchEvent(control);
375
+ props.dropdownMatchSelectWidth = false;
376
+ return <Control {...props} />;
377
+ };
378
+
379
+ area = (props, {key,options}) => {
380
+ const {readonly} = this.props;
381
+ props.parentKey = key;
382
+ props.options = this.getOptions(key, options);
383
+ props.dropdownMatchSelectWidth = false;
384
+ props.readonly = readonly === true || Array.isArray(readonly) && readonly.some(readonlyKey => readonlyKey === key) ? true : false;
385
+ return <Control {...props} />;
386
+ };
387
+
388
+ uploadImg = (props, control) => {
389
+ const {readonly} = this.props;
390
+ props.required = control.required || false;
391
+ props.onFileChange = this.onFileChange.bind(this,control);
392
+ props.readonly = readonly === true || Array.isArray(readonly) && readonly.some(readonlyKey => readonlyKey === control.key) ? true : false;
393
+ return <Control {...props} />
394
+ };
395
+
396
+ toCascader = (props, control) => {
397
+ const container = this.getContainer();
398
+ container && (props.getPopupContainer = container);
399
+ props.options = control.options || [];
400
+ props.onSearch = this.createSearchEvent(control);
401
+ props.placeholder = props.placeholder || '';
402
+ props.loadData = this.createSearchEvent(control);
403
+ return <Control {...props} />;
404
+ };
405
+
406
+ toTreeSelect = (props,filter) => {
407
+ const container = this.getContainer();
408
+ container && (props.getPopupContainer = container);
409
+ props.options = this.getOptions(filter);
410
+ props.onSearch = this.createSearchEvent(filter);
411
+ props.placeholder = filter.placeholder || '';
412
+ return <Control {...props} />;
413
+ };
414
+ toControl = (props, control) => {
415
+ switch (props.type) {
416
+ case 'readonly':
417
+ return this.toReadonly(props, control);
418
+ case 'text':
419
+ return this.toText(props, control);
420
+ case 'number':
421
+ return this.toNumber(props, control);
422
+ case 'select':
423
+ case 'selectText':
424
+ return this.toSelect(props, control);
425
+ case 'search':
426
+ case 'searchText':
427
+ return this.toSearch(props, control);
428
+ case 'date':
429
+ return this.toDate(props, control);
430
+ case 'radioGroup':
431
+ return this.toRadioGroup(props, control);
432
+ case 'textArea':
433
+ return this.toTextArea(props, control);
434
+ case 'password':
435
+ return this.toPassword(props, control);
436
+ case 'editor':
437
+ return this.toEditor(props, control);
438
+ case 'selectWriting' :
439
+ return this.toSelectWriting(props,control)
440
+ case 'selectSearch':
441
+ return this.selectSearch(props, control);
442
+ case 'empty':
443
+ return this.toEmpty(props, control);
444
+ case 'area':
445
+ return this.area(props, control);
446
+ case 'uploadImg':
447
+ return this.uploadImg(props, control);
448
+ case 'cascader':
449
+ return this.toCascader(props, control);
450
+ case 'treeSelect':
451
+ return this.toTreeSelect(props, control);
452
+ default:
453
+ return 'type error';
454
+ }
455
+ };
456
+
457
+ toLabel = ({title, showAdd, key}, type) => {
458
+ if (showAdd && (type !== 'readonly')) {
459
+ const onClick = this.onAdd.bind(this, key, title);
460
+ return <span>{title}<Icon role='add' type='plus-circle-o' onClick={onClick}/></span>;
461
+ } else {
462
+ return title;
463
+ }
464
+ };
465
+
466
+ toCol = (span, control) => {
467
+ const factor = control.span || 1;
468
+ const status = this.getValidState(control);
469
+ const controlProps = this.getControlProps(control, status);
470
+ const itemProps = {
471
+ label: this.toLabel(control, controlProps.type),
472
+ required: control.required,
473
+ validateStatus: status
474
+ };
475
+ const {checkable,onCheckItem} = this.props;
476
+ return control.type !== 'empty' ? (
477
+ <Col span={span * factor} key={control.key}>
478
+ {checkable && <Checkbox className={variables('SuperForm').checkbox} onChange={onCheckItem.bind(this,control)} checked={control.checked} />}
479
+ <FormItem {...itemProps} className={checkable ? variables('SuperForm').formItemWithCheckbox : ''}>
480
+ {this.toControl(controlProps, control)}
481
+ </FormItem>
482
+ </Col>
483
+ ) : (
484
+ <Col span={span * factor} key={control.key} style={{height: '44px'}}/>
485
+ );
486
+ };
487
+
488
+ toCols = () => {
489
+ let {colNum=defaultColNum,allFullFather} = this.props;
490
+ if(allFullFather){
491
+ colNum = 1;
492
+ }
493
+ const span = 24 / colNum;
494
+ return this.getControls().map(control => {
495
+ if(allFullFather){
496
+ control.allFullFather = allFullFather;
497
+ }
498
+ return this.toCol(span, control)
499
+ });
500
+ };
501
+
502
+ render() {
503
+ this.initValidState();
504
+ return (
505
+ <div className={variables('SuperForm')}>
506
+ <Form layout='vertical' style={{maxWidth: this.props.allFullFather ? '100%' : this.getMaxWidth()}}>
507
+ <Row gutter={20}>
508
+ {this.toCols()}
509
+ </Row>
510
+ </Form>
511
+ </div>
512
+ );
513
+ }
514
+ }
515
+
516
+ export default SuperForm;