cloud-b2b 1.1.58 → 1.1.59

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 (308) 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/InputWriting/InputWriting.js +65 -0
  20. package/src/Layout/Layout.js +121 -0
  21. package/src/LayoutLink/LayoutLink.js +59 -0
  22. package/src/Link/Link.js +57 -0
  23. package/src/Loading/Loading.js +15 -0
  24. package/src/Loading2/Loading2.js +15 -0
  25. package/src/ModalWithDrag/ModalWithDrag.js +17 -0
  26. package/{es → src}/ModalWithDrag/drag.js +128 -116
  27. package/src/NumberInput/NumberInput.js +137 -0
  28. package/src/Search/Search.js +368 -0
  29. package/src/Search2/Search.js +436 -0
  30. package/{lib/Search → src/Search2}/Search.less +65 -63
  31. package/{lib/Search → src/Search2}/package.json +6 -6
  32. package/src/Sidebar/Sidebar.js +111 -0
  33. package/src/Sidebar2/Sidebar.js +143 -0
  34. package/src/SuperForm/SuperForm.js +519 -0
  35. package/src/SuperForm2/SuperForm.js +588 -0
  36. package/src/SuperIcon/SuperIcon.js +14 -0
  37. package/src/SuperPagination/SuperPagination.js +65 -0
  38. package/src/SuperTab/SuperTab.js +84 -0
  39. package/src/SuperTab2/SuperTab2.js +94 -0
  40. package/src/SuperTable/DragSortRow.js +62 -0
  41. package/src/SuperTable/FilterDropDown.js +111 -0
  42. package/src/SuperTable/SuperTable.js +590 -0
  43. package/src/SuperTable/fixed.js +34 -0
  44. package/src/SuperTable2/SuperTable2.js +624 -0
  45. package/src/SuperTable2/SuperTableCell.js +175 -0
  46. package/src/SuperTable3/FilterDropDown.js +111 -0
  47. package/src/SuperTable3/SuperTable.js +498 -0
  48. package/src/SuperTable3/fixed.js +34 -0
  49. package/src/SuperToolbar/SuperToolbar.js +128 -0
  50. package/src/SuperUpload/SuperUpload.js +137 -0
  51. package/src/Title/Title.js +18 -0
  52. package/src/Viewer/ImageViews.js +220 -0
  53. package/src/Viewer/Viewer.js +97 -0
  54. package/src/WingBlank/WingBlank.js +14 -0
  55. package/src/helper.js +185 -0
  56. package/{es → src}/history.js +6 -6
  57. package/src/index.js +39 -0
  58. package/src/variables.js +5 -0
  59. package/test/index.html +10 -0
  60. package/test/test.js +16 -0
  61. package/test/test.less +12 -0
  62. package/test/webpack.config.js +71 -0
  63. package/tools/babel.config.js +14 -0
  64. package/tools/build.js +70 -0
  65. package/tools/publish.js +9 -0
  66. package/tools/util.js +53 -0
  67. package/es/Area/Area.js +0 -141
  68. package/es/Card/Card.js +0 -19
  69. package/es/CodeInput/CodeInput.js +0 -123
  70. package/es/Control/Control.js +0 -444
  71. package/es/Control/event.js +0 -43
  72. package/es/Enhance/Dialogs.js +0 -52
  73. package/es/Enhance/Loading.js +0 -131
  74. package/es/Header/Header.js +0 -162
  75. package/es/Header/Vertical.js +0 -106
  76. package/es/ImageView/ImageView.js +0 -100
  77. package/es/Indent/Indent.js +0 -19
  78. package/es/InpurCascader/InputCascader.js +0 -117
  79. package/es/InputEditor/InputEditor.js +0 -173
  80. package/es/InputSearch/InputSearch.js +0 -266
  81. package/es/InputSelect/InputSelect.js +0 -160
  82. package/es/InputTreeSelect/InputTreeSelect.js +0 -121
  83. package/es/InputWriting/InputWriting.js +0 -85
  84. package/es/Layout/Layout.js +0 -201
  85. package/es/LayoutLink/LayoutLink.js +0 -73
  86. package/es/Link/Link.js +0 -85
  87. package/es/Loading/Loading.js +0 -13
  88. package/es/Loading2/Loading2.js +0 -9
  89. package/es/ModalWithDrag/ModalWithDrag.js +0 -29
  90. package/es/NumberInput/NumberInput.js +0 -200
  91. package/es/Search/Search.js +0 -497
  92. package/es/Sidebar/Sidebar.js +0 -144
  93. package/es/Sidebar2/Sidebar.js +0 -165
  94. package/es/SuperForm/SuperForm.js +0 -598
  95. package/es/SuperForm2/SuperForm.js +0 -687
  96. package/es/SuperIcon/SuperIcon.js +0 -27
  97. package/es/SuperPagination/SuperPagination.js +0 -109
  98. package/es/SuperTab/SuperTab.js +0 -107
  99. package/es/SuperTab2/SuperTab2.js +0 -145
  100. package/es/SuperTable/DragSortRow.js +0 -97
  101. package/es/SuperTable/FilterDropDown.js +0 -164
  102. package/es/SuperTable/SuperTable.js +0 -808
  103. package/es/SuperTable/fixed.js +0 -34
  104. package/es/SuperTable2/SuperTable2.js +0 -926
  105. package/es/SuperTable2/SuperTableCell.js +0 -225
  106. package/es/SuperTable3/FilterDropDown.js +0 -164
  107. package/es/SuperTable3/SuperTable.js +0 -665
  108. package/es/SuperTable3/fixed.js +0 -34
  109. package/es/SuperToolbar/SuperToolbar.js +0 -195
  110. package/es/SuperUpload/SuperUpload.js +0 -356
  111. package/es/Title/Title.js +0 -33
  112. package/es/Viewer/ImageViews.js +0 -258
  113. package/es/Viewer/Viewer.js +0 -122
  114. package/es/WingBlank/WingBlank.js +0 -16
  115. package/es/helper.js +0 -240
  116. package/es/index.js +0 -37
  117. package/es/variables.js +0 -6
  118. package/lib/Area/Area.js +0 -149
  119. package/lib/Area/package.json +0 -6
  120. package/lib/Card/Card.js +0 -27
  121. package/lib/Card/package.json +0 -6
  122. package/lib/CodeInput/CodeInput.js +0 -131
  123. package/lib/CodeInput/package.json +0 -6
  124. package/lib/Control/Control.js +0 -450
  125. package/lib/Control/event.js +0 -51
  126. package/lib/Control/package.json +0 -6
  127. package/lib/Enhance/Dialogs.js +0 -60
  128. package/lib/Enhance/Loading.js +0 -138
  129. package/lib/Enhance/index.js +0 -25
  130. package/lib/Enhance/package.json +0 -6
  131. package/lib/Header/Header.js +0 -169
  132. package/lib/Header/Header.less +0 -95
  133. package/lib/Header/Vertical.js +0 -114
  134. package/lib/Header/Vertical.less +0 -60
  135. package/lib/Header/package.json +0 -6
  136. package/lib/ImageView/ImageView.js +0 -108
  137. package/lib/ImageView/ImageView.less +0 -14
  138. package/lib/ImageView/package.json +0 -6
  139. package/lib/Indent/Indent.js +0 -27
  140. package/lib/Indent/package.json +0 -6
  141. package/lib/InpurCascader/InputCascader.js +0 -124
  142. package/lib/InpurCascader/package.json +0 -6
  143. package/lib/InputEditor/InputEditor.js +0 -181
  144. package/lib/InputEditor/inputEditor.less +0 -8
  145. package/lib/InputEditor/package.json +0 -6
  146. package/lib/InputSearch/InputSearch.js +0 -274
  147. package/lib/InputSearch/package.json +0 -6
  148. package/lib/InputSelect/InputSelect.js +0 -168
  149. package/lib/InputSelect/package.json +0 -6
  150. package/lib/InputTreeSelect/InputTreeSelect.js +0 -128
  151. package/lib/InputTreeSelect/package.json +0 -6
  152. package/lib/InputWriting/InputWriting.js +0 -93
  153. package/lib/InputWriting/package.json +0 -6
  154. package/lib/Layout/Layout.js +0 -209
  155. package/lib/Layout/Layout.less +0 -28
  156. package/lib/Layout/package.json +0 -6
  157. package/lib/LayoutLink/LayoutLink.js +0 -86
  158. package/lib/LayoutLink/LayoutLink.less +0 -53
  159. package/lib/LayoutLink/package.json +0 -6
  160. package/lib/Link/Link.js +0 -93
  161. package/lib/Link/package.json +0 -6
  162. package/lib/Loading/Loading.js +0 -21
  163. package/lib/Loading/Loading.less +0 -13
  164. package/lib/Loading/package.json +0 -6
  165. package/lib/Loading2/Loading2.js +0 -17
  166. package/lib/Loading2/Loading2.less +0 -19
  167. package/lib/Loading2/package.json +0 -6
  168. package/lib/ModalWithDrag/ModalWithDrag.js +0 -37
  169. package/lib/ModalWithDrag/ModalWithDrag.less +0 -6
  170. package/lib/ModalWithDrag/drag.js +0 -124
  171. package/lib/ModalWithDrag/package.json +0 -6
  172. package/lib/NumberInput/NumberInput.js +0 -208
  173. package/lib/NumberInput/package.json +0 -6
  174. package/lib/Search/Search.js +0 -510
  175. package/lib/Sidebar/Sidebar.js +0 -152
  176. package/lib/Sidebar/Sidebar.less +0 -78
  177. package/lib/Sidebar/package.json +0 -6
  178. package/lib/Sidebar2/Sidebar.js +0 -173
  179. package/lib/Sidebar2/Sidebar.less +0 -153
  180. package/lib/Sidebar2/package.json +0 -6
  181. package/lib/SuperForm/SuperForm.js +0 -610
  182. package/lib/SuperForm/SuperForm.less +0 -52
  183. package/lib/SuperForm/package.json +0 -6
  184. package/lib/SuperForm2/SuperForm.js +0 -699
  185. package/lib/SuperForm2/SuperForm.less +0 -52
  186. package/lib/SuperForm2/package.json +0 -6
  187. package/lib/SuperIcon/SuperIcon.js +0 -35
  188. package/lib/SuperIcon/package.json +0 -6
  189. package/lib/SuperPagination/SuperPagination.js +0 -117
  190. package/lib/SuperPagination/package.json +0 -6
  191. package/lib/SuperTab/SuperTab.js +0 -115
  192. package/lib/SuperTab/SuperTab.less +0 -43
  193. package/lib/SuperTab/package.json +0 -6
  194. package/lib/SuperTab2/SuperTab2.js +0 -153
  195. package/lib/SuperTab2/SuperTab2.less +0 -18
  196. package/lib/SuperTab2/package.json +0 -6
  197. package/lib/SuperTable/DragSortRow.js +0 -105
  198. package/lib/SuperTable/DragSortRow.less +0 -17
  199. package/lib/SuperTable/FilterDropDown.js +0 -172
  200. package/lib/SuperTable/FilterDropDown.less +0 -30
  201. package/lib/SuperTable/SuperTable.js +0 -816
  202. package/lib/SuperTable/SuperTable.less +0 -132
  203. package/lib/SuperTable/fixed.js +0 -42
  204. package/lib/SuperTable/package.json +0 -6
  205. package/lib/SuperTable2/SuperTable2.js +0 -939
  206. package/lib/SuperTable2/SuperTable2.less +0 -118
  207. package/lib/SuperTable2/SuperTableCell.js +0 -230
  208. package/lib/SuperTable2/package.json +0 -6
  209. package/lib/SuperTable3/FilterDropDown.js +0 -172
  210. package/lib/SuperTable3/FilterDropDown.less +0 -29
  211. package/lib/SuperTable3/SuperTable.js +0 -673
  212. package/lib/SuperTable3/SuperTable.less +0 -99
  213. package/lib/SuperTable3/fixed.js +0 -42
  214. package/lib/SuperTable3/package.json +0 -6
  215. package/lib/SuperToolbar/SuperToolbar.js +0 -203
  216. package/lib/SuperToolbar/SuperToolbar.less +0 -17
  217. package/lib/SuperToolbar/package.json +0 -6
  218. package/lib/SuperUpload/SuperUpload.js +0 -368
  219. package/lib/SuperUpload/SuperUpload.less +0 -28
  220. package/lib/SuperUpload/package.json +0 -6
  221. package/lib/Title/Title.js +0 -41
  222. package/lib/Title/Title.less +0 -35
  223. package/lib/Title/package.json +0 -6
  224. package/lib/Viewer/ImageViews.js +0 -266
  225. package/lib/Viewer/Viewer.js +0 -130
  226. package/lib/Viewer/Viewer.less +0 -67
  227. package/lib/Viewer/imgView.less +0 -59
  228. package/lib/Viewer/package.json +0 -7
  229. package/lib/WingBlank/WingBlank.js +0 -24
  230. package/lib/WingBlank/WingBlank.less +0 -12
  231. package/lib/WingBlank/package.json +0 -6
  232. package/lib/adjust.less +0 -89
  233. package/lib/helper.js +0 -246
  234. package/lib/history.js +0 -12
  235. package/lib/index.js +0 -271
  236. package/lib/index.less +0 -31
  237. package/lib/style.less +0 -30
  238. package/lib/variables.js +0 -14
  239. package/lib/variables.less +0 -73
  240. /package/{es → src}/Area/package.json +0 -0
  241. /package/{es → src}/Card/package.json +0 -0
  242. /package/{es → src}/CodeInput/package.json +0 -0
  243. /package/{es → src}/Control/package.json +0 -0
  244. /package/{es → src}/Enhance/package.json +0 -0
  245. /package/{es → src}/Header/Header.less +0 -0
  246. /package/{es → src}/Header/Vertical.less +0 -0
  247. /package/{es → src}/Header/package.json +0 -0
  248. /package/{es → src}/ImageView/ImageView.less +0 -0
  249. /package/{es → src}/ImageView/package.json +0 -0
  250. /package/{es → src}/Indent/package.json +0 -0
  251. /package/{es → src}/InpurCascader/package.json +0 -0
  252. /package/{es → src}/InputEditor/inputEditor.less +0 -0
  253. /package/{es → src}/InputEditor/package.json +0 -0
  254. /package/{es → src}/InputSearch/package.json +0 -0
  255. /package/{es → src}/InputSelect/package.json +0 -0
  256. /package/{es → src}/InputTreeSelect/package.json +0 -0
  257. /package/{es → src}/InputWriting/package.json +0 -0
  258. /package/{es → src}/Layout/Layout.less +0 -0
  259. /package/{es → src}/Layout/package.json +0 -0
  260. /package/{es → src}/LayoutLink/LayoutLink.less +0 -0
  261. /package/{es → src}/LayoutLink/package.json +0 -0
  262. /package/{es → src}/Link/package.json +0 -0
  263. /package/{es → src}/Loading/Loading.less +0 -0
  264. /package/{es → src}/Loading/package.json +0 -0
  265. /package/{es → src}/Loading2/Loading2.less +0 -0
  266. /package/{es → src}/Loading2/package.json +0 -0
  267. /package/{es → src}/ModalWithDrag/ModalWithDrag.less +0 -0
  268. /package/{es → src}/ModalWithDrag/package.json +0 -0
  269. /package/{es → src}/NumberInput/package.json +0 -0
  270. /package/{es → src}/Search/Search.less +0 -0
  271. /package/{es → src}/Search/package.json +0 -0
  272. /package/{es → src}/Sidebar/Sidebar.less +0 -0
  273. /package/{es → src}/Sidebar/package.json +0 -0
  274. /package/{es → src}/Sidebar2/Sidebar.less +0 -0
  275. /package/{es → src}/Sidebar2/package.json +0 -0
  276. /package/{es → src}/SuperForm/SuperForm.less +0 -0
  277. /package/{es → src}/SuperForm/package.json +0 -0
  278. /package/{es → src}/SuperForm2/SuperForm.less +0 -0
  279. /package/{es → src}/SuperForm2/package.json +0 -0
  280. /package/{es → src}/SuperIcon/package.json +0 -0
  281. /package/{es → src}/SuperPagination/package.json +0 -0
  282. /package/{es → src}/SuperTab/SuperTab.less +0 -0
  283. /package/{es → src}/SuperTab/package.json +0 -0
  284. /package/{es → src}/SuperTab2/SuperTab2.less +0 -0
  285. /package/{es → src}/SuperTab2/package.json +0 -0
  286. /package/{es → src}/SuperTable/DragSortRow.less +0 -0
  287. /package/{es → src}/SuperTable/FilterDropDown.less +0 -0
  288. /package/{es → src}/SuperTable/SuperTable.less +0 -0
  289. /package/{es → src}/SuperTable/package.json +0 -0
  290. /package/{es → src}/SuperTable2/SuperTable2.less +0 -0
  291. /package/{es → src}/SuperTable2/package.json +0 -0
  292. /package/{es → src}/SuperTable3/FilterDropDown.less +0 -0
  293. /package/{es → src}/SuperTable3/SuperTable.less +0 -0
  294. /package/{es → src}/SuperTable3/package.json +0 -0
  295. /package/{es → src}/SuperToolbar/SuperToolbar.less +0 -0
  296. /package/{es → src}/SuperToolbar/package.json +0 -0
  297. /package/{es → src}/SuperUpload/SuperUpload.less +0 -0
  298. /package/{es → src}/SuperUpload/package.json +0 -0
  299. /package/{es → src}/Title/Title.less +0 -0
  300. /package/{es → src}/Title/package.json +0 -0
  301. /package/{es → src}/Viewer/Viewer.less +0 -0
  302. /package/{es → src}/Viewer/imgView.less +0 -0
  303. /package/{es → src}/Viewer/package.json +0 -0
  304. /package/{es → src}/WingBlank/WingBlank.less +0 -0
  305. /package/{es → src}/WingBlank/package.json +0 -0
  306. /package/{es → src}/adjust.less +0 -0
  307. /package/{es → src}/style.less +0 -0
  308. /package/{es → src}/variables.less +0 -0
