cloud-b2b 1.1.50 → 1.1.52

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 (309) 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 -8
  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/src/ModalWithDrag/drag.js +128 -0
  27. package/src/NumberInput/NumberInput.js +137 -0
  28. package/src/Search/Search.js +368 -0
  29. package/src/Sidebar/Sidebar.js +111 -0
  30. package/src/Sidebar2/Sidebar.js +143 -0
  31. package/src/SuperForm/SuperForm.js +516 -0
  32. package/src/SuperForm2/SuperForm.js +588 -0
  33. package/src/SuperIcon/SuperIcon.js +14 -0
  34. package/src/SuperPagination/SuperPagination.js +65 -0
  35. package/src/SuperTab/SuperTab.js +84 -0
  36. package/src/SuperTab2/SuperTab2.js +94 -0
  37. package/src/SuperTable/DragSortRow.js +62 -0
  38. package/src/SuperTable/FilterDropDown.js +111 -0
  39. package/src/SuperTable/SuperTable.js +590 -0
  40. package/src/SuperTable/fixed.js +34 -0
  41. package/src/SuperTable2/SuperTable2.js +600 -0
  42. package/src/SuperTable2/SuperTableCell.js +144 -0
  43. package/src/SuperTable3/FilterDropDown.js +111 -0
  44. package/src/SuperTable3/SuperTable.js +498 -0
  45. package/src/SuperTable3/fixed.js +34 -0
  46. package/src/SuperToolbar/SuperToolbar.js +128 -0
  47. package/src/SuperUpload/SuperUpload.js +137 -0
  48. package/src/Title/Title.js +18 -0
  49. package/src/Viewer/ImageViews.js +220 -0
  50. package/src/Viewer/Viewer.js +97 -0
  51. package/src/WingBlank/WingBlank.js +14 -0
  52. package/src/helper.js +185 -0
  53. package/src/history.js +6 -0
  54. package/src/index.js +38 -0
  55. package/src/variables.js +5 -0
  56. package/test/index.html +10 -0
  57. package/test/test.js +16 -0
  58. package/test/test.less +12 -0
  59. package/test/webpack.config.js +71 -0
  60. package/tools/babel.config.js +14 -0
  61. package/tools/build.js +70 -0
  62. package/tools/publish.js +9 -0
  63. package/tools/util.js +53 -0
  64. package/es/Area/Area.js +0 -170
  65. package/es/Card/Card.js +0 -20
  66. package/es/CodeInput/CodeInput.js +0 -152
  67. package/es/Control/Control.js +0 -496
  68. package/es/Control/event.js +0 -57
  69. package/es/Enhance/Dialogs.js +0 -67
  70. package/es/Enhance/Loading.js +0 -151
  71. package/es/Header/Header.js +0 -194
  72. package/es/Header/Vertical.js +0 -129
  73. package/es/ImageView/ImageView.js +0 -117
  74. package/es/Indent/Indent.js +0 -23
  75. package/es/InpurCascader/InputCascader.js +0 -135
  76. package/es/InputEditor/InputEditor.js +0 -113
  77. package/es/InputSearch/InputSearch.js +0 -311
  78. package/es/InputSelect/InputSelect.js +0 -191
  79. package/es/InputTreeSelect/InputTreeSelect.js +0 -147
  80. package/es/InputWriting/InputWriting.js +0 -107
  81. package/es/Layout/Layout.js +0 -232
  82. package/es/LayoutLink/LayoutLink.js +0 -82
  83. package/es/Link/Link.js +0 -108
  84. package/es/Loading/Loading.js +0 -15
  85. package/es/Loading2/Loading2.js +0 -11
  86. package/es/ModalWithDrag/ModalWithDrag.js +0 -34
  87. package/es/ModalWithDrag/drag.js +0 -133
  88. package/es/NumberInput/NumberInput.js +0 -240
  89. package/es/Search/Search.js +0 -595
  90. package/es/Sidebar/Sidebar.js +0 -165
  91. package/es/Sidebar2/Sidebar.js +0 -192
  92. package/es/SuperForm/SuperForm.js +0 -720
  93. package/es/SuperForm2/SuperForm.js +0 -828
  94. package/es/SuperIcon/SuperIcon.js +0 -30
  95. package/es/SuperPagination/SuperPagination.js +0 -126
  96. package/es/SuperTab/SuperTab.js +0 -130
  97. package/es/SuperTab2/SuperTab2.js +0 -167
  98. package/es/SuperTable/DragSortRow.js +0 -125
  99. package/es/SuperTable/FilterDropDown.js +0 -188
  100. package/es/SuperTable/SuperTable.js +0 -940
  101. package/es/SuperTable/fixed.js +0 -42
  102. package/es/SuperTable2/SuperTable2.js +0 -1019
  103. package/es/SuperTable2/SuperTableCell.js +0 -242
  104. package/es/SuperTable3/FilterDropDown.js +0 -188
  105. package/es/SuperTable3/SuperTable.js +0 -790
  106. package/es/SuperTable3/fixed.js +0 -42
  107. package/es/SuperToolbar/SuperToolbar.js +0 -223
  108. package/es/SuperUpload/SuperUpload.js +0 -434
  109. package/es/Title/Title.js +0 -36
  110. package/es/Viewer/ImageViews.js +0 -311
  111. package/es/Viewer/Viewer.js +0 -149
  112. package/es/WingBlank/WingBlank.js +0 -20
  113. package/es/helper.js +0 -169
  114. package/es/history.js +0 -5
  115. package/es/index.js +0 -37
  116. package/es/variables.js +0 -4
  117. package/lib/Area/Area.js +0 -198
  118. package/lib/Area/package.json +0 -6
  119. package/lib/Card/Card.js +0 -38
  120. package/lib/Card/package.json +0 -6
  121. package/lib/CodeInput/CodeInput.js +0 -179
  122. package/lib/CodeInput/package.json +0 -6
  123. package/lib/Control/Control.js +0 -548
  124. package/lib/Control/event.js +0 -68
  125. package/lib/Control/package.json +0 -6
  126. package/lib/Enhance/Dialogs.js +0 -87
  127. package/lib/Enhance/Loading.js +0 -175
  128. package/lib/Enhance/index.js +0 -35
  129. package/lib/Enhance/package.json +0 -6
  130. package/lib/Header/Header.js +0 -215
  131. package/lib/Header/Header.less +0 -95
  132. package/lib/Header/Vertical.js +0 -150
  133. package/lib/Header/Vertical.less +0 -60
  134. package/lib/Header/package.json +0 -6
  135. package/lib/ImageView/ImageView.js +0 -134
  136. package/lib/ImageView/ImageView.less +0 -14
  137. package/lib/ImageView/package.json +0 -6
  138. package/lib/Indent/Indent.js +0 -38
  139. package/lib/Indent/package.json +0 -6
  140. package/lib/InpurCascader/InputCascader.js +0 -156
  141. package/lib/InpurCascader/package.json +0 -6
  142. package/lib/InputEditor/InputEditor.js +0 -131
  143. package/lib/InputEditor/inputEditor.less +0 -8
  144. package/lib/InputEditor/package.json +0 -6
  145. package/lib/InputSearch/InputSearch.js +0 -327
  146. package/lib/InputSearch/package.json +0 -6
  147. package/lib/InputSelect/InputSelect.js +0 -214
  148. package/lib/InputSelect/package.json +0 -6
  149. package/lib/InputTreeSelect/InputTreeSelect.js +0 -169
  150. package/lib/InputTreeSelect/package.json +0 -6
  151. package/lib/InputWriting/InputWriting.js +0 -123
  152. package/lib/InputWriting/package.json +0 -6
  153. package/lib/Layout/Layout.js +0 -258
  154. package/lib/Layout/Layout.less +0 -28
  155. package/lib/Layout/package.json +0 -6
  156. package/lib/LayoutLink/LayoutLink.js +0 -114
  157. package/lib/LayoutLink/LayoutLink.less +0 -53
  158. package/lib/LayoutLink/package.json +0 -6
  159. package/lib/Link/Link.js +0 -130
  160. package/lib/Link/package.json +0 -6
  161. package/lib/Loading/Loading.js +0 -30
  162. package/lib/Loading/Loading.less +0 -13
  163. package/lib/Loading/package.json +0 -6
  164. package/lib/Loading2/Loading2.js +0 -26
  165. package/lib/Loading2/Loading2.less +0 -19
  166. package/lib/Loading2/package.json +0 -6
  167. package/lib/ModalWithDrag/ModalWithDrag.js +0 -53
  168. package/lib/ModalWithDrag/ModalWithDrag.less +0 -6
  169. package/lib/ModalWithDrag/drag.js +0 -147
  170. package/lib/ModalWithDrag/package.json +0 -6
  171. package/lib/NumberInput/NumberInput.js +0 -262
  172. package/lib/NumberInput/package.json +0 -6
  173. package/lib/Search/Search.js +0 -616
  174. package/lib/Search/Search.less +0 -63
  175. package/lib/Search/package.json +0 -6
  176. package/lib/Sidebar/Sidebar.js +0 -186
  177. package/lib/Sidebar/Sidebar.less +0 -78
  178. package/lib/Sidebar/package.json +0 -6
  179. package/lib/Sidebar2/Sidebar.js +0 -213
  180. package/lib/Sidebar2/Sidebar.less +0 -153
  181. package/lib/Sidebar2/package.json +0 -6
  182. package/lib/SuperForm/SuperForm.js +0 -731
  183. package/lib/SuperForm/SuperForm.less +0 -52
  184. package/lib/SuperForm/package.json +0 -6
  185. package/lib/SuperForm2/SuperForm.js +0 -834
  186. package/lib/SuperForm2/SuperForm.less +0 -52
  187. package/lib/SuperForm2/package.json +0 -6
  188. package/lib/SuperIcon/SuperIcon.js +0 -47
  189. package/lib/SuperIcon/package.json +0 -6
  190. package/lib/SuperPagination/SuperPagination.js +0 -145
  191. package/lib/SuperPagination/package.json +0 -6
  192. package/lib/SuperTab/SuperTab.js +0 -146
  193. package/lib/SuperTab/SuperTab.less +0 -43
  194. package/lib/SuperTab/package.json +0 -6
  195. package/lib/SuperTab2/SuperTab2.js +0 -191
  196. package/lib/SuperTab2/SuperTab2.less +0 -18
  197. package/lib/SuperTab2/package.json +0 -6
  198. package/lib/SuperTable/DragSortRow.js +0 -142
  199. package/lib/SuperTable/DragSortRow.less +0 -17
  200. package/lib/SuperTable/FilterDropDown.js +0 -205
  201. package/lib/SuperTable/FilterDropDown.less +0 -30
  202. package/lib/SuperTable/SuperTable.js +0 -945
  203. package/lib/SuperTable/SuperTable.less +0 -132
  204. package/lib/SuperTable/fixed.js +0 -55
  205. package/lib/SuperTable/package.json +0 -6
  206. package/lib/SuperTable2/SuperTable2.js +0 -1047
  207. package/lib/SuperTable2/SuperTable2.less +0 -118
  208. package/lib/SuperTable2/SuperTableCell.js +0 -258
  209. package/lib/SuperTable2/package.json +0 -6
  210. package/lib/SuperTable3/FilterDropDown.js +0 -205
  211. package/lib/SuperTable3/FilterDropDown.less +0 -29
  212. package/lib/SuperTable3/SuperTable.js +0 -795
  213. package/lib/SuperTable3/SuperTable.less +0 -99
  214. package/lib/SuperTable3/fixed.js +0 -55
  215. package/lib/SuperTable3/package.json +0 -6
  216. package/lib/SuperToolbar/SuperToolbar.js +0 -248
  217. package/lib/SuperToolbar/SuperToolbar.less +0 -17
  218. package/lib/SuperToolbar/package.json +0 -6
  219. package/lib/SuperUpload/SuperUpload.js +0 -481
  220. package/lib/SuperUpload/SuperUpload.less +0 -28
  221. package/lib/SuperUpload/package.json +0 -6
  222. package/lib/Title/Title.js +0 -54
  223. package/lib/Title/Title.less +0 -35
  224. package/lib/Title/package.json +0 -6
  225. package/lib/Viewer/ImageViews.js +0 -323
  226. package/lib/Viewer/Viewer.js +0 -167
  227. package/lib/Viewer/Viewer.less +0 -67
  228. package/lib/Viewer/imgView.less +0 -59
  229. package/lib/Viewer/package.json +0 -7
  230. package/lib/WingBlank/WingBlank.js +0 -37
  231. package/lib/WingBlank/WingBlank.less +0 -12
  232. package/lib/WingBlank/package.json +0 -6
  233. package/lib/adjust.less +0 -89
  234. package/lib/helper.js +0 -204
  235. package/lib/history.js +0 -18
  236. package/lib/index.js +0 -347
  237. package/lib/index.less +0 -31
  238. package/lib/style.less +0 -30
  239. package/lib/variables.js +0 -16
  240. package/lib/variables.less +0 -73
  241. /package/{es → src}/Area/package.json +0 -0
  242. /package/{es → src}/Card/package.json +0 -0
  243. /package/{es → src}/CodeInput/package.json +0 -0
  244. /package/{es → src}/Control/package.json +0 -0
  245. /package/{es → src}/Enhance/package.json +0 -0
  246. /package/{es → src}/Header/Header.less +0 -0
  247. /package/{es → src}/Header/Vertical.less +0 -0
  248. /package/{es → src}/Header/package.json +0 -0
  249. /package/{es → src}/ImageView/ImageView.less +0 -0
  250. /package/{es → src}/ImageView/package.json +0 -0
  251. /package/{es → src}/Indent/package.json +0 -0
  252. /package/{es → src}/InpurCascader/package.json +0 -0
  253. /package/{es → src}/InputEditor/inputEditor.less +0 -0
  254. /package/{es → src}/InputEditor/package.json +0 -0
  255. /package/{es → src}/InputSearch/package.json +0 -0
  256. /package/{es → src}/InputSelect/package.json +0 -0
  257. /package/{es → src}/InputTreeSelect/package.json +0 -0
  258. /package/{es → src}/InputWriting/package.json +0 -0
  259. /package/{es → src}/Layout/Layout.less +0 -0
  260. /package/{es → src}/Layout/package.json +0 -0
  261. /package/{es → src}/LayoutLink/LayoutLink.less +0 -0
  262. /package/{es → src}/LayoutLink/package.json +0 -0
  263. /package/{es → src}/Link/package.json +0 -0
  264. /package/{es → src}/Loading/Loading.less +0 -0
  265. /package/{es → src}/Loading/package.json +0 -0
  266. /package/{es → src}/Loading2/Loading2.less +0 -0
  267. /package/{es → src}/Loading2/package.json +0 -0
  268. /package/{es → src}/ModalWithDrag/ModalWithDrag.less +0 -0
  269. /package/{es → src}/ModalWithDrag/package.json +0 -0
  270. /package/{es → src}/NumberInput/package.json +0 -0
  271. /package/{es → src}/Search/Search.less +0 -0
  272. /package/{es → src}/Search/package.json +0 -0
  273. /package/{es → src}/Sidebar/Sidebar.less +0 -0
  274. /package/{es → src}/Sidebar/package.json +0 -0
  275. /package/{es → src}/Sidebar2/Sidebar.less +0 -0
  276. /package/{es → src}/Sidebar2/package.json +0 -0
  277. /package/{es → src}/SuperForm/SuperForm.less +0 -0
  278. /package/{es → src}/SuperForm/package.json +0 -0
  279. /package/{es → src}/SuperForm2/SuperForm.less +0 -0
  280. /package/{es → src}/SuperForm2/package.json +0 -0
  281. /package/{es → src}/SuperIcon/package.json +0 -0
  282. /package/{es → src}/SuperPagination/package.json +0 -0
  283. /package/{es → src}/SuperTab/SuperTab.less +0 -0
  284. /package/{es → src}/SuperTab/package.json +0 -0
  285. /package/{es → src}/SuperTab2/SuperTab2.less +0 -0
  286. /package/{es → src}/SuperTab2/package.json +0 -0
  287. /package/{es → src}/SuperTable/DragSortRow.less +0 -0
  288. /package/{es → src}/SuperTable/FilterDropDown.less +0 -0
  289. /package/{es → src}/SuperTable/SuperTable.less +0 -0
  290. /package/{es → src}/SuperTable/package.json +0 -0
  291. /package/{es → src}/SuperTable2/SuperTable2.less +0 -0
  292. /package/{es → src}/SuperTable2/package.json +0 -0
  293. /package/{es → src}/SuperTable3/FilterDropDown.less +0 -0
  294. /package/{es → src}/SuperTable3/SuperTable.less +0 -0
  295. /package/{es → src}/SuperTable3/package.json +0 -0
  296. /package/{es → src}/SuperToolbar/SuperToolbar.less +0 -0
  297. /package/{es → src}/SuperToolbar/package.json +0 -0
  298. /package/{es → src}/SuperUpload/SuperUpload.less +0 -0
  299. /package/{es → src}/SuperUpload/package.json +0 -0
  300. /package/{es → src}/Title/Title.less +0 -0
  301. /package/{es → src}/Title/package.json +0 -0
  302. /package/{es → src}/Viewer/Viewer.less +0 -0
  303. /package/{es → src}/Viewer/imgView.less +0 -0
  304. /package/{es → src}/Viewer/package.json +0 -0
  305. /package/{es → src}/WingBlank/WingBlank.less +0 -0
  306. /package/{es → src}/WingBlank/package.json +0 -0
  307. /package/{es → src}/adjust.less +0 -0
  308. /package/{es → src}/style.less +0 -0
  309. /package/{es → src}/variables.less +0 -0
