amis 1.9.0-beta.12 → 1.9.0-beta.15

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 (365) hide show
  1. package/lib/Schema.d.ts +4 -2
  2. package/lib/Schema.js.map +1 -1
  3. package/lib/SchemaRenderer.d.ts +2 -2
  4. package/lib/SchemaRenderer.js +3 -3
  5. package/lib/SchemaRenderer.js.map +2 -2
  6. package/lib/actions/Action.d.ts +8 -6
  7. package/lib/actions/Action.js.map +2 -2
  8. package/lib/actions/AjaxAction.d.ts +10 -7
  9. package/lib/actions/AjaxAction.js +27 -21
  10. package/lib/actions/AjaxAction.js.map +2 -2
  11. package/lib/actions/BreakAction.d.ts +2 -2
  12. package/lib/actions/BreakAction.js.map +1 -1
  13. package/lib/actions/BroadcastAction.d.ts +3 -3
  14. package/lib/actions/BroadcastAction.js +3 -2
  15. package/lib/actions/BroadcastAction.js.map +2 -2
  16. package/lib/actions/CmptAction.d.ts +2 -2
  17. package/lib/actions/CmptAction.js +7 -9
  18. package/lib/actions/CmptAction.js.map +2 -2
  19. package/lib/actions/ContinueAction.d.ts +2 -2
  20. package/lib/actions/ContinueAction.js.map +1 -1
  21. package/lib/actions/CopyAction.d.ts +7 -4
  22. package/lib/actions/CopyAction.js +8 -6
  23. package/lib/actions/CopyAction.js.map +2 -2
  24. package/lib/actions/CustomAction.d.ts +2 -2
  25. package/lib/actions/CustomAction.js.map +1 -1
  26. package/lib/actions/DialogAction.d.ts +14 -8
  27. package/lib/actions/DialogAction.js +6 -6
  28. package/lib/actions/DialogAction.js.map +2 -2
  29. package/lib/actions/DrawerAction.d.ts +3 -3
  30. package/lib/actions/DrawerAction.js.map +1 -1
  31. package/lib/actions/EmailAction.d.ts +10 -7
  32. package/lib/actions/EmailAction.js +4 -5
  33. package/lib/actions/EmailAction.js.map +2 -2
  34. package/lib/actions/LinkAction.d.ts +19 -11
  35. package/lib/actions/LinkAction.js +6 -5
  36. package/lib/actions/LinkAction.js.map +2 -2
  37. package/lib/actions/LoopAction.d.ts +6 -3
  38. package/lib/actions/LoopAction.js +22 -20
  39. package/lib/actions/LoopAction.js.map +2 -2
  40. package/lib/actions/PageAction.d.ts +8 -5
  41. package/lib/actions/PageAction.js +3 -2
  42. package/lib/actions/PageAction.js.map +2 -2
  43. package/lib/actions/ParallelAction.d.ts +2 -2
  44. package/lib/actions/ParallelAction.js.map +1 -1
  45. package/lib/actions/SwitchAction.d.ts +2 -2
  46. package/lib/actions/SwitchAction.js.map +1 -1
  47. package/lib/actions/ToastAction.d.ts +2 -2
  48. package/lib/actions/ToastAction.js +6 -4
  49. package/lib/actions/ToastAction.js.map +2 -2
  50. package/lib/components/Editor.d.ts +84 -84
  51. package/lib/components/InputBox.js +1 -1
  52. package/lib/components/InputBox.js.map +2 -2
  53. package/lib/components/Pagination.d.ts +1175 -0
  54. package/lib/components/Pagination.js +274 -0
  55. package/lib/components/Pagination.js.map +13 -0
  56. package/lib/components/PickerContainer.d.ts +1 -0
  57. package/lib/components/PickerContainer.js +3 -2
  58. package/lib/components/PickerContainer.js.map +2 -2
  59. package/lib/components/Rating.js +11 -9
  60. package/lib/components/Rating.js.map +2 -2
  61. package/lib/components/Select.js +3 -3
  62. package/lib/components/Select.js.map +2 -2
  63. package/lib/components/Tag.d.ts +148 -0
  64. package/lib/components/Tag.js +96 -0
  65. package/lib/components/Tag.js.map +13 -0
  66. package/lib/components/TooltipWrapper.d.ts +25 -21
  67. package/lib/components/TooltipWrapper.js +11 -1
  68. package/lib/components/TooltipWrapper.js.map +2 -2
  69. package/lib/components/TransferDropDown.d.ts +85 -84
  70. package/lib/components/TransferDropDown.js +2 -2
  71. package/lib/components/TransferDropDown.js.map +2 -2
  72. package/lib/components/Tree.d.ts +84 -84
  73. package/lib/components/formula/VariableList.d.ts +1 -0
  74. package/lib/components/formula/VariableList.js.map +2 -2
  75. package/lib/components/icons.js +2 -0
  76. package/lib/components/icons.js.map +2 -2
  77. package/lib/components/index.d.ts +4 -1
  78. package/lib/components/index.js +7 -1
  79. package/lib/components/index.js.map +2 -2
  80. package/lib/components/schema-editor/Array.d.ts +11 -0
  81. package/lib/components/schema-editor/Array.js +66 -0
  82. package/lib/components/schema-editor/Array.js.map +13 -0
  83. package/lib/components/schema-editor/Common.d.ts +29 -0
  84. package/lib/components/schema-editor/Common.js +69 -0
  85. package/lib/components/schema-editor/Common.js.map +13 -0
  86. package/lib/components/schema-editor/Item.d.ts +9 -0
  87. package/lib/components/schema-editor/Item.js +31 -0
  88. package/lib/components/schema-editor/Item.js.map +13 -0
  89. package/lib/components/schema-editor/Object.d.ts +44 -0
  90. package/lib/components/schema-editor/Object.js +191 -0
  91. package/lib/components/schema-editor/Object.js.map +13 -0
  92. package/lib/components/schema-editor/SchemaVariableList.d.ts +316 -0
  93. package/lib/components/schema-editor/SchemaVariableList.js +74 -0
  94. package/lib/components/schema-editor/SchemaVariableList.js.map +13 -0
  95. package/lib/components/schema-editor/SchemaVariableListPicker.d.ts +305 -0
  96. package/lib/components/schema-editor/SchemaVariableListPicker.js +32 -0
  97. package/lib/components/schema-editor/SchemaVariableListPicker.js.map +13 -0
  98. package/lib/components/schema-editor/index.d.ts +520 -0
  99. package/lib/components/schema-editor/index.js +118 -0
  100. package/lib/components/schema-editor/index.js.map +13 -0
  101. package/lib/components/table/Cell.d.ts +930 -0
  102. package/lib/components/table/Cell.js +36 -0
  103. package/lib/components/table/Cell.js.map +13 -0
  104. package/lib/components/table/HeadCellDropDown.d.ts +514 -0
  105. package/lib/components/table/HeadCellDropDown.js +52 -0
  106. package/lib/components/table/HeadCellDropDown.js.map +13 -0
  107. package/lib/components/table/HeadCellFilter.d.ts +771 -0
  108. package/lib/components/table/HeadCellFilter.js +106 -0
  109. package/lib/components/table/HeadCellFilter.js.map +13 -0
  110. package/lib/components/table/HeadCellSelect.d.ts +672 -0
  111. package/lib/components/table/HeadCellSelect.js +46 -0
  112. package/lib/components/table/HeadCellSelect.js.map +13 -0
  113. package/lib/components/table/HeadCellSort.d.ts +498 -0
  114. package/lib/components/table/HeadCellSort.js +67 -0
  115. package/lib/components/table/HeadCellSort.js.map +13 -0
  116. package/lib/components/table/index.d.ts +1355 -0
  117. package/lib/components/table/index.js +1095 -0
  118. package/lib/components/table/index.js.map +13 -0
  119. package/lib/env.d.ts +2 -4
  120. package/lib/env.js.map +2 -2
  121. package/lib/factory.js +0 -95
  122. package/lib/factory.js.map +2 -2
  123. package/lib/icons/dot.js +11 -0
  124. package/lib/index.d.ts +6 -1
  125. package/lib/index.js +9 -2
  126. package/lib/index.js.map +2 -2
  127. package/lib/locale/de-DE.js +18 -1
  128. package/lib/locale/de-DE.js.map +2 -2
  129. package/lib/locale/en-US.js +18 -1
  130. package/lib/locale/en-US.js.map +2 -2
  131. package/lib/locale/zh-CN.js +20 -1
  132. package/lib/locale/zh-CN.js.map +2 -2
  133. package/lib/renderers/Action.js +0 -2
  134. package/lib/renderers/Action.js.map +2 -2
  135. package/lib/renderers/Carousel.d.ts +5 -1
  136. package/lib/renderers/Carousel.js +18 -5
  137. package/lib/renderers/Carousel.js.map +2 -2
  138. package/lib/renderers/Form/ButtonGroupSelect.d.ts +2 -0
  139. package/lib/renderers/Form/ButtonGroupSelect.js +7 -0
  140. package/lib/renderers/Form/ButtonGroupSelect.js.map +2 -2
  141. package/lib/renderers/Form/Checkbox.js +3 -4
  142. package/lib/renderers/Form/Checkbox.js.map +2 -2
  143. package/lib/renderers/Form/Checkboxes.d.ts +2 -1
  144. package/lib/renderers/Form/Checkboxes.js +19 -14
  145. package/lib/renderers/Form/Checkboxes.js.map +2 -2
  146. package/lib/renderers/Form/Combo.js +23 -4
  147. package/lib/renderers/Form/Combo.js.map +2 -2
  148. package/lib/renderers/Form/DiffEditor.d.ts +126 -18
  149. package/lib/renderers/Form/Editor.d.ts +412 -112
  150. package/lib/renderers/Form/Editor.js +10 -1
  151. package/lib/renderers/Form/Editor.js.map +2 -2
  152. package/lib/renderers/Form/InputExcel.js +6 -1
  153. package/lib/renderers/Form/InputExcel.js.map +2 -2
  154. package/lib/renderers/Form/InputFile.js +1 -2
  155. package/lib/renderers/Form/InputFile.js.map +2 -2
  156. package/lib/renderers/Form/InputTree.js +1 -1
  157. package/lib/renderers/Form/InputTree.js.map +2 -2
  158. package/lib/renderers/Form/Item.d.ts +0 -6
  159. package/lib/renderers/Form/JSONSchemaEditor.d.ts +41 -0
  160. package/lib/renderers/Form/JSONSchemaEditor.js +33 -0
  161. package/lib/renderers/Form/JSONSchemaEditor.js.map +13 -0
  162. package/lib/renderers/Form/ListSelect.d.ts +2 -0
  163. package/lib/renderers/Form/ListSelect.js +7 -0
  164. package/lib/renderers/Form/ListSelect.js.map +2 -2
  165. package/lib/renderers/Form/Options.js +1 -0
  166. package/lib/renderers/Form/Options.js.map +2 -2
  167. package/lib/renderers/Form/Select.js +12 -1
  168. package/lib/renderers/Form/Select.js.map +2 -2
  169. package/lib/renderers/Form/TabsTransfer.d.ts +1 -1
  170. package/lib/renderers/Form/TabsTransfer.js +2 -2
  171. package/lib/renderers/Form/TabsTransfer.js.map +2 -2
  172. package/lib/renderers/Form/TreeSelect.d.ts +4 -0
  173. package/lib/renderers/Form/TreeSelect.js +2 -2
  174. package/lib/renderers/Form/TreeSelect.js.map +2 -2
  175. package/lib/renderers/Form/wrapControl.js +10 -5
  176. package/lib/renderers/Form/wrapControl.js.map +2 -2
  177. package/lib/renderers/Pagination.d.ts +49 -30
  178. package/lib/renderers/Pagination.js +3 -132
  179. package/lib/renderers/Pagination.js.map +2 -2
  180. package/lib/renderers/Table/HeadCellSearchDropdown.js +0 -1
  181. package/lib/renderers/Table/HeadCellSearchDropdown.js.map +2 -2
  182. package/lib/renderers/Table-v2/HeadCellSearchDropdown.d.ts +29 -0
  183. package/lib/renderers/Table-v2/HeadCellSearchDropdown.js +158 -0
  184. package/lib/renderers/Table-v2/HeadCellSearchDropdown.js.map +13 -0
  185. package/lib/renderers/Table-v2/TableCell.d.ts +6 -0
  186. package/lib/renderers/Table-v2/TableCell.js +28 -0
  187. package/lib/renderers/Table-v2/TableCell.js.map +13 -0
  188. package/lib/renderers/Table-v2/index.d.ts +256 -0
  189. package/lib/renderers/Table-v2/index.js +548 -0
  190. package/lib/renderers/Table-v2/index.js.map +13 -0
  191. package/lib/renderers/Tabs.js +1 -1
  192. package/lib/renderers/Tabs.js.map +2 -2
  193. package/lib/renderers/Tag.d.ts +66 -0
  194. package/lib/renderers/Tag.js +53 -0
  195. package/lib/renderers/Tag.js.map +13 -0
  196. package/lib/renderers/Wizard.js +3 -3
  197. package/lib/renderers/Wizard.js.map +2 -2
  198. package/lib/schemaExtend.js +24 -30
  199. package/lib/schemaExtend.js.map +2 -2
  200. package/lib/store/combo.d.ts +140 -20
  201. package/lib/store/form.d.ts +56 -8
  202. package/lib/store/formItem.d.ts +3 -1
  203. package/lib/store/formItem.js +3 -1
  204. package/lib/store/formItem.js.map +2 -2
  205. package/lib/store/index.js +2 -0
  206. package/lib/store/index.js.map +2 -2
  207. package/lib/store/table-v2.d.ts +308 -0
  208. package/lib/store/table-v2.js +452 -0
  209. package/lib/store/table-v2.js.map +13 -0
  210. package/lib/store/table.d.ts +112 -16
  211. package/lib/store/table.js +1 -1
  212. package/lib/store/table.js.map +2 -2
  213. package/lib/themes/ang-ie11.css +1686 -120
  214. package/lib/themes/ang.css +1807 -208
  215. package/lib/themes/ang.css.map +1 -1
  216. package/lib/themes/antd-ie11.css +1667 -101
  217. package/lib/themes/antd.css +1789 -201
  218. package/lib/themes/antd.css.map +1 -1
  219. package/lib/themes/cxd-ie11.css +1662 -97
  220. package/lib/themes/cxd.css +1983 -394
  221. package/lib/themes/cxd.css.map +1 -1
  222. package/lib/themes/dark-ie11.css +1667 -101
  223. package/lib/themes/dark.css +1789 -201
  224. package/lib/themes/dark.css.map +1 -1
  225. package/lib/themes/default-ie11.css +1662 -97
  226. package/lib/themes/default.css +1983 -394
  227. package/lib/themes/default.css.map +1 -1
  228. package/lib/utils/DataSchema.d.ts +25 -0
  229. package/lib/utils/DataSchema.js +104 -0
  230. package/lib/utils/DataSchema.js.map +13 -0
  231. package/lib/utils/DataScope.d.ts +23 -0
  232. package/lib/utils/DataScope.js +140 -0
  233. package/lib/utils/DataScope.js.map +13 -0
  234. package/lib/utils/handleAction.js +1 -1
  235. package/lib/utils/handleAction.js.map +2 -2
  236. package/lib/utils/renderer-event.d.ts +8 -2
  237. package/lib/utils/renderer-event.js +102 -1
  238. package/lib/utils/renderer-event.js.map +2 -2
  239. package/package.json +3 -2
  240. package/schema.json +1476 -469
  241. package/scss/_properties.scss +69 -0
  242. package/scss/components/_button.scss +37 -39
  243. package/scss/components/_context-menu.scss +3 -18
  244. package/scss/components/_json-schema-editor.scss +126 -0
  245. package/scss/components/_pagination.scss +104 -23
  246. package/scss/components/_result-box.scss +2 -2
  247. package/scss/components/_table-v2.scss +912 -0
  248. package/scss/components/_tag.scss +177 -0
  249. package/scss/components/form/_selection.scss +1 -14
  250. package/scss/components/form/_text.scss +1 -1
  251. package/scss/themes/_antd-variables.scss +0 -13
  252. package/scss/themes/_common.scss +3 -0
  253. package/scss/themes/_cxd-variables.scss +7 -17
  254. package/scss/themes/_dark-variables.scss +0 -13
  255. package/scss/themes/cxd.scss +1 -1
  256. package/sdk/ang-ie11.css +2240 -227
  257. package/sdk/ang.css +2905 -859
  258. package/sdk/antd-ie11.css +2233 -220
  259. package/sdk/antd.css +2905 -870
  260. package/sdk/barcode.js +51 -51
  261. package/sdk/charts.js +14 -14
  262. package/sdk/codemirror.js +7 -7
  263. package/sdk/color-picker.js +65 -65
  264. package/sdk/cropperjs.js +2 -2
  265. package/sdk/cxd-ie11.css +2223 -211
  266. package/sdk/cxd.css +2911 -875
  267. package/sdk/dark-ie11.css +2233 -220
  268. package/sdk/dark.css +2905 -870
  269. package/sdk/exceljs.js +1 -1
  270. package/sdk/locale/de-DE.js +18 -1
  271. package/sdk/markdown.js +69 -69
  272. package/sdk/papaparse.js +1 -1
  273. package/sdk/renderers/Form/CityDB.js +1 -1
  274. package/sdk/rest.js +16 -16
  275. package/sdk/rich-text.js +62 -62
  276. package/sdk/sdk-ie11.css +2223 -211
  277. package/sdk/sdk.css +2911 -875
  278. package/sdk/sdk.js +1326 -1270
  279. package/sdk/thirds/hls.js/hls.js +1 -1
  280. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  281. package/sdk/tinymce.js +57 -57
  282. package/src/Schema.ts +7 -0
  283. package/src/SchemaRenderer.tsx +4 -5
  284. package/src/actions/Action.ts +7 -6
  285. package/src/actions/AjaxAction.ts +33 -24
  286. package/src/actions/BreakAction.ts +2 -2
  287. package/src/actions/BroadcastAction.ts +6 -5
  288. package/src/actions/CmptAction.ts +5 -6
  289. package/src/actions/ContinueAction.ts +2 -2
  290. package/src/actions/CopyAction.ts +14 -8
  291. package/src/actions/CustomAction.ts +2 -2
  292. package/src/actions/DialogAction.ts +16 -10
  293. package/src/actions/DrawerAction.ts +3 -3
  294. package/src/actions/EmailAction.ts +12 -12
  295. package/src/actions/LinkAction.ts +34 -14
  296. package/src/actions/LoopAction.ts +13 -8
  297. package/src/actions/PageAction.ts +9 -6
  298. package/src/actions/ParallelAction.ts +2 -2
  299. package/src/actions/SwitchAction.ts +2 -2
  300. package/src/actions/ToastAction.ts +9 -5
  301. package/src/components/InputBox.tsx +1 -0
  302. package/src/components/Pagination.tsx +446 -0
  303. package/src/components/PickerContainer.tsx +8 -5
  304. package/src/components/Rating.tsx +16 -9
  305. package/src/components/Select.tsx +3 -3
  306. package/src/components/Tag.tsx +179 -0
  307. package/src/components/TooltipWrapper.tsx +14 -1
  308. package/src/components/TransferDropDown.tsx +3 -0
  309. package/src/components/formula/VariableList.tsx +1 -0
  310. package/src/components/icons.tsx +2 -0
  311. package/src/components/index.tsx +7 -1
  312. package/src/components/schema-editor/Array.tsx +95 -0
  313. package/src/components/schema-editor/Common.tsx +138 -0
  314. package/src/components/schema-editor/Item.tsx +36 -0
  315. package/src/components/schema-editor/Object.tsx +299 -0
  316. package/src/components/schema-editor/SchemaVariableList.tsx +97 -0
  317. package/src/components/schema-editor/SchemaVariableListPicker.tsx +66 -0
  318. package/src/components/schema-editor/index.tsx +211 -0
  319. package/src/components/table/Cell.tsx +70 -0
  320. package/src/components/table/HeadCellDropDown.tsx +115 -0
  321. package/src/components/table/HeadCellFilter.tsx +193 -0
  322. package/src/components/table/HeadCellSelect.tsx +86 -0
  323. package/src/components/table/HeadCellSort.tsx +102 -0
  324. package/src/components/table/index.tsx +1681 -0
  325. package/src/env.tsx +7 -14
  326. package/src/factory.tsx +3 -106
  327. package/src/icons/dot.svg +11 -0
  328. package/src/index.tsx +8 -1
  329. package/src/locale/de-DE.ts +18 -1
  330. package/src/locale/en-US.ts +18 -1
  331. package/src/locale/zh-CN.ts +20 -1
  332. package/src/renderers/Action.tsx +1 -1
  333. package/src/renderers/Carousel.tsx +21 -6
  334. package/src/renderers/Form/ButtonGroupSelect.tsx +10 -1
  335. package/src/renderers/Form/Checkbox.tsx +4 -4
  336. package/src/renderers/Form/Checkboxes.tsx +31 -25
  337. package/src/renderers/Form/Combo.tsx +20 -4
  338. package/src/renderers/Form/Editor.tsx +15 -1
  339. package/src/renderers/Form/InputExcel.tsx +6 -1
  340. package/src/renderers/Form/InputFile.tsx +1 -2
  341. package/src/renderers/Form/InputTree.tsx +1 -1
  342. package/src/renderers/Form/JSONSchemaEditor.tsx +67 -0
  343. package/src/renderers/Form/ListSelect.tsx +9 -1
  344. package/src/renderers/Form/Options.tsx +1 -1
  345. package/src/renderers/Form/Select.tsx +7 -0
  346. package/src/renderers/Form/TabsTransfer.tsx +2 -2
  347. package/src/renderers/Form/TreeSelect.tsx +8 -1
  348. package/src/renderers/Form/wrapControl.tsx +11 -5
  349. package/src/renderers/Pagination.tsx +65 -253
  350. package/src/renderers/Table/HeadCellSearchDropdown.tsx +0 -1
  351. package/src/renderers/Table-v2/HeadCellSearchDropdown.tsx +244 -0
  352. package/src/renderers/Table-v2/TableCell.tsx +19 -0
  353. package/src/renderers/Table-v2/index.tsx +1140 -0
  354. package/src/renderers/Tabs.tsx +1 -1
  355. package/src/renderers/Tag.tsx +128 -0
  356. package/src/renderers/Wizard.tsx +3 -3
  357. package/src/schemaExtend.ts +24 -28
  358. package/src/store/formItem.ts +5 -1
  359. package/src/store/index.ts +2 -0
  360. package/src/store/table-v2.ts +646 -0
  361. package/src/store/table.ts +1 -1
  362. package/src/utils/DataSchema.ts +131 -0
  363. package/src/utils/DataScope.ts +190 -0
  364. package/src/utils/handleAction.ts +1 -1
  365. package/src/utils/renderer-event.ts +113 -2