@@ -0,0 +1,143 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Link from '../Link';
4
+ import {Icon} from 'antd';
5
+ import variables from '../variables';
6
+
7
+ const ITEM_HEIGHT = 40;
8
+
9
+ /** 侧边栏二级条目的类型
10
+ * key: 唯一标识一个条目
11
+ * title:条目的标题
12
+ * href: 为跳转页面的url
13
+ */
14
+ const ChildType = {
15
+ key: PropTypes.string.isRequired,
16
+ title: PropTypes.string.isRequired,
17
+ href: PropTypes.string.isRequired
18
+ };
19
+
20
+ /** 侧边栏一级条目的类型
21
+ * key: 唯一标识一个条目
22
+ * title:条目的标题
23
+ * isFolder:为true表明有下级菜单,此时href被忽略,children存放下级菜单的信息
24
+ * href: isFolder为false时,为跳转页面的url,否则被忽略
25
+ * children:isFolder为true时,存放下级菜单的信息,否则被忽略
26
+ */
27
+ const ItemType = {
28
+ key: PropTypes.string.isRequired,
29
+ title: PropTypes.string.isRequired,
30
+ isFolder: PropTypes.bool,
31
+ href: PropTypes.string,
32
+ children: PropTypes.arrayOf(PropTypes.shape(ChildType))
33
+ };
34
+
35
+ /**
36
+ * title: 侧边栏的标题
37
+ * mode: 显示模式,默认为expand(展开)
38
+ * activeKey:指定被选中的一级条目的key,不能是二级条目的key
39
+ * items:存放所有侧边栏条目的信息
40
+ * openKeys: 展开条目的key
41
+ * style: 样式
42
+ * onOpenChange: 展开条目信息改变时触发,原型为func(openKeys)
43
+ * onModeChange: 模式改变时触发,原型为func(mode)
44
+ */
45
+ class Sidebar extends React.Component {
46
+ static propTypes = {
47
+ title: PropTypes.string,
48
+ mode: PropTypes.oneOf(['collapse', 'expand']),
49
+ activeKey: PropTypes.string,
50
+ items: PropTypes.arrayOf(PropTypes.shape(ItemType)),
51
+ openKeys: PropTypes.array,
52
+ style: PropTypes.object,
53
+ onOpenChange: PropTypes.func,
54
+ onModeChange: PropTypes.func
55
+ };
56
+
57
+ onModeChange = () => {
58
+ const mode = this.props.mode || 'expand';
59
+ this.props.onModeChange(mode === 'expand' ? 'collapse' : 'expand');
60
+ };
61
+
62
+ isSelect = (item) => {
63
+ return this.props.activeKey === item.key;
64
+ };
65
+
66
+ isOpen = (item) => {
67
+ return this.props.openKeys.includes(item.key);
68
+ };
69
+
70
+ getHeight = (item) => {
71
+ if (item.isFolder && this.isOpen(item)) {
72
+ return (item.children.length + 1) * ITEM_HEIGHT;
73
+ } else {
74
+ return ITEM_HEIGHT;
75
+ }
76
+ };
77
+
78
+ linkProps = (item) => {
79
+ if (item.isFolder) {
80
+ return {
81
+ title: item.title,
82
+ onClick: () => {
83
+ if (this.isOpen(item)) {
84
+ this.props.onOpenChange(this.props.openKeys.filter(key => item.key !== key));
85
+ } else {
86
+ this.props.onOpenChange([...this.props.openKeys, item.key]);
87
+ }
88
+ }
89
+ }
90
+ } else {
91
+ return {
92
+ title: item.title,
93
+ to: item.href,
94
+ 'data-select': this.isSelect(item)
95
+ };
96
+ }
97
+ };
98
+
99
+ renderChild = (item, index) => {
100
+ return (
101
+ <li key={index}>
102
+ <Link {...this.linkProps(item)} data-role='child-item'>
103
+ <span>{item.title}</span>
104
+ {item.unreadTotal && item.unreadTotal>0 && <span className={variables('Sidebar2').unreadTotal}>{item.unreadTotal}</span>}
105
+ </Link>
106
+ </li>
107
+ );
108
+ };
109
+
110
+ renderItem = (item, index) => {
111
+ return (
112
+ <li key={index} style={{height: this.getHeight(item)}}>
113
+ <Link {...this.linkProps(item)} data-role='parent-item'>
114
+ <span>{item.isFolder ? <Icon type='caret-right' data-open={this.isOpen(item)} /> : null}</span>
115
+ <span>{item.title}</span>
116
+ </Link>
117
+ {item.isFolder && this.isOpen(item) ? <ul>{item.children.map(this.renderChild)}</ul> : null}
118
+ </li>
119
+ );
120
+ };
121
+
122
+ render() {
123
+ return (
124
+ <div className={variables('Sidebar2')} data-mode={this.props.mode || 'expand'}>
125
+ <div>
126
+ <span> </span>
127
+ <span>{this.props.title}</span>
128
+ </div>
129
+ <ul>{this.props.items.map(this.renderItem)}</ul>
130
+ {!this.props.onModeChange ? null : (
131
+ <div data-role='shousuo' onClick={this.onModeChange}>
132
+ <div>
133
+ <i />
134
+ <div><Icon type={this.props.mode === 'expand' ? 'left' : 'right'} /></div>
135
+ </div>
136
+ </div>
137
+ )}
138
+ </div>
139
+ );
140
+ }
141
+ }
142
+
143
+ export default Sidebar;
@@ -0,0 +1,519 @@
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
+ onFileChange = ({key}, file) => {
140
+ const {onFileChange} = this.props;
141
+ onFileChange && onFileChange(key, file);
142
+ };
143
+ onExitValid = (key,value) => {
144
+ if (key === this.validKey) {
145
+ this.validKey = '';
146
+ this.props.onExitValid();
147
+ }
148
+ this.props.onChangeOperate && this.props.onChangeOperate(key,value);
149
+ };
150
+
151
+ // 动态生成getValidState方法
152
+ initValidState = () => {
153
+ const {value, valid} = this.props;
154
+ const invalid = () => null;
155
+ const _valid = ({key, required}) => {
156
+ if (required) {
157
+ if (!value || helper.isEmpty2(value[key]) || ( !Array.isArray(value[key]) && typeof value[key] === 'object' && helper.isEmpty(value[key].value))) {
158
+ this.getValidState = invalid;
159
+ this.validKey = key;
160
+ return 'error';
161
+ }
162
+ }
163
+ return null;
164
+ };
165
+ this.getValidState = valid ? _valid : invalid;
166
+ };
167
+
168
+ validDate = ({key, type}) => (date) => {
169
+ const {value={}} = this.props;
170
+ if (!date || !value[key]) {
171
+ return false;
172
+ } else {
173
+ if (type === '>') {
174
+ return date.format('YYYY-MM-DD') <= value[key];
175
+ } else if (type === '<') {
176
+ return date.format('YYYY-MM-DD') >= value[key];
177
+ } else {
178
+ return false;
179
+ }
180
+ }
181
+ };
182
+
183
+ getPopupContainer = () => {
184
+ const {container} = this.props;
185
+ if (typeof container === 'undefined') {
186
+ return ReactDOM.findDOMNode(this);
187
+ } else if (typeof container === 'boolean') {
188
+ return document.body;
189
+ } else {
190
+ return ReactDOM.findDOMNode(container);
191
+ }
192
+ };
193
+
194
+ getMaxWidth = () => {
195
+ const {colNum=defaultColNum} = this.props;
196
+ return colNum * 250;
197
+ };
198
+
199
+ getContainer = () => {
200
+ return this.props.getContainer;
201
+ };
202
+
203
+ getControls = () => {
204
+ const {hideControls, controls} = this.props;
205
+ if (!hideControls) {
206
+ return controls;
207
+ } else {
208
+ return controls.filter(control => !hideControls.some(key => control.key === key));
209
+ }
210
+ };
211
+
212
+ getType = ({key, type}) => {
213
+ const {readonly} = this.props;
214
+ if (['area', 'uploadImg'].includes(type)){
215
+ return type;
216
+ }else if (!readonly) {
217
+ return type;
218
+ } else if (readonly === true) {
219
+ return 'readonly';
220
+ } else if (Array.isArray(readonly) && readonly.some(readonlyKey => readonlyKey === key)) {
221
+ return 'readonly';
222
+ } else {
223
+ return type;
224
+ }
225
+ };
226
+
227
+ specialProps = (type, {key, props={}, type:originType}) => {
228
+ if (type === 'readonly') {
229
+ const {highLightKeys=[]} = this.props;
230
+ const style = highLightKeys.includes(key) ? {backgroundColor: 'red', color: 'white'} : {backgroundColor: '#f0f0f0'};
231
+ if (originType === 'textArea') {
232
+ return {
233
+ type: 'textArea',
234
+ readonly: true,
235
+ style,
236
+ onBlur: this.onExitValid.bind(this, key)
237
+ }
238
+ } else {
239
+ return {
240
+ style,
241
+ onBlur: this.onExitValid.bind(this, key)
242
+ };
243
+ }
244
+ } else if (type === 'text' || type === 'textArea') {
245
+ return {
246
+ ...props,
247
+ onChange: this.onExitValid.bind(this, key),
248
+ onBlur: this.onChange.bind(this, key)
249
+ }
250
+ } else if (type === 'date') {
251
+ const propsObj = {
252
+ ...props,
253
+ onChange: this.onBlur.bind(this, key),
254
+ onBlur: this.onExitValid.bind(this, key)
255
+ };
256
+ if (this.props.onOpenChange && typeof this.props.onOpenChange === 'function') {
257
+ propsObj.onOpenChange = this.props.onOpenChange.bind(this, key);
258
+ }
259
+ return propsObj;
260
+ }else if (type === 'area'){
261
+ return {
262
+ ...props,
263
+ onChange: this.onBlur.bind(this, key),
264
+ onBlur: this.onExitValid.bind(this, key),
265
+ onAreaSearch: this.props.onAreaSearch
266
+ }
267
+ } else {
268
+ return {
269
+ ...props,
270
+ onChange: this.onBlur.bind(this, key),
271
+ onBlur: this.onExitValid.bind(this, key)
272
+ };
273
+ }
274
+ };
275
+
276
+ getControlProps = (control, status) => {
277
+ const {value={}} = this.props;
278
+ const type = this.getType(control);
279
+ const props = this.specialProps(type, control);
280
+ return {
281
+ autoFocus: !!status,
282
+ type, ...props,
283
+ size: defaultSize,
284
+ value: makeString(value[control.key])
285
+ };
286
+ };
287
+
288
+ getOptions = (key, options) => {
289
+ const higher = this.props.options || {};
290
+ return higher[key] || options;
291
+ };
292
+
293
+ toEmpty = (props) => {
294
+
295
+ };
296
+
297
+ toText = (props) => {
298
+ return <Controlled {...props} />;
299
+ };
300
+
301
+ toPassword = (props) => {
302
+ return <Controlled {...props} />;
303
+ };
304
+
305
+ toEditor = (props,control) => {
306
+ props.inputKey =control.key
307
+ return <Controlled {...props} />;
308
+ };
309
+
310
+ toSelectWriting = (props,control) => {
311
+ return <Controlled {...props} />;
312
+ };
313
+
314
+
315
+ toTextArea = (props, control) => {
316
+ if(control.allFullFather){
317
+ props.rows = control.rows;
318
+ props.maxLength = control.maxLength;
319
+ props.style = {
320
+ 'resize': 'none'
321
+ };
322
+ }else{
323
+ props.autoSize = {minRows: 1, maxRows: 5};
324
+ }
325
+ return <Controlled {...props} />;
326
+ };
327
+
328
+ toNumber = (props) => {
329
+ props.defaultValue = props.value;
330
+ delete props.value;
331
+ return <Control {...props} />;
332
+ };
333
+
334
+ toSelect = (props, {options, key}) => {
335
+ props.getPopupContainer = this.getPopupContainer;
336
+ props.options = this.getOptions(key, options);
337
+ props.dropdownMatchSelectWidth = false;
338
+ return <Control {...props} />;
339
+ };
340
+
341
+ createSearchEvent = (control) => {
342
+ if (this.props.onSearch) {
343
+ return value => this.props.onSearch(control.key, value, control);
344
+ } else {
345
+ return null;
346
+ }
347
+ };
348
+
349
+ toSearch = (props, control) => {
350
+ props.getPopupContainer = this.getPopupContainer;
351
+ props.options = this.getOptions(control.key, control.options);
352
+ props.onSearch = this.createSearchEvent(control);
353
+ props.dropdownMatchSelectWidth = false;
354
+ return <Control {...props} />;
355
+ };
356
+
357
+ toDate = (props, {rule}) => {
358
+ props.getCalendarContainer = this.getPopupContainer;
359
+ props.style = {width: '100%'};
360
+ rule && (props.disabledDate = this.validDate(rule));
361
+ return <Control {...props} />;
362
+ };
363
+
364
+ toRadioGroup = (props, {key, options}) => {
365
+ props.options = this.getOptions(key, options);
366
+ return <Control {...props} />;
367
+ };
368
+
369
+ toReadonly = (props, {options, key}) => {
370
+ props.value = getTitle(props.value, this.getOptions(key, options));
371
+ return <Control {...props} />;
372
+ };
373
+
374
+ selectSearch = (props, control) => {
375
+ props.getPopupContainer = this.getPopupContainer;
376
+ props.options = this.getOptions(control.key, control.options);
377
+ props.onSearch = this.createSearchEvent(control);
378
+ props.dropdownMatchSelectWidth = false;
379
+ return <Control {...props} />;
380
+ };
381
+
382
+ area = (props, {key,options}) => {
383
+ const {readonly} = this.props;
384
+ props.parentKey = key;
385
+ props.options = this.getOptions(key, options);
386
+ props.dropdownMatchSelectWidth = false;
387
+ props.readonly = readonly === true || Array.isArray(readonly) && readonly.some(readonlyKey => readonlyKey === key) ? true : false;
388
+ return <Control {...props} />;
389
+ };
390
+
391
+ uploadImg = (props, control) => {
392
+ const {readonly} = this.props;
393
+ props.required = control.required || false;
394
+ props.onFileChange = this.onFileChange.bind(this,control);
395
+ props.readonly = readonly === true || Array.isArray(readonly) && readonly.some(readonlyKey => readonlyKey === control.key) ? true : false;
396
+ return <Control {...props} />
397
+ };
398
+
399
+ toCascader = (props, control) => {
400
+ const container = this.getContainer();
401
+ container && (props.getPopupContainer = container);
402
+ props.options = control.options || [];
403
+ props.onSearch = this.createSearchEvent(control);
404
+ props.placeholder = props.placeholder || '';
405
+ props.loadData = this.createSearchEvent(control);
406
+ return <Control {...props} />;
407
+ };
408
+
409
+ toTreeSelect = (props,filter) => {
410
+ const container = this.getContainer();
411
+ container && (props.getPopupContainer = container);
412
+ props.options = this.getOptions(filter);
413
+ props.onSearch = this.createSearchEvent(filter);
414
+ props.placeholder = filter.placeholder || '';
415
+ return <Control {...props} />;
416
+ };
417
+ toControl = (props, control) => {
418
+ switch (props.type) {
419
+ case 'readonly':
420
+ return this.toReadonly(props, control);
421
+ case 'text':
422
+ return this.toText(props, control);
423
+ case 'number':
424
+ return this.toNumber(props, control);
425
+ case 'select':
426
+ case 'selectText':
427
+ return this.toSelect(props, control);
428
+ case 'search':
429
+ case 'searchText':
430
+ return this.toSearch(props, control);
431
+ case 'date':
432
+ return this.toDate(props, control);
433
+ case 'radioGroup':
434
+ return this.toRadioGroup(props, control);
435
+ case 'textArea':
436
+ return this.toTextArea(props, control);
437
+ case 'password':
438
+ return this.toPassword(props, control);
439
+ case 'editor':
440
+ return this.toEditor(props, control);
441
+ case 'selectWriting' :
442
+ return this.toSelectWriting(props,control)
443
+ case 'selectSearch':
444
+ return this.selectSearch(props, control);
445
+ case 'empty':
446
+ return this.toEmpty(props, control);
447
+ case 'area':
448
+ return this.area(props, control);
449
+ case 'uploadImg':
450
+ return this.uploadImg(props, control);
451
+ case 'cascader':
452
+ return this.toCascader(props, control);
453
+ case 'treeSelect':
454
+ return this.toTreeSelect(props, control);
455
+ default:
456
+ return 'type error';
457
+ }
458
+ };
459
+
460
+ toLabel = ({title, showAdd, key}, type) => {
461
+ if (showAdd && (type !== 'readonly')) {
462
+ const onClick = this.onAdd.bind(this, key, title);
463
+ return <span>{title}<Icon role='add' type='plus-circle-o' onClick={onClick}/></span>;
464
+ } else {
465
+ return title;
466
+ }
467
+ };
468
+
469
+ toCol = (span, control) => {
470
+ const factor = control.span || 1;
471
+ const status = this.getValidState(control);
472
+ const controlProps = this.getControlProps(control, status);
473
+ const itemProps = {
474
+ label: this.toLabel(control, controlProps.type),
475
+ required: control.required,
476
+ validateStatus: status
477
+ };
478
+ const {checkable,onCheckItem} = this.props;
479
+ return control.type !== 'empty' ? (
480
+ <Col span={span * factor} key={control.key}>
481
+ {checkable && <Checkbox className={variables('SuperForm').checkbox} onChange={onCheckItem.bind(this,control)} checked={control.checked} />}
482
+ <FormItem {...itemProps} className={checkable ? variables('SuperForm').formItemWithCheckbox : ''}>
483
+ {this.toControl(controlProps, control)}
484
+ </FormItem>
485
+ </Col>
486
+ ) : (
487
+ <Col span={span * factor} key={control.key} style={{height: '44px'}}/>
488
+ );
489
+ };
490
+
491
+ toCols = () => {
492
+ let {colNum=defaultColNum,allFullFather} = this.props;
493
+ if(allFullFather){
494
+ colNum = 1;
495
+ }
496
+ const span = 24 / colNum;
497
+ return this.getControls().map(control => {
498
+ if(allFullFather){
499
+ control.allFullFather = allFullFather;
500
+ }
501
+ return this.toCol(span, control)
502
+ });
503
+ };
504
+
505
+ render() {
506
+ this.initValidState();
507
+ return (
508
+ <div className={variables('SuperForm')}>
509
+ <Form layout='vertical' style={{maxWidth: this.props.allFullFather ? '100%' : this.getMaxWidth()}}>
510
+ <Row gutter={20}>
511
+ {this.toCols()}
512
+ </Row>
513
+ </Form>
514
+ </div>
515
+ );
516
+ }
517
+ }
518
+
519
+ export default SuperForm;