@@ -0,0 +1,498 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ReactDOM from 'react-dom';
4
+ import {getTitle} from '../Control';
5
+ import {Table, Tooltip} from 'antd';
6
+ import FilterDropDown from './FilterDropDown';
7
+ import fixed from './fixed';
8
+ import variables from '../variables';
9
+
10
+ /**
11
+ * sorter: [可选],不传表示该列不支持排序;为string表示按字符串排序;为number表示按数字大小排序
12
+ * filter: [可选],是否支持过滤,默认为false
13
+ * link: [可选],为true表示超链接,内容来至items;为字符串表示超链接,内容就是该字符串;为字符串‘list’表示超链接数组,内容就是该items对应key对象数组的linkTitleKey属性拼接
14
+ * linkTitleKey: [可选],当link为'list'表示超链接组时,该值表示要拼接展示的属性key值
15
+ * isDateFilterByStartAndEnd: [可选],为true时做过滤操作会显示时间段搜索,默认为false
16
+ *
17
+ */
18
+ const ColType = {
19
+ key: PropTypes.string.isRequired,
20
+ title: PropTypes.string,
21
+ align: PropTypes.oneOf(['left', 'center', 'right']),
22
+ sorter: PropTypes.oneOf(['string', 'number']),
23
+ filter: PropTypes.bool,
24
+ hide: PropTypes.bool,
25
+ options: PropTypes.array,
26
+ link: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
27
+ linkTitleKey: PropTypes.string,
28
+ noWrap: PropTypes.bool,
29
+ isDateFilterByStartAndEnd: PropTypes.bool,
30
+ };
31
+
32
+ const ItemType = {
33
+ checked: PropTypes.bool
34
+ };
35
+
36
+ /**
37
+ * onCheck:点击复选框时触发, 原型为onCheck(checkedRows)
38
+ * onRadio: 点击单选按钮时触发,原型为func(checkedRows)
39
+ * onDoubleClick: 行双击时触发,原型func(rowIndex)
40
+ * onLink: 点击超链接时触发,原型为func(key, rowIndex, item)
41
+ * onTableChange: 排序信息改变时触发,原型为func(sortInfo, filterInfo)
42
+ */
43
+ const CallbackType = {
44
+ onCheck: PropTypes.func,
45
+ onRadio: PropTypes.func,
46
+ onDoubleClick: PropTypes.func,
47
+ onLink: PropTypes.func,
48
+ onTableChange: PropTypes.func,
49
+ };
50
+
51
+ /**
52
+ * checkbox: [可选],是否有复选框,默认为true
53
+ * isPaging: [可选],是否分页,默认为false
54
+ * radio: [可选],是否为单选按钮,当checkbox为true时生效,默认值为false
55
+ * checkedRows: [可选],选中的行数,radio为true时生效
56
+ * index: [可选],是否有序号,默认值为true
57
+ * indexTitle:[可选],序号标题,默认为'序号'
58
+ * sortInfo: [可选],排序信息,默认为null
59
+ * filterInfo: [可选],过滤信息,默认为null
60
+ * maxHeight: [可选],设置表格的最大高度
61
+ * childrenKey: [可选],设置子列表数据的key,默认children
62
+ */
63
+ class SuperTable extends React.Component {
64
+ static propTypes = {
65
+ cols: PropTypes.arrayOf(PropTypes.shape(ColType)).isRequired,
66
+ items: PropTypes.arrayOf(PropTypes.shape(ItemType)).isRequired,
67
+ isPaging:PropTypes.bool,
68
+ checkbox: PropTypes.bool,
69
+ radio: PropTypes.bool,
70
+ checkedRows: PropTypes.array,
71
+ index: PropTypes.bool,
72
+ indexTitle: PropTypes.string,
73
+ sortInfo: PropTypes.object,
74
+ filterInfo: PropTypes.object,
75
+ maxHeight: PropTypes.string,
76
+ callback: PropTypes.shape(CallbackType),
77
+ childrenKey: PropTypes.string,
78
+ };
79
+
80
+ state = {filterVisibleKey: ''};
81
+
82
+ onTableChange = (pagination, filters, sorter) => {
83
+ const {onTableChange} = this.props.callback || {};
84
+ const {filterInfo=null} = this.props;
85
+ onTableChange && onTableChange(sorter, filterInfo);
86
+ };
87
+
88
+ onChange = (selectedKeyArr=[]) => {
89
+ const {onCheck} = this.props.callback || {};
90
+ if (onCheck) {
91
+ const {items=[]} = this.props;
92
+ let offset = 0;
93
+ const realSlectedList = selectedKeyArr.length > items.length ? selectedKeyArr.slice(0, selectedKeyArr.length + offset) : selectedKeyArr;
94
+ const selectedKeys = realSlectedList;
95
+ const newItems = items;
96
+ if (selectedKeys.length === 0) {
97
+ onCheck(true, false, -1);
98
+ } else if (selectedKeys.length === newItems.length) {
99
+ const checked = newItems.every(o => o.checked);
100
+ onCheck(true, !checked, -1);
101
+ } else {
102
+ const defaultSelectedKeys = this.getSelectedRowKeys(newItems);
103
+ if (selectedKeys.length > defaultSelectedKeys.length) {
104
+ if (this.props.isPaging && selectedKeys.length - defaultSelectedKeys.length > 1) {
105
+ return onCheck(true, true, -1);
106
+ }
107
+ onCheck(false, true, selectedKeys[selectedKeys.length - 1]);
108
+ } else {
109
+ const index = defaultSelectedKeys.findIndex(key => !selectedKeys.some(select => select === key));
110
+ onCheck(false, false, defaultSelectedKeys[index]);
111
+ }
112
+ }
113
+ }
114
+ };
115
+
116
+ onCheckChange = (selectedKeys) => {
117
+ const {onCheck} = this.props.callback || {};
118
+ onCheck && onCheck(selectedKeys);
119
+ };
120
+
121
+ onRadioChange = (selectedKeys) => {
122
+ const {onRadio} = this.props.callback || {};
123
+ onRadio && onRadio(selectedKeys);
124
+ };
125
+
126
+ onRadioRowClick = (record) => {
127
+ const {onRadio} = this.props.callback || {};
128
+ onRadio && onRadio([record.key]);
129
+ };
130
+
131
+ onRowClick = (record) => {
132
+ const {items} = this.props;
133
+ if (items.length <= record.key) return;
134
+ clearTimeout(this.timer);
135
+ this.timer = setTimeout(() => {
136
+ const {onCheck} = this.props.callback || {};
137
+ if (onCheck) {
138
+ const {checkedRows=[]} = this.props;
139
+ if (checkedRows.includes(record.key)) {
140
+ onCheck(checkedRows.filter(key => record.key !== key));
141
+ } else {
142
+ onCheck(checkedRows.concat(record.key));
143
+ }
144
+ }
145
+ }, 250);
146
+ };
147
+
148
+ onDoubleClick = (record) => {
149
+ clearTimeout(this.timer);
150
+ const {onDoubleClick} = this.props.callback || {};
151
+ onDoubleClick && onDoubleClick(record.key);
152
+ };
153
+
154
+ onLink = (key, index, item, e) => {
155
+ const {onLink} = this.props.callback || {};
156
+ onLink && onLink(key, index, item);
157
+ e.stopPropagation();
158
+ };
159
+
160
+ onLinkDouble = (e) => {
161
+ e.stopPropagation();
162
+ };
163
+
164
+ getSelectedRowKeys = (items) => {
165
+ return items.reduce((result, item, index) => {
166
+ item.checked && result.push(index);
167
+ return result;
168
+ }, []);
169
+ };
170
+
171
+ getIndexInfo = (items=[]) => {
172
+ const {index=true, indexTitle='序号'} = this.props;
173
+ return index ? [{key: 'index', title: indexTitle, render: (text, record, index) => (index + 1)}] : [];
174
+ };
175
+
176
+ setSortInfo = (col, sortInfo) => {
177
+ if (col.sorter === 'string') {
178
+ col.sortOrder = sortInfo.columnKey === col.key && sortInfo.order;
179
+ col.sorter = (row1, row2) => {
180
+ const a = !col.link ? row1[col.key] : row1[col.key].props.children;
181
+ const b = !col.link ? row2[col.key] : row2[col.key].props.children;
182
+ if (a > b) {
183
+ return 1;
184
+ } else if (a === b) {
185
+ return 0;
186
+ } else {
187
+ return -1;
188
+ }
189
+ };
190
+ } else if (col.sorter === 'number') {
191
+ col.sortOrder = sortInfo.columnKey === col.key && sortInfo.order;
192
+ col.sorter = (a, b) => a[col.key] - b[col.key];
193
+ } else {
194
+ delete col.sorter;
195
+ }
196
+ };
197
+
198
+ setFilterInfo = (col, filterInfo, visibleKey) => {
199
+ if (col.filter) {
200
+ const {isDateFilterByStartAndEnd=false} = col;
201
+ const onSearch = (value) => {
202
+ const {onTableChange} = this.props.callback || {};
203
+ const {sortInfo=null} = this.props;
204
+ const newFilterInfo = Object.assign({}, filterInfo, {[col.key]: value});
205
+ this.setState({filterVisibleKey: ''});
206
+ onTableChange && onTableChange(sortInfo, newFilterInfo);
207
+ };
208
+ const value = filterInfo[col.key];
209
+ col.filteredValue = value ? [value] : null;
210
+ col.filterDropdownVisible = visibleKey === col.key;
211
+ const onClose = () => {
212
+ this.setState({filterVisibleKey: ''});
213
+ };
214
+ col.filterDropdown = <FilterDropDown {...{value, onSearch, onClose, isDateFilterByStartAndEnd}} />;
215
+ col.onFilterDropdownVisibleChange = (visible) => {
216
+ if (isDateFilterByStartAndEnd) {
217
+ visible && this.setState({filterVisibleKey: col.key});
218
+ } else {
219
+ this.setState({filterVisibleKey: visible ? col.key : ''});
220
+ }
221
+ };
222
+ col.onFilter = (value, record) => {
223
+ const content = !col.link ? record[col.key] : record[col.key].props.children;
224
+ if(!col.isDateFilterByStartAndEnd){
225
+ const con = Array.isArray(content) ? content : String(content);
226
+ return con.includes(value);
227
+ } else {
228
+ return !((value.start && new Date(value.start) > new Date(content)) || (value.end && value.end < content));
229
+ }
230
+ }
231
+ }
232
+ delete col.filter;
233
+ };
234
+
235
+ linkList = (key, index, item, linkTitleKey='fileName') => {
236
+ const list = item[key] || [];
237
+ return (
238
+ <div>
239
+ {list.map((item2, index2) => {
240
+ const split = index2 === list.length-1 ? '' : ',';
241
+ const onClick = this.onLink.bind(null, key, index, item2);
242
+ return <a key={index2} onClick={onClick} onDoubleClick={this.onLinkDouble}>{`${item2[linkTitleKey]}${split}`}</a>;
243
+ })}
244
+ </div>
245
+ )
246
+ };
247
+
248
+ waring = (key,index,item,warningKey) => {
249
+ const text = item[key] ? item[key] : '';
250
+ const color = item[warningKey] == 1 ?'red' :'rgba(0, 0, 0, 0.65)';
251
+ return (
252
+ <div>
253
+ <p style={{color:color}}>{text.title ? text.title : text}</p>
254
+ </div>
255
+ )
256
+ };
257
+
258
+ defaultList = (key,index,item,text,link) => {
259
+ const onClick = this.onLink.bind(null, key, index, item);
260
+ if (link && (typeof link === 'string')) {
261
+ return <a onClick={onClick} onDoubleClick={this.onLinkDouble}>{text}</a>;
262
+ }
263
+ return (
264
+ <div>
265
+ <p>{text}</p>
266
+ </div>
267
+ )
268
+ };
269
+
270
+ getColumns = (cols, items) => {
271
+ const {sortInfo, filterInfo} = this.props;
272
+ const {filterVisibleKey} = this.state;
273
+ return this.getIndexInfo(items).concat(cols.filter(col => !col.hide)).map(({...col}) => {
274
+ col.dataIndex = col.key;
275
+ col.className = col.key === 'index' ? 'ant-table-selection-column' : (col.align ? s[col.align] : '');
276
+ col.noWrap && (col.className = variables('SuperTable3').noWrap);
277
+ this.setSortInfo(col, sortInfo || {});
278
+ this.setFilterInfo(col, filterInfo || {}, filterVisibleKey);
279
+
280
+ if(col.defaultValue){
281
+ col.render = (text, record, index) => this.defaultList(col.key, index, items[index],col.defaultValue,col.link)
282
+ }else if (col.link === 'list') {
283
+ col.render = (text, record, index) => this.linkList(col.key, index, items[index], col.linkTitleKey);
284
+ }else if (col.link && (typeof col.link === 'string')) {
285
+ col.render = (text, record, index) => this.link(col.key, index, items[index], col.link);
286
+ }else if(col.isWarning){
287
+ col.render = (text, record, index) => this.waring(col.key, index, items[index],col.warningKey);
288
+ }else if (col.tooltip) {
289
+ col.render = (text, record, index) => this.tooltip(col.key, index, items[index], col);
290
+ }
291
+ return col;
292
+ });
293
+ };
294
+
295
+ getText = (value, options) => {
296
+ if (Array.isArray(value)) {
297
+ return value.map(v => getTitle(v, options)).toString();
298
+ } else {
299
+ return getTitle(value, options);
300
+ }
301
+ };
302
+
303
+ link = (key, index, item, text) => {
304
+ const onClick = this.onLink.bind(null, key, index, item);
305
+ return <a onClick={onClick} onDoubleClick={this.onLinkDouble}>{text}</a>;
306
+ };
307
+
308
+ tooltip = (key, index, item, {tooltip:tipLen, options}) => {
309
+ const text = this.getText(item[key], options);
310
+ const needTip = tipLen > 1 && text && typeof text === 'string' && text.length > tipLen;
311
+ return needTip ? (
312
+ <Tooltip title={text}>
313
+ <span>{text.slice(0, tipLen) + '...'}</span>
314
+ </Tooltip>
315
+ ) : <span>{Array.isArray(text) ? text.join(',') : text}</span>;
316
+ };
317
+
318
+ getImgSrc = (value, options) => {
319
+ const index = options.findIndex(obj => obj.value == value);
320
+ return index === -1 ? null : options[index].img;
321
+ };
322
+
323
+ /**
324
+ *
325
+ * @param item{array}:列数据
326
+ * @param key{string}:字段key
327
+ * @param options{array}:字段options
328
+ * @param dataSource{string,array}:数据源,如果列数据有多层则用此决定
329
+ */
330
+ getSourceText = (item,key,options,dataSource) => {
331
+ let value = {};
332
+ if(typeof dataSource === 'string'){
333
+ value = item[dataSource] || {};
334
+ }else if(Array.isArray(dataSource)){
335
+ dataSource.forEach((source,index) => {
336
+ /*如果字段重复则用dataSource取到结果,key不作为取字段的标准*/
337
+ if(index === 0){
338
+ value = item[source] || {};
339
+ }else {
340
+ value = value[source] || {}
341
+ }
342
+ })
343
+ }
344
+ /*如果上面已经取到结果则不进入*/
345
+ if(typeof value !== 'string'){
346
+ value = value[key];
347
+ }
348
+ return this.getText(value, options);
349
+ };
350
+
351
+
352
+ getDataSource = (items, cols) => {
353
+ const getItemObj = (item, index) => {
354
+ return cols.reduce((result, {key, options, link, icon,dataSource}) => {
355
+ if (link) {
356
+ if (typeof link === 'boolean') {
357
+ result[key] = this.link(key, index, item, this.getText(item[key], options));
358
+ }
359
+ } else if (icon) { //单独的icon列,icon=true数据值根据options获得显示的图片url
360
+ const src = this.getImgSrc(item[key], options);
361
+ const onClick = this.onLink.bind(null, key, index, item);
362
+ result[key] = src ? <img src={src} onClick={onClick} /> : '';
363
+ } else if(dataSource){
364
+ result[key] = this.getSourceText(item,key,options,dataSource);
365
+ }else {
366
+ result[key] = this.getText(item[key], options);
367
+ }
368
+ return result;
369
+ }, {key: index, checked: !!item.checked});
370
+ };
371
+
372
+ const data = items.map((item, index) => {
373
+ return {
374
+ ...getItemObj(item, index),
375
+ children: item.children ? item.children.map((item2, index2) => getItemObj(item2, `${index}-${index2}`)) : null
376
+ };
377
+ });
378
+ return data;
379
+ };
380
+
381
+ getPropsByCheckbox = () => {
382
+ const {checkbox=true, checkedRows=[]} = this.props;
383
+ const rowClassName1 = (record) => {
384
+ return checkedRows.includes(record.key) ? variables('SuperTable3').select : '';
385
+ };
386
+ if (checkbox) {
387
+ return {
388
+ rowClassName: rowClassName1,
389
+ onRowClick: this.onRowClick,
390
+ rowSelection: {
391
+ selectedRowKeys: checkedRows,
392
+ onChange: this.onCheckChange,
393
+ getCheckboxProps: (record) => {
394
+ const checked = checkedRows.includes(record.key);
395
+ return {
396
+ checked,
397
+ }
398
+ },
399
+ }
400
+ }
401
+ }
402
+ };
403
+
404
+ getRowProps = (onRowClick) => {
405
+ return (record) => {
406
+ return {
407
+ onClick: () => onRowClick && onRowClick(record),
408
+ onDoubleClick: () => this.onDoubleClick(record)
409
+ };
410
+ };
411
+ };
412
+
413
+ getItems = () => {
414
+ const {items, childrenKey} = this.props;
415
+ let resItems = items;
416
+ if (childrenKey) {
417
+ resItems = items.map(o => o[childrenKey] && o[childrenKey].length ? {...o, children: o[childrenKey]} : o);
418
+ }
419
+ return resItems;
420
+ };
421
+
422
+ toTotalFooter = () => {
423
+ const {cols, items, checkedRows} = this.props;
424
+ const totalCols = cols.filter(item => item.total);
425
+ if (totalCols.length > 0) {
426
+ const checkedItems = items.filter((item, index) => checkedRows.includes(index));
427
+ const countItems = checkedItems.length ? checkedItems : items;
428
+ const totalItems = totalCols.map(({title, key, props={}}) => {
429
+ const value = countItems.reduce((result, item) => parseFloat((result + Number(item[key] || 0)).toFixed(props.precision || 6)), 0);
430
+ return {title, value};
431
+ });
432
+ return (
433
+ <div style={{height: '36px',lineHeight: '36px'}}>
434
+ <span style={{marginRight: `15px`}}>{checkedItems.length ? '【当页勾选汇总】' : '【当页汇总】'}</span>
435
+ {totalItems.map(({title, value}, index) => {
436
+ return (
437
+ <span key={index} style={{marginRight: `10px`}}>
438
+ <span>{title}: </span>
439
+ <span style={{color: '#01a4ff'}}>{value}</span>
440
+ </span>
441
+ )
442
+ })}
443
+ </div>
444
+ );
445
+ } else {
446
+ return null;
447
+ }
448
+ };
449
+
450
+ getProps = () => {
451
+ const {cols, isPaging=false, footer = null} = this.props;
452
+ const items = this.getItems();
453
+ const {onRowClick, ...extraProps} = this.getPropsByCheckbox(items);
454
+ const renderProps = {
455
+ className: variables('SuperTable3'),
456
+ columns: this.getColumns(cols, items),
457
+ dataSource: this.getDataSource(items, cols),
458
+ size: 'small',
459
+ pagination: isPaging,
460
+ scroll: {x: true},
461
+ onChange: this.onTableChange,
462
+ onRow: this.getRowProps(onRowClick),
463
+ components: {},
464
+ footer: footer ? footer : this.toTotalFooter,
465
+ ...extraProps
466
+ };
467
+ return renderProps;
468
+ };
469
+
470
+ setScroll = () => {
471
+ const {maxHeight} = this.props;
472
+ if (maxHeight && this.getItems().length) {
473
+ const root = ReactDOM.findDOMNode(this);
474
+ const container = root.getElementsByClassName('ant-table-body')[0];
475
+ const header = root.getElementsByClassName('ant-table-thead')[0];
476
+ fixed(container, header, maxHeight);
477
+ }
478
+ };
479
+
480
+ shouldComponentUpdate(props, state) {
481
+ const keys = ['cols', 'items', 'maxHeight', 'checkedRows', 'sortInfo', 'filterInfo'];
482
+ return keys.some(key => props[key] !== this.props[key]) || state.filterVisibleKey !== this.state.filterVisibleKey;
483
+ }
484
+
485
+ componentDidMount() {
486
+ this.setScroll();
487
+ }
488
+
489
+ componentDidUpdate() {
490
+ this.setScroll();
491
+ }
492
+
493
+ render() {
494
+ return <Table {...this.getProps()} key={this.props.items.length} />;
495
+ }
496
+ }
497
+
498
+ export default SuperTable;
@@ -0,0 +1,34 @@
1
+
2
+ const isFirefox = () => {
3
+ return navigator.userAgent.indexOf('Firefox') > 0;
4
+ };
5
+
6
+ const getComputedStyle = (element) => {
7
+ return window.getComputedStyle ? window.getComputedStyle(element, null) : element.currentStyle;
8
+ }
9
+
10
+ const fixed = (container, header, maxHeight, totalFooter={}) => {
11
+ container.style.overflowY = 'auto';
12
+ container.style.maxHeight = maxHeight;
13
+ if (isFirefox()) {
14
+ container.style.position = 'relative';
15
+ header.style.top = '0';
16
+ header.style.position = 'sticky';
17
+ header.style.zIndex = '1';
18
+ } else {
19
+ header.parentNode.appendChild(header);
20
+ }
21
+ const containerHeight = Number(getComputedStyle(container).height.replace('px', ''))
22
+ const translateHeight = containerHeight - 10 - container.scrollHeight;
23
+ const {pageTotalElement, searchTotalElement} = totalFooter;
24
+ pageTotalElement && (pageTotalElement.style.transform = `translateY(${translateHeight + container.scrollTop}px)`);
25
+ searchTotalElement && (searchTotalElement.style.transform = `translateY(${translateHeight + container.scrollTop}px)`);
26
+ container.onscroll = () => {
27
+ if (container.scrollTop + containerHeight - 10 > container.scrollHeight) return;
28
+ !isFirefox() && (header.style.transform = `translateY(${container.scrollTop}px)`);
29
+ pageTotalElement && (pageTotalElement.style.transform = `translateY(${translateHeight + container.scrollTop}px)`);
30
+ searchTotalElement && (searchTotalElement.style.transform = `translateY(${translateHeight + container.scrollTop}px)`);
31
+ };
32
+ };
33
+
34
+ export default fixed;
@@ -0,0 +1,128 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import {Button, Popconfirm, Icon, Dropdown, Menu} from 'antd';
4
+ import variables from '../variables';
5
+ const MenuItem = Menu.Item;
6
+ const SubMenu = Menu.SubMenu;
7
+
8
+ let clicktag = 0; //被点击标识
9
+
10
+ /**
11
+ * key: 用于标识菜单项
12
+ * title: 菜单项上的文字
13
+ * subMenu: [可选],菜单项子列表,包含key和title的对象数组,此时点击菜单项不触发事件,只有点击子列表项才会触发onSubClick事件
14
+ */
15
+ const MenuType = {
16
+ key: PropTypes.string.isRequired,
17
+ title: PropTypes.string.isRequired,
18
+ subMenu: PropTypes.array
19
+ };
20
+
21
+ /**
22
+ * key: 用于标识按钮
23
+ * title: 按钮上的文字
24
+ * bsStyle: 按钮样式,与antd中Button的type取值一样
25
+ * confirm: 触发按钮事件前,是否需要用户确认,以及确认的提示文字;为空串则不会触发确认提示
26
+ * menu: [可选],下拉菜单项,有此属性时点击按钮不触发事件,菜单项如果仅是包含key和title的对象,点击菜单项会触发onClick事件
27
+ * 菜单项如果是包含key、title、subMenu的对象,则点击此菜单项不触发事件,必须点击子列表项时才会触发onSubClick事件
28
+ * loading: 是否正在加载,与antd中Button的loading取值一样
29
+ */
30
+ const ButtonType = {
31
+ key: PropTypes.string.isRequired,
32
+ title: PropTypes.string.isRequired,
33
+ bsStyle: PropTypes.string,
34
+ confirm: PropTypes.string,
35
+ menu: PropTypes.arrayOf(PropTypes.shape(MenuType)),
36
+ loading: PropTypes.bool,
37
+ };
38
+
39
+ const ButtonEx = ({type, children, ...props}) => {
40
+ props[type === 'primary-o' ? 'data-btn-type' : 'type'] = type;
41
+ return <Button {...props}>{children}</Button>;
42
+ };
43
+
44
+ /**
45
+ * onClick: 纯按钮点击时或按钮下拉项中无子菜单列表项点击触发,原型为function(key)
46
+ * onSubClick: 按钮为下拉时下拉项子列表项点击时触发,原型为function(key, subKey)
47
+ */
48
+ class SuperToolbar extends React.Component {
49
+ static propTypes = {
50
+ buttons: PropTypes.arrayOf(PropTypes.shape(ButtonType)).isRequired,
51
+ size: PropTypes.oneOf(['small', 'default', 'large']),
52
+ onClick: PropTypes.func,
53
+ onSubClick: PropTypes.func
54
+ };
55
+
56
+ onClick = (e) => {
57
+ const {onClick, onSubClick} = this.props;
58
+ const key = typeof e === 'object' ? e.key : e;
59
+ if (typeof e === 'object' && e.keyPath.length === 2 && onSubClick) {
60
+ onSubClick(e.keyPath[1], e.keyPath[0]);
61
+ } else if (onClick) {
62
+ if(clicktag === 0){
63
+ clicktag = 1;
64
+ onClick(key);
65
+ //1秒过后可以再次点击
66
+ setTimeout(function () { clicktag = 0 }, 1000);
67
+ }else{
68
+ console.log('请勿频繁操作!');
69
+ }
70
+ }
71
+ };
72
+
73
+ toSubMenu = ({key, title, subMenu=[]}) => {
74
+ return (
75
+ <SubMenu key={key} title={title}>
76
+ {subMenu.map(({key, title}) => <MenuItem key={key}>{title}</MenuItem>)}
77
+ </SubMenu>
78
+ );
79
+ };
80
+
81
+ toMenu = (menu) => {
82
+ return (
83
+ <Menu onClick={this.onClick}>
84
+ {
85
+ menu.map((item) => {
86
+ const {key, title, subMenu} = item;
87
+ if (subMenu) {
88
+ return this.toSubMenu(item);
89
+ } else {
90
+ return <MenuItem key={key}>{title}</MenuItem>;
91
+ }
92
+ })
93
+ }
94
+ </Menu>
95
+ );
96
+ };
97
+
98
+ toButton = ({key, title, bsStyle: type, confirm, menu, loading}) => {
99
+ const onClick = this.onClick.bind(this, key);
100
+ const {size='small'} = this.props;
101
+ if (menu && menu.length) {
102
+ return (
103
+ <Dropdown key={key} trigger={['hover']} overlay={this.toMenu(menu)}>
104
+ <ButtonEx {...{size, type}}>{title}<Icon type='down'/></ButtonEx>
105
+ </Dropdown>
106
+ );
107
+ } else if (!confirm) {
108
+ return <ButtonEx {...{key, size, type, onClick, loading}}>{title}</ButtonEx>;
109
+ } else {
110
+ return (
111
+ <Popconfirm key={key} title={confirm} onConfirm={onClick}>
112
+ <ButtonEx {...{size, type, loading}}>{title}</ButtonEx>
113
+ </Popconfirm>
114
+ );
115
+ }
116
+ };
117
+
118
+ render() {
119
+ const {buttons} = this.props;
120
+ return (
121
+ <div className={variables('SuperToolbar')} role='toolbar'>
122
+ {buttons.map(this.toButton)}
123
+ </div>
124
+ );
125
+ }
126
+ }
127
+
128
+ export default SuperToolbar;