@@ -0,0 +1,1140 @@
1
+ import React from 'react';
2
+ import {findDOMNode} from 'react-dom';
3
+ import {isAlive} from 'mobx-state-tree';
4
+ import cloneDeep from 'lodash/cloneDeep';
5
+ import isEqual from 'lodash/isEqual';
6
+
7
+ import {IScopedContext} from '../../Scoped';
8
+ import {Renderer, RendererProps} from '../../factory';
9
+ import {Action} from '../../types';
10
+ import Table from '../../components/table';
11
+ import {BaseSchema, SchemaObject, SchemaTokenizeableString} from '../../Schema';
12
+ import {
13
+ isObject,
14
+ anyChanged,
15
+ difference,
16
+ createObject
17
+ } from '../../utils/helper';
18
+ import {
19
+ resolveVariableAndFilter,
20
+ isPureVariable,
21
+ resolveVariable
22
+ } from '../../utils/tpl-builtin';
23
+ import {evalExpression, filter} from '../../utils/tpl';
24
+ import {isEffectiveApi} from '../../utils/api';
25
+ import Checkbox from '../../components/Checkbox';
26
+ import {BadgeSchema} from '../../components/Badge';
27
+ import {TableStoreV2, ITableStore, IColumn, IRow} from '../../store/table-v2';
28
+
29
+ import ColumnToggler, {ColumnTogglerProps} from '../Table/ColumnToggler';
30
+ import {HeadCellSearchDropDown} from './HeadCellSearchDropdown';
31
+ import './TableCell';
32
+
33
+ /**
34
+ * Table 表格v2渲染器。
35
+ * 文档:https://baidu.gitee.io/amis/docs/components/table-v2
36
+ */
37
+
38
+ export interface CellSpan {
39
+ colIndex: number;
40
+ rowIndex: number;
41
+ colSpan?: number;
42
+ rowSpan?: number;
43
+ }
44
+
45
+ export interface RenderProps {
46
+ colSpan?: number;
47
+ rowSpan?: number;
48
+ }
49
+
50
+ export interface ColumnSchema {
51
+ /**
52
+ * 指定列唯一标识
53
+ */
54
+ key: string;
55
+
56
+ /**
57
+ * 指定列标题
58
+ */
59
+ title: string | SchemaObject;
60
+
61
+ /**
62
+ * 指定列内容渲染器
63
+ */
64
+ type?: string;
65
+
66
+ /**
67
+ * 指定行合并表达式
68
+ */
69
+ rowSpanExpr?: string;
70
+
71
+ /**
72
+ * 指定列合并表达式
73
+ */
74
+ colSpanExpr?: string;
75
+
76
+ /**
77
+ * 表头分组
78
+ */
79
+ children?: Array<ColumnSchema>;
80
+
81
+ /**
82
+ * 可复制
83
+ */
84
+ copyable?: boolean;
85
+
86
+ /**
87
+ * 列表头提示
88
+ */
89
+ remark?: string;
90
+
91
+ /**
92
+ * 快速搜索
93
+ */
94
+ searchable?: boolean | SchemaObject;
95
+
96
+ /**
97
+ * 快速排序
98
+ */
99
+ sorter?: boolean;
100
+
101
+ /**
102
+ * 内容居左、居中、居右
103
+ */
104
+ align?: string;
105
+
106
+ /**
107
+ * 是否固定在左侧/右侧
108
+ */
109
+ fixed?: boolean | string;
110
+
111
+ /**
112
+ * 当前列是否展示
113
+ */
114
+ toggled?: boolean;
115
+ }
116
+
117
+ export interface RowSelectionOptionsSchema {
118
+ /**
119
+ * 选择类型 选择全部
120
+ */
121
+ key: string; // 选择类型 目前只支持all、invert、none、odd、even
122
+
123
+ /**
124
+ * 选项显示文本
125
+ */
126
+ text: string;
127
+ }
128
+
129
+ export interface RowSelectionSchema {
130
+ /**
131
+ * 选择类型 单选/多选
132
+ */
133
+ type: string;
134
+
135
+ /**
136
+ * 对应数据源的key值
137
+ */
138
+ keyField?: string;
139
+
140
+ /**
141
+ * 行是否禁用表达式
142
+ */
143
+ disableOn?: string;
144
+
145
+ /**
146
+ * 自定义选择菜单
147
+ */
148
+ selections?: Array<RowSelectionOptionsSchema>;
149
+
150
+ /**
151
+ * 已选择的key值
152
+ */
153
+ selectedRowKeys?: Array<string | number>;
154
+
155
+ /**
156
+ * 已选择的key值表达式
157
+ */
158
+ selectedRowKeysExpr: string;
159
+
160
+ /**
161
+ * 已选择的key值表达式
162
+ */
163
+ columnWidth?: number;
164
+
165
+ /**
166
+ * 是否点击行触发选中或取消选中
167
+ */
168
+ rowClick?: boolean;
169
+ }
170
+
171
+ export interface ExpandableSchema {
172
+ /**
173
+ * 对应数据源的key值
174
+ */
175
+ keyField: string;
176
+
177
+ /**
178
+ * 行是否可展开表达式
179
+ */
180
+ expandableOn: string;
181
+
182
+ /**
183
+ * 展开行自定义样式表达式
184
+ */
185
+ expandedRowClassNameExpr: string;
186
+
187
+ /**
188
+ * 已展开的key值
189
+ */
190
+ expandedRowKeys: Array<string | number>;
191
+
192
+ /**
193
+ * 已展开的key值表达式
194
+ */
195
+ expandedRowKeysExpr: string;
196
+ }
197
+
198
+ export interface TableSchemaV2 extends BaseSchema {
199
+ /**
200
+ * 指定为表格类型
201
+ */
202
+ type: 'table-v2';
203
+
204
+ /**
205
+ * 表格标题
206
+ */
207
+ title?: string | SchemaObject | Array<SchemaObject>;
208
+
209
+ /**
210
+ * 表格数据源
211
+ */
212
+ source: SchemaTokenizeableString;
213
+
214
+ /**
215
+ * 表格可自定义列
216
+ */
217
+ columnsTogglable: boolean;
218
+
219
+ /**
220
+ * 表格可自定义列的一些配置
221
+ */
222
+ columnsToggler: any;
223
+ // columnsToggler: ColumnTogglerProps;
224
+
225
+ /**
226
+ * 表格列配置
227
+ */
228
+ columns: Array<ColumnSchema>;
229
+
230
+ /**
231
+ * 表格可选择配置
232
+ */
233
+ rowSelection?: RowSelectionSchema;
234
+
235
+ /**
236
+ * 表格行可展开配置
237
+ */
238
+ expandable?: ExpandableSchema;
239
+
240
+ /**
241
+ * 表格行可展开内容配置
242
+ */
243
+ expandableBody?: Array<SchemaObject>;
244
+
245
+ /**
246
+ * 粘性头部
247
+ */
248
+ sticky?: boolean;
249
+
250
+ /**
251
+ * 加载中
252
+ */
253
+ loading?: boolean | string | SchemaObject;
254
+
255
+ /**
256
+ * 行角标
257
+ */
258
+ itemBadge?: BadgeSchema;
259
+
260
+ /**
261
+ * 指定挂载dom
262
+ */
263
+ popOverContainer?: any;
264
+
265
+ /**
266
+ * 嵌套展开记录的唯一标识
267
+ */
268
+ keyField?: string;
269
+
270
+ /**
271
+ * 数据源嵌套自定义字段名
272
+ */
273
+ childrenColumnName?: string;
274
+
275
+ /**
276
+ * 自定义行样式
277
+ */
278
+ rowClassNameExpr?: string;
279
+
280
+ /**
281
+ * 是否固定内容行高度
282
+ */
283
+ lineHeight?: string;
284
+
285
+ /**
286
+ * 是否展示边框
287
+ */
288
+ bordered?: boolean;
289
+
290
+ /**
291
+ * 是否展示表头
292
+ */
293
+ showHeader?: boolean;
294
+
295
+ /**
296
+ * 自定义表格样式
297
+ */
298
+ className?: string;
299
+
300
+ /**
301
+ * 指定表尾
302
+ */
303
+ footer?: string | SchemaObject | Array<SchemaObject>;
304
+ }
305
+
306
+ export interface TableV2Props extends RendererProps {
307
+ title?: string;
308
+ source?: string;
309
+ store: ITableStore;
310
+ togglable: boolean;
311
+ }
312
+
313
+ @Renderer({
314
+ type: 'table-v2',
315
+ storeType: TableStoreV2.name,
316
+ name: 'table-v2'
317
+ })
318
+ export class TableRenderer extends React.Component<TableV2Props, object> {
319
+ renderedToolbars: Array<string> = [];
320
+ control: any;
321
+
322
+ constructor(props: TableV2Props) {
323
+ super(props);
324
+
325
+ this.handleColumnToggle = this.handleColumnToggle.bind(this);
326
+ this.getPopOverContainer = this.getPopOverContainer.bind(this);
327
+ this.handleAction = this.handleAction.bind(this);
328
+ this.handleQuickChange = this.handleQuickChange.bind(this);
329
+ this.handleSave = this.handleSave.bind(this);
330
+ this.controlRef = this.controlRef.bind(this);
331
+
332
+ const {store, columnsTogglable, columns} = props;
333
+
334
+ store.update({columnsTogglable, columns});
335
+ TableRenderer.syncRows(store, props, undefined) && this.syncSelected();
336
+ }
337
+
338
+ controlRef(control: any) {
339
+ // 因为 control 有可能被 n 层 hoc 包裹。
340
+ while (control && control.getWrappedInstance) {
341
+ control = control.getWrappedInstance();
342
+ }
343
+
344
+ this.control = control;
345
+ }
346
+
347
+ syncSelected() {
348
+ const {store, rowSelection} = this.props;
349
+
350
+ rowSelection &&
351
+ rowSelection.onSelect &&
352
+ rowSelection.onSelectonSelect(
353
+ store.selectedRowKeys.map(item => item),
354
+ store.selectedRows.map(item => item.data)
355
+ );
356
+ }
357
+
358
+ static syncRows(
359
+ store: ITableStore,
360
+ props: TableV2Props,
361
+ prevProps?: TableV2Props
362
+ ) {
363
+ const source = props.source;
364
+ const value = props.value || props.items;
365
+ let rows: Array<object> = [];
366
+ let updateRows = false;
367
+
368
+ if (
369
+ Array.isArray(value) &&
370
+ (!prevProps || (prevProps.value || prevProps.items) !== value)
371
+ ) {
372
+ updateRows = true;
373
+ rows = value;
374
+ } else if (typeof source === 'string') {
375
+ const resolved = resolveVariableAndFilter(source, props.data, '| raw');
376
+ const prev = prevProps
377
+ ? resolveVariableAndFilter(source, prevProps.data, '| raw')
378
+ : null;
379
+
380
+ if (prev && prev === resolved) {
381
+ updateRows = false;
382
+ } else if (Array.isArray(resolved)) {
383
+ updateRows = true;
384
+ rows = resolved;
385
+ }
386
+ }
387
+ updateRows &&
388
+ store.initRows(
389
+ rows,
390
+ props.getEntryId,
391
+ props.reUseRow,
392
+ props.childrenColumnName
393
+ );
394
+
395
+ let selectedRowKeys: Array<string | number> = [];
396
+ // selectedRowKeysExpr比selectedRowKeys优先级高
397
+ if (props.rowSelection && props.rowSelection.selectedRowKeysExpr) {
398
+ rows.forEach((row: any, index: number) => {
399
+ const flag = filter(props.rowSelection.selectedRowKeysExpr, {
400
+ record: row,
401
+ rowIndex: index
402
+ });
403
+ if (flag === 'true') {
404
+ selectedRowKeys.push(row[props?.rowSelection?.keyField || 'key']);
405
+ }
406
+ });
407
+ } else if (props.rowSelection && props.rowSelection.selectedRowKeys) {
408
+ selectedRowKeys = [...props.rowSelection.selectedRowKeys];
409
+ }
410
+
411
+ if (updateRows && selectedRowKeys.length > 0) {
412
+ store.updateSelected(selectedRowKeys, props.rowSelection.keyField);
413
+ }
414
+
415
+ let expandedRowKeys: Array<string | number> = [];
416
+ if (props.expandable && props.expandable.expandedRowKeysExpr) {
417
+ rows.forEach((row: any, index: number) => {
418
+ const flag = filter(props.expandable.expandedRowKeysExpr, {
419
+ record: row,
420
+ rowIndex: index
421
+ });
422
+ if (flag === 'true') {
423
+ expandedRowKeys.push(row[props?.expandable?.keyField || 'key']);
424
+ }
425
+ });
426
+ } else if (props.expandable && props.expandable.expandedRowKeys) {
427
+ expandedRowKeys = [...props.expandable.expandedRowKeys];
428
+ }
429
+
430
+ if (updateRows && expandedRowKeys.length > 0) {
431
+ store.updateExpanded(expandedRowKeys, props.expandable.keyField);
432
+ }
433
+
434
+ return updateRows;
435
+ }
436
+
437
+ componentDidUpdate(prevProps: TableV2Props) {
438
+ const props = this.props;
439
+ const store = props.store;
440
+
441
+ if (anyChanged(['columnsTogglable'], prevProps, props)) {
442
+ store.update({
443
+ columnsTogglable: props.columnsTogglable
444
+ });
445
+ }
446
+
447
+ if (
448
+ anyChanged(['source', 'value', 'items'], prevProps, props) ||
449
+ (!props.value &&
450
+ !props.items &&
451
+ (props.data !== prevProps.data ||
452
+ (typeof props.source === 'string' && isPureVariable(props.source))))
453
+ ) {
454
+ TableRenderer.syncRows(store, props, prevProps) && this.syncSelected();
455
+ }
456
+
457
+ if (!isEqual(prevProps.columns, props.columns)) {
458
+ store.update({
459
+ columns: props.columns
460
+ });
461
+ }
462
+ }
463
+
464
+ getPopOverContainer() {
465
+ return findDOMNode(this);
466
+ }
467
+
468
+ renderCellSchema(schema: any, props: any) {
469
+ const {render} = this.props;
470
+
471
+ // Table Cell SchemaObject转化成ReactNode
472
+ if (schema && isObject(schema)) {
473
+ // 在TableCell里会根据width设置div的width
474
+ // 原来的table td/th是最外层标签 设置width没问题
475
+ // v2的拆开了 就不需要再设置div的width了
476
+ // 否则加上padding 就超出单元格的区域了
477
+ // children属性在schema里是一个关键字 在渲染器schema中 自定义的children没有用 去掉
478
+ const {width, children, ...rest} = schema;
479
+ return render(
480
+ 'cell-field',
481
+ {
482
+ ...rest,
483
+ type: 'cell-field',
484
+ column: rest,
485
+ data: props.data,
486
+ name: schema.key
487
+ },
488
+ props
489
+ );
490
+ }
491
+
492
+ return schema;
493
+ }
494
+
495
+ renderSchema(key: string, schema: any, props?: any) {
496
+ const {render} = this.props;
497
+
498
+ // Header、Footer等SchemaObject转化成ReactNode
499
+ if (schema && isObject(schema)) {
500
+ return render(key || 'field', {...schema, data: props.data}, props);
501
+ } else if (Array.isArray(schema)) {
502
+ const renderers: Array<any> = [];
503
+ schema.forEach((s, i) =>
504
+ renderers.push(
505
+ render(
506
+ key || 'field',
507
+ {
508
+ ...s,
509
+ data: props.data
510
+ },
511
+ {...props, key: i}
512
+ )
513
+ )
514
+ );
515
+ return renderers;
516
+ }
517
+
518
+ return schema;
519
+ }
520
+ // editor传来的处理过的column 还可能包含其他字段
521
+ buildColumns(columns: Array<any>) {
522
+ const {
523
+ env,
524
+ render,
525
+ store,
526
+ popOverContainer,
527
+ canAccessSuperData,
528
+ showBadge,
529
+ itemBadge,
530
+ classnames: cx
531
+ } = this.props;
532
+
533
+ const cols: Array<any> = [];
534
+ const rowSpans: Array<CellSpan> = [];
535
+ const colSpans: Array<CellSpan> = [];
536
+
537
+ Array.isArray(columns) &&
538
+ columns.forEach((column, col) => {
539
+ const clone = {...column} as any;
540
+
541
+ let titleSchema: any = null;
542
+ const titleProps = {
543
+ popOverContainer: popOverContainer || this.getPopOverContainer,
544
+ value: column.title
545
+ };
546
+ if (isObject(column.title)) {
547
+ titleSchema = cloneDeep(column.title);
548
+ } else if (typeof column.title === 'string') {
549
+ titleSchema = {type: 'plain'};
550
+ }
551
+
552
+ const titleRender = (children: any) => {
553
+ const content = this.renderCellSchema(titleSchema, titleProps);
554
+
555
+ let remark = null;
556
+ if (column.remark) {
557
+ remark = render('remark', {
558
+ type: 'remark',
559
+ tooltip: column.remark,
560
+ container:
561
+ env && env.getModalContainer ? env.getModalContainer : undefined
562
+ });
563
+ }
564
+
565
+ return (
566
+ <div className={cx('Table-head-cell-wrapper')}>
567
+ {content}
568
+ {remark}
569
+ {children}
570
+ </div>
571
+ );
572
+ };
573
+
574
+ Object.assign(clone, {
575
+ title: titleRender
576
+ });
577
+
578
+ // 设置了type值 就完全按渲染器处理了
579
+ if (column.type) {
580
+ Object.assign(clone, {
581
+ render: (
582
+ text: string,
583
+ record: any,
584
+ rowIndex: number,
585
+ colIndex: number
586
+ ) => {
587
+ const props: RenderProps = {};
588
+ const item = store.getRowByIndex(rowIndex);
589
+ const obj = {
590
+ children: this.renderCellSchema(column, {
591
+ data: item.locals,
592
+ value: column.key
593
+ ? resolveVariable(
594
+ column.key,
595
+ canAccessSuperData ? item.locals : item.data
596
+ )
597
+ : column.key,
598
+ popOverContainer:
599
+ popOverContainer || this.getPopOverContainer,
600
+ onQuickChange: (
601
+ values: object,
602
+ saveImmediately?: boolean,
603
+ savePristine?: boolean,
604
+ resetOnFailed?: boolean
605
+ ) => {
606
+ this.handleQuickChange(
607
+ item,
608
+ values,
609
+ saveImmediately,
610
+ savePristine,
611
+ resetOnFailed
612
+ );
613
+ },
614
+ row: item,
615
+ showBadge,
616
+ itemBadge
617
+ }),
618
+ props
619
+ };
620
+ if (column.rowSpanExpr) {
621
+ const rowSpan = +filter(column.rowSpanExpr, {
622
+ record,
623
+ rowIndex,
624
+ colIndex
625
+ });
626
+ if (rowSpan) {
627
+ obj.props.rowSpan = rowSpan;
628
+ rowSpans.push({colIndex, rowIndex, rowSpan});
629
+ }
630
+ }
631
+
632
+ if (column.colSpanExpr) {
633
+ const colSpan = +filter(column.colSpanExpr, {
634
+ record,
635
+ rowIndex,
636
+ colIndex
637
+ });
638
+ if (colSpan) {
639
+ obj.props.colSpan = colSpan;
640
+ colSpans.push({colIndex, rowIndex, colSpan});
641
+ }
642
+ }
643
+
644
+ rowSpans.forEach(item => {
645
+ if (
646
+ colIndex === item.colIndex &&
647
+ rowIndex > item.rowIndex &&
648
+ rowIndex < item.rowIndex + (item.rowSpan || 0)
649
+ ) {
650
+ obj.props.rowSpan = 0;
651
+ }
652
+ });
653
+
654
+ colSpans.forEach(item => {
655
+ if (
656
+ rowIndex === item.rowIndex &&
657
+ colIndex > item.colIndex &&
658
+ colIndex < item.colIndex + (item.colSpan || 0)
659
+ ) {
660
+ obj.props.colSpan = 0;
661
+ }
662
+ });
663
+
664
+ return obj;
665
+ }
666
+ });
667
+ }
668
+
669
+ // 设置了列搜索
670
+ if (column.searchable) {
671
+ clone.filterDropdown = (
672
+ <HeadCellSearchDropDown
673
+ {...this.props}
674
+ popOverContainer={this.getPopOverContainer}
675
+ name={column.key}
676
+ searchable={column.searchable}
677
+ orderBy={store.orderBy}
678
+ orderDir={store.order}
679
+ data={store.query}
680
+ key={'th-search-' + col}
681
+ store={store}
682
+ />
683
+ );
684
+ }
685
+
686
+ if (column.children) {
687
+ clone.children = this.buildColumns(column.children);
688
+ }
689
+
690
+ cols.push(clone);
691
+ });
692
+
693
+ return cols;
694
+ }
695
+
696
+ buildSummary(key: string, summary: Array<any>) {
697
+ const result: Array<any> = [];
698
+ if (Array.isArray(summary)) {
699
+ summary.forEach((s, index) => {
700
+ if (isObject(s)) {
701
+ result.push({
702
+ colSpan: s.colSpan,
703
+ fixed: s.fixed,
704
+ render: (dataSouce: Array<any>) =>
705
+ this.renderSchema(key, s, {
706
+ data: dataSouce
707
+ })
708
+ });
709
+ } else if (Array.isArray(s)) {
710
+ if (!result[index]) {
711
+ result.push([]);
712
+ }
713
+ s.forEach(d => {
714
+ result[index].push({
715
+ colSpan: d.colSpan,
716
+ fixed: d.fixed,
717
+ render: (dataSouce: Array<any>) =>
718
+ this.renderSchema(key, d, {
719
+ data: dataSouce
720
+ })
721
+ });
722
+ });
723
+ }
724
+ });
725
+ }
726
+
727
+ return result.length ? result : null;
728
+ }
729
+
730
+ reloadTarget(target: string, data: any) {
731
+ const scoped = this.context as IScopedContext;
732
+ scoped.reload(target, data);
733
+ }
734
+
735
+ handleSave(
736
+ rows: Array<object> | object,
737
+ diff: Array<object> | object,
738
+ indexes: Array<string>,
739
+ unModifiedItems?: Array<any>,
740
+ rowsOrigin?: Array<object> | object,
741
+ resetOnFailed?: boolean
742
+ ) {
743
+ const {
744
+ store,
745
+ quickSaveApi,
746
+ quickSaveItemApi,
747
+ primaryField,
748
+ env,
749
+ messages,
750
+ reload
751
+ } = this.props;
752
+
753
+ if (Array.isArray(rows)) {
754
+ if (!isEffectiveApi(quickSaveApi)) {
755
+ env && env.alert('TableV2 quickSaveApi is required');
756
+ return;
757
+ }
758
+
759
+ const data: any = createObject(store.data, {
760
+ rows,
761
+ rowsDiff: diff,
762
+ indexes: indexes,
763
+ rowsOrigin
764
+ });
765
+
766
+ if (rows.length && rows[0].hasOwnProperty(primaryField || 'id')) {
767
+ data.ids = rows
768
+ .map(item => (item as any)[primaryField || 'id'])
769
+ .join(',');
770
+ }
771
+
772
+ if (unModifiedItems) {
773
+ data.unModifiedItems = unModifiedItems;
774
+ }
775
+
776
+ store
777
+ .saveRemote(quickSaveApi, data, {
778
+ successMessage: messages && messages.saveFailed,
779
+ errorMessage: messages && messages.saveSuccess
780
+ })
781
+ .then(() => {
782
+ reload && this.reloadTarget(reload, data);
783
+ })
784
+ .catch(() => {});
785
+ } else {
786
+ if (!isEffectiveApi(quickSaveItemApi)) {
787
+ env && env.alert('TableV2 quickSaveItemApi is required!');
788
+ return;
789
+ }
790
+
791
+ const data = createObject(store.data, {
792
+ item: rows,
793
+ modified: diff,
794
+ origin: rowsOrigin
795
+ });
796
+
797
+ const sendData = createObject(data, rows);
798
+ store
799
+ .saveRemote(quickSaveItemApi, sendData)
800
+ .then(() => {
801
+ reload && this.reloadTarget(reload, data);
802
+ })
803
+ .catch(() => {
804
+ resetOnFailed && this.control.reset();
805
+ });
806
+ }
807
+ }
808
+
809
+ handleQuickChange(
810
+ item: IRow,
811
+ values: object,
812
+ saveImmediately?: boolean | any,
813
+ savePristine?: boolean,
814
+ resetOnFailed?: boolean
815
+ ) {
816
+ if (!isAlive(item)) {
817
+ return;
818
+ }
819
+
820
+ const {onSave, onPristineChange, primaryField, quickSaveItemApi} =
821
+ this.props;
822
+
823
+ item.change(values, savePristine);
824
+
825
+ // 值发生变化了,需要通过 onSelect 通知到外面,否则会出现数据不同步的问题
826
+ item.modified && this.syncSelected();
827
+
828
+ if (savePristine) {
829
+ onPristineChange?.(item.data, item.path);
830
+ return;
831
+ }
832
+
833
+ if (saveImmediately && saveImmediately.api) {
834
+ this.props.onAction(
835
+ null,
836
+ {
837
+ actionType: 'ajax',
838
+ api: saveImmediately.api
839
+ },
840
+ values
841
+ );
842
+ return;
843
+ }
844
+
845
+ onSave
846
+ ? onSave(
847
+ item.data,
848
+ difference(item.data, item.pristine, ['id', primaryField]),
849
+ item.path,
850
+ undefined,
851
+ item.pristine,
852
+ resetOnFailed
853
+ )
854
+ : this.handleSave(
855
+ quickSaveItemApi ? item.data : [item.data],
856
+ difference(item.data, item.pristine, ['id', primaryField]),
857
+ [item.path],
858
+ undefined,
859
+ item.pristine,
860
+ resetOnFailed
861
+ );
862
+ }
863
+
864
+ handleColumnToggle(columns: Array<IColumn>) {
865
+ const {store} = this.props;
866
+
867
+ store.update({columns});
868
+ }
869
+
870
+ renderColumnsToggler(config?: any) {
871
+ const {
872
+ className,
873
+ store,
874
+ render,
875
+ classPrefix: ns,
876
+ classnames: cx,
877
+ ...rest
878
+ } = this.props;
879
+ const __ = rest.translate;
880
+ const env = rest.env;
881
+
882
+ if (!store.toggable) {
883
+ return null;
884
+ }
885
+
886
+ return (
887
+ <ColumnToggler
888
+ {...rest}
889
+ {...(isObject(config) ? config : {})}
890
+ tooltip={config?.tooltip || __('Table.columnsVisibility')}
891
+ tooltipContainer={
892
+ env && env.getModalContainer ? env.getModalContainer : undefined
893
+ }
894
+ align={config?.align ?? 'left'}
895
+ isActived={store.hasColumnHidden()}
896
+ classnames={cx}
897
+ classPrefix={ns}
898
+ key="columns-toggable"
899
+ size={config?.size || 'sm'}
900
+ icon={config?.icon}
901
+ label={config?.label || ''}
902
+ draggable={config?.draggable}
903
+ columns={store.columnsData}
904
+ onColumnToggle={this.handleColumnToggle}
905
+ >
906
+ {store.toggableColumns.map((column, index) => (
907
+ <li
908
+ className={cx('ColumnToggler-menuItem')}
909
+ key={'toggable-li-' + index}
910
+ onClick={column.toggleToggle}
911
+ >
912
+ <Checkbox
913
+ key={'toggable-select' + index}
914
+ size="sm"
915
+ classPrefix={ns}
916
+ checked={column.toggled}
917
+ >
918
+ {column.title ? render('tpl', column.title) : null}
919
+ </Checkbox>
920
+ </li>
921
+ ))}
922
+ </ColumnToggler>
923
+ );
924
+ }
925
+
926
+ handleAction(e: React.UIEvent<any>, action: Action, ctx: object) {
927
+ const {onAction} = this.props;
928
+
929
+ // todo
930
+ onAction(e, action, ctx);
931
+ }
932
+
933
+ renderActions(region: string) {
934
+ let {
935
+ actions,
936
+ render,
937
+ store,
938
+ classnames: cx,
939
+ data,
940
+ columnsToggler
941
+ } = this.props;
942
+
943
+ actions = Array.isArray(actions) ? actions.concat() : [];
944
+
945
+ if (
946
+ store.toggable &&
947
+ region === 'header' &&
948
+ !~this.renderedToolbars.indexOf('columns-toggler')
949
+ ) {
950
+ actions.push({
951
+ type: 'button',
952
+ children: this.renderColumnsToggler(columnsToggler)
953
+ });
954
+ }
955
+
956
+ return Array.isArray(actions) && actions.length ? (
957
+ <div className={cx('Table-toolbar')}>
958
+ {actions.map((action, key) =>
959
+ render(
960
+ `action/${key}`,
961
+ {
962
+ type: 'button',
963
+ ...(action as any)
964
+ },
965
+ {
966
+ onAction: this.handleAction,
967
+ key,
968
+ btnDisabled: store.dragging,
969
+ data: store.getData(data)
970
+ }
971
+ )
972
+ )}
973
+ </div>
974
+ ) : null;
975
+ }
976
+
977
+ renderTable() {
978
+ const {
979
+ render,
980
+ title,
981
+ footer,
982
+ rowSelection,
983
+ columns,
984
+ expandable,
985
+ expandableBody,
986
+ footSummary,
987
+ headSummary,
988
+ loading,
989
+ classnames: cx,
990
+ placeholder,
991
+ rowClassNameExpr,
992
+ store,
993
+ ...rest
994
+ } = this.props;
995
+
996
+ let expandableConfig: any = null;
997
+ if (expandable) {
998
+ const {expandedRowKeys, ...rest} = expandable;
999
+
1000
+ expandableConfig = {
1001
+ expandedRowKeys: store.currentExpandedKeys,
1002
+ ...rest
1003
+ };
1004
+
1005
+ if (expandable.expandableOn) {
1006
+ expandableConfig.rowExpandable = (record: any, rowIndex: number) =>
1007
+ evalExpression(expandable.expandableOn, {record, rowIndex});
1008
+ delete expandableConfig.expandableOn;
1009
+ }
1010
+
1011
+ if (expandableBody && expandableBody.length > 0) {
1012
+ expandableConfig.expandedRowRender = (record: any, rowIndex: number) =>
1013
+ this.renderSchema('expandableBody', expandableBody, {data: record});
1014
+ }
1015
+
1016
+ if (expandable.expandedRowClassNameExpr) {
1017
+ expandableConfig.expandedRowClassName = (
1018
+ record: any,
1019
+ rowIndex: number
1020
+ ) => filter(expandable.expandedRowClassNameExpr, {record, rowIndex});
1021
+ delete expandableConfig.expandedRowClassNameExpr;
1022
+ }
1023
+ }
1024
+
1025
+ let rowSelectionConfig: any = null;
1026
+ if (rowSelection) {
1027
+ const {selectedRowKeys, selections, ...rest} = rowSelection;
1028
+ rowSelectionConfig = {
1029
+ selectedRowKeys: store.currentSelectedRowKeys,
1030
+ ...rest
1031
+ };
1032
+
1033
+ if (rowSelection.disableOn) {
1034
+ const disableOn = rowSelection.disableOn;
1035
+
1036
+ rowSelectionConfig.getCheckboxProps = (
1037
+ record: any,
1038
+ rowIndex: number
1039
+ ) => ({
1040
+ disabled: evalExpression(disableOn, {record, rowIndex})
1041
+ });
1042
+
1043
+ delete rowSelectionConfig.disableOn;
1044
+ }
1045
+
1046
+ if (selections && Array.isArray(selections)) {
1047
+ rowSelectionConfig.selections = [];
1048
+
1049
+ selections.forEach((item: RowSelectionOptionsSchema) => {
1050
+ rowSelectionConfig.selections.push({
1051
+ key: item.key,
1052
+ text: item.text,
1053
+ onSelect: (changableRowKeys: Array<string | number>) => {
1054
+ let newSelectedRowKeys = [];
1055
+ newSelectedRowKeys = changableRowKeys.filter((key, index) => {
1056
+ if (item.key === 'all') {
1057
+ return true;
1058
+ }
1059
+ if (item.key === 'none') {
1060
+ return false;
1061
+ }
1062
+ if (item.key === 'invert') {
1063
+ return !store.currentSelectedRowKeys.includes(key);
1064
+ }
1065
+ // 奇数行
1066
+ if (item.key === 'odd') {
1067
+ if (index % 2 !== 0) {
1068
+ return false;
1069
+ }
1070
+ return true;
1071
+ }
1072
+ // 偶数行
1073
+ if (item.key === 'even') {
1074
+ if (index % 2 !== 0) {
1075
+ return true;
1076
+ }
1077
+ return false;
1078
+ }
1079
+ return true;
1080
+ });
1081
+ store.updateSelected(newSelectedRowKeys, rowSelection.keyField);
1082
+ }
1083
+ });
1084
+ });
1085
+ }
1086
+
1087
+ // 因为要通过原子组件Table同步store里的selectedRows
1088
+ // 因此onSelect在这里处理一下
1089
+ rowSelectionConfig.onSelect = (
1090
+ record: any,
1091
+ value: boolean,
1092
+ selectedRows: Array<any>,
1093
+ selectedRowKeys: Array<string | number>
1094
+ ) => {
1095
+ store.updateSelected(selectedRowKeys, rowSelection.keyField);
1096
+
1097
+ rowSelection.onSelect &&
1098
+ rowSelection.onSelect(record, value, selectedRows, selectedRowKeys);
1099
+ };
1100
+ }
1101
+
1102
+ let rowClassName = undefined;
1103
+ // 设置了行样式
1104
+ if (rowClassNameExpr) {
1105
+ rowClassName = (record: any, rowIndex: number) => {
1106
+ return filter(rowClassNameExpr, {record, rowIndex});
1107
+ };
1108
+ }
1109
+
1110
+ return (
1111
+ <Table
1112
+ {...rest}
1113
+ title={this.renderSchema('title', title, {data: this.props.data})}
1114
+ footer={this.renderSchema('footer', footer, {data: this.props.data})}
1115
+ columns={this.buildColumns(store.filteredColumns)}
1116
+ dataSource={store.dataSource}
1117
+ rowSelection={rowSelectionConfig}
1118
+ rowClassName={rowClassName}
1119
+ expandable={expandableConfig}
1120
+ footSummary={this.buildSummary('footSummary', footSummary)}
1121
+ headSummary={this.buildSummary('headSummary', headSummary)}
1122
+ loading={this.renderSchema('loading', loading)}
1123
+ placeholder={this.renderSchema('placeholder', placeholder)}
1124
+ ></Table>
1125
+ );
1126
+ }
1127
+
1128
+ render() {
1129
+ const {classnames: cx} = this.props;
1130
+
1131
+ this.renderedToolbars = []; // 用来记录哪些 toolbar 已经渲染了
1132
+
1133
+ return (
1134
+ <div className={cx('Table-render-wrapper')}>
1135
+ {this.renderActions('header')}
1136
+ {this.renderTable()}
1137
+ </div>
1138
+ );
1139
+ }
1140
+ }