amis 1.3.5-beta.3 → 1.4.1

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 (280) hide show
  1. package/lib/components/Badge.d.ts +15 -2
  2. package/lib/components/Badge.js +47 -4
  3. package/lib/components/Badge.js.map +2 -2
  4. package/lib/components/Button.d.ts +24 -22
  5. package/lib/components/Button.js +13 -7
  6. package/lib/components/Button.js.map +2 -2
  7. package/lib/components/Checkbox.d.ts +1 -1
  8. package/lib/components/Checkbox.js +1 -1
  9. package/lib/components/Checkbox.js.map +2 -2
  10. package/lib/components/Drawer.js +1 -1
  11. package/lib/components/Drawer.js.map +2 -2
  12. package/lib/components/Modal.js +1 -1
  13. package/lib/components/Modal.js.map +2 -2
  14. package/lib/components/RichText.d.ts +6 -4
  15. package/lib/components/RichText.js +241 -27
  16. package/lib/components/RichText.js.map +2 -2
  17. package/lib/components/Select.d.ts +7 -0
  18. package/lib/components/Select.js.map +2 -2
  19. package/lib/components/Steps.d.ts +3 -3
  20. package/lib/components/Steps.js.map +1 -1
  21. package/lib/components/WithRemoteConfig.d.ts +8 -0
  22. package/lib/components/WithRemoteConfig.js +28 -2
  23. package/lib/components/WithRemoteConfig.js.map +2 -2
  24. package/lib/components/calendar/DaysView.js +2 -2
  25. package/lib/components/calendar/DaysView.js.map +2 -2
  26. package/lib/components/condition-builder/Field.js +0 -1
  27. package/lib/components/condition-builder/Field.js.map +2 -2
  28. package/lib/components/condition-builder/Value.js +2 -1
  29. package/lib/components/condition-builder/Value.js.map +2 -2
  30. package/lib/components/condition-builder/types.d.ts +5 -0
  31. package/lib/components/condition-builder/types.js.map +1 -1
  32. package/lib/components/icons.js +2 -0
  33. package/lib/components/icons.js.map +2 -2
  34. package/lib/factory.d.ts +5 -1
  35. package/lib/factory.js +9 -4
  36. package/lib/factory.js.map +2 -2
  37. package/lib/helper.css.map +1 -1
  38. package/lib/icons/loading-outline.js +7 -0
  39. package/lib/index.d.ts +1 -0
  40. package/lib/index.js +2 -1
  41. package/lib/index.js.map +2 -2
  42. package/lib/locale/de-DE.js +1 -0
  43. package/lib/locale/de-DE.js.map +2 -2
  44. package/lib/locale/en-US.js +2 -1
  45. package/lib/locale/en-US.js.map +2 -2
  46. package/lib/locale/zh-CN.js +2 -1
  47. package/lib/locale/zh-CN.js.map +2 -2
  48. package/lib/renderers/Action.d.ts +15 -1
  49. package/lib/renderers/Action.js +13 -6
  50. package/lib/renderers/Action.js.map +2 -2
  51. package/lib/renderers/CRUD.d.ts +2 -2
  52. package/lib/renderers/CRUD.js +11 -20
  53. package/lib/renderers/CRUD.js.map +2 -2
  54. package/lib/renderers/Card.js +11 -11
  55. package/lib/renderers/Card.js.map +2 -2
  56. package/lib/renderers/Collapse.d.ts +1 -1
  57. package/lib/renderers/Collapse.js +5 -1
  58. package/lib/renderers/Collapse.js.map +2 -2
  59. package/lib/renderers/Dialog.d.ts +0 -252
  60. package/lib/renderers/Dialog.js +3 -2
  61. package/lib/renderers/Dialog.js.map +2 -2
  62. package/lib/renderers/Drawer.js +2 -1
  63. package/lib/renderers/Drawer.js.map +2 -2
  64. package/lib/renderers/DropDownButton.d.ts +8 -0
  65. package/lib/renderers/DropDownButton.js +6 -4
  66. package/lib/renderers/DropDownButton.js.map +2 -2
  67. package/lib/renderers/Form/ButtonGroupSelect.js +3 -0
  68. package/lib/renderers/Form/ButtonGroupSelect.js.map +2 -2
  69. package/lib/renderers/Form/Combo.d.ts +2 -0
  70. package/lib/renderers/Form/Combo.js +16 -1
  71. package/lib/renderers/Form/Combo.js.map +2 -2
  72. package/lib/renderers/Form/DiffEditor.d.ts +0 -2
  73. package/lib/renderers/Form/Editor.d.ts +0 -2
  74. package/lib/renderers/Form/Editor.js +1 -1
  75. package/lib/renderers/Form/Editor.js.map +2 -2
  76. package/lib/renderers/Form/InputExcel.d.ts +5 -0
  77. package/lib/renderers/Form/InputExcel.js +24 -3
  78. package/lib/renderers/Form/InputExcel.js.map +2 -2
  79. package/lib/renderers/Form/InputImage.d.ts +8 -0
  80. package/lib/renderers/Form/InputImage.js +2 -1
  81. package/lib/renderers/Form/InputImage.js.map +2 -2
  82. package/lib/renderers/Form/InputNumber.d.ts +19 -5
  83. package/lib/renderers/Form/InputNumber.js +69 -7
  84. package/lib/renderers/Form/InputNumber.js.map +2 -2
  85. package/lib/renderers/Form/InputRange.js +7 -2
  86. package/lib/renderers/Form/InputRange.js.map +2 -2
  87. package/lib/renderers/Form/InputTable.d.ts +23 -5
  88. package/lib/renderers/Form/InputTable.js +32 -3
  89. package/lib/renderers/Form/InputTable.js.map +2 -2
  90. package/lib/renderers/Form/Options.js +3 -1
  91. package/lib/renderers/Form/Options.js.map +2 -2
  92. package/lib/renderers/Form/index.js +0 -10
  93. package/lib/renderers/Form/index.js.map +2 -2
  94. package/lib/renderers/Form/wrapControl.js +3 -3
  95. package/lib/renderers/Form/wrapControl.js.map +2 -2
  96. package/lib/renderers/Json.js +5 -1
  97. package/lib/renderers/Json.js.map +2 -2
  98. package/lib/renderers/List.d.ts +5 -0
  99. package/lib/renderers/List.js +20 -14
  100. package/lib/renderers/List.js.map +2 -2
  101. package/lib/renderers/Nav.d.ts +52 -22
  102. package/lib/renderers/Nav.js +100 -15
  103. package/lib/renderers/Nav.js.map +2 -2
  104. package/lib/renderers/Page.d.ts +6 -0
  105. package/lib/renderers/Page.js +11 -3
  106. package/lib/renderers/Page.js.map +2 -2
  107. package/lib/renderers/Service.d.ts +10 -1
  108. package/lib/renderers/Service.js +85 -3
  109. package/lib/renderers/Service.js.map +2 -2
  110. package/lib/renderers/Steps.d.ts +4 -4
  111. package/lib/renderers/Steps.js +5 -2
  112. package/lib/renderers/Steps.js.map +2 -2
  113. package/lib/renderers/Table/TableBody.d.ts +5 -3
  114. package/lib/renderers/Table/TableBody.js +17 -11
  115. package/lib/renderers/Table/TableBody.js.map +2 -2
  116. package/lib/renderers/Table/TableCell.js +6 -2
  117. package/lib/renderers/Table/TableCell.js.map +2 -2
  118. package/lib/renderers/Table/TableContent.d.ts +3 -1
  119. package/lib/renderers/Table/TableContent.js +6 -2
  120. package/lib/renderers/Table/TableContent.js.map +2 -2
  121. package/lib/renderers/Table/TableRow.d.ts +1 -1
  122. package/lib/renderers/Table/TableRow.js +14 -13
  123. package/lib/renderers/Table/TableRow.js.map +2 -2
  124. package/lib/renderers/Table/index.d.ts +28 -3
  125. package/lib/renderers/Table/index.js +92 -52
  126. package/lib/renderers/Table/index.js.map +2 -2
  127. package/lib/schemaExtend.d.ts +1 -0
  128. package/lib/schemaExtend.js +59 -0
  129. package/lib/schemaExtend.js.map +13 -0
  130. package/lib/store/app.d.ts +0 -1
  131. package/lib/store/combo.d.ts +0 -2
  132. package/lib/store/crud.d.ts +3 -3
  133. package/lib/store/crud.js +41 -36
  134. package/lib/store/crud.js.map +2 -2
  135. package/lib/store/form.d.ts +0 -1
  136. package/lib/store/formItem.js +10 -6
  137. package/lib/store/formItem.js.map +2 -2
  138. package/lib/store/modal.d.ts +1 -1
  139. package/lib/store/modal.js +4 -0
  140. package/lib/store/modal.js.map +2 -2
  141. package/lib/store/root.d.ts +0 -1
  142. package/lib/store/service.d.ts +0 -1
  143. package/lib/store/service.js +0 -13
  144. package/lib/store/service.js.map +2 -2
  145. package/lib/store/table.d.ts +1 -2
  146. package/lib/store/table.js +44 -3
  147. package/lib/store/table.js.map +2 -2
  148. package/lib/themes/ang-ie11.css +624 -71
  149. package/lib/themes/ang.css +624 -71
  150. package/lib/themes/ang.css.map +1 -1
  151. package/lib/themes/antd-ie11.css +624 -71
  152. package/lib/themes/antd.css +624 -71
  153. package/lib/themes/antd.css.map +1 -1
  154. package/lib/themes/cxd-ie11.css +732 -191
  155. package/lib/themes/cxd.css +732 -191
  156. package/lib/themes/cxd.css.map +1 -1
  157. package/lib/themes/dark-ie11.css +624 -71
  158. package/lib/themes/dark.css +624 -71
  159. package/lib/themes/dark.css.map +1 -1
  160. package/lib/themes/default.css +732 -191
  161. package/lib/themes/default.css.map +1 -1
  162. package/lib/utils/api.js +12 -0
  163. package/lib/utils/api.js.map +2 -2
  164. package/lib/utils/attachmentAdpator.d.ts +7 -0
  165. package/lib/utils/attachmentAdpator.js +82 -0
  166. package/lib/utils/attachmentAdpator.js.map +13 -0
  167. package/lib/utils/helper.d.ts +2 -0
  168. package/lib/utils/helper.js +14 -1
  169. package/lib/utils/helper.js.map +2 -2
  170. package/lib/utils/resize-sensor.js +6 -0
  171. package/lib/utils/resize-sensor.js.map +2 -2
  172. package/lib/utils/tpl-builtin.d.ts +1 -0
  173. package/lib/utils/tpl-builtin.js +24 -8
  174. package/lib/utils/tpl-builtin.js.map +2 -2
  175. package/lib/utils/validations.js +62 -5
  176. package/lib/utils/validations.js.map +2 -2
  177. package/package.json +1 -2
  178. package/schema.json +561 -171
  179. package/scss/_mixins.scss +29 -0
  180. package/scss/_properties.scss +29 -11
  181. package/scss/components/_badge.scss +67 -2
  182. package/scss/components/_button.scss +35 -3
  183. package/scss/components/_image-gallery.scss +1 -1
  184. package/scss/components/_list.scss +8 -0
  185. package/scss/components/_markdown.scss +266 -0
  186. package/scss/components/_nav.scss +109 -35
  187. package/scss/components/_spinner.scss +6 -2
  188. package/scss/components/_table.scss +4 -0
  189. package/scss/components/form/_form.scss +3 -17
  190. package/scss/components/form/_group.scss +4 -0
  191. package/scss/components/form/_number.scss +12 -1
  192. package/scss/themes/_common.scss +1 -0
  193. package/scss/themes/_cxd-variables.scss +20 -20
  194. package/sdk/ang-ie11.css +769 -76
  195. package/sdk/ang.css +785 -76
  196. package/sdk/antd-ie11.css +759 -68
  197. package/sdk/antd.css +785 -76
  198. package/sdk/charts.js +13 -13
  199. package/sdk/color-picker.js +67 -67
  200. package/sdk/cropperjs.js +2 -2
  201. package/sdk/cxd-ie11.css +1243 -552
  202. package/sdk/cxd.css +893 -196
  203. package/sdk/dark-ie11.css +769 -76
  204. package/sdk/dark.css +785 -76
  205. package/sdk/exceljs.js +1 -1
  206. package/sdk/helper.css.map +1 -1
  207. package/sdk/locale/de-DE.js +1 -0
  208. package/sdk/markdown.js +69 -69
  209. package/sdk/papaparse.js +1 -1
  210. package/sdk/renderers/Form/CityDB.js +1 -1
  211. package/sdk/rest.js +22 -24
  212. package/sdk/rich-text.js +62 -64
  213. package/sdk/sdk-ie11.css +1243 -552
  214. package/sdk/sdk.css +893 -196
  215. package/sdk/sdk.js +1123 -1111
  216. package/sdk/thirds/hls.js/hls.js +1 -1
  217. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  218. package/sdk/tinymce.js +57 -57
  219. package/sdk.zip +0 -0
  220. package/src/components/Badge.tsx +111 -20
  221. package/src/components/Button.tsx +23 -7
  222. package/src/components/Checkbox.tsx +5 -2
  223. package/src/components/Drawer.tsx +3 -2
  224. package/src/components/Modal.tsx +3 -2
  225. package/src/components/RichText.tsx +280 -24
  226. package/src/components/Select.tsx +1 -0
  227. package/src/components/Steps.tsx +3 -3
  228. package/src/components/WithRemoteConfig.tsx +37 -2
  229. package/src/components/calendar/DaysView.tsx +2 -2
  230. package/src/components/condition-builder/Field.tsx +1 -2
  231. package/src/components/condition-builder/Value.tsx +3 -0
  232. package/src/components/condition-builder/types.ts +6 -0
  233. package/src/components/icons.tsx +2 -0
  234. package/src/factory.tsx +13 -3
  235. package/src/icons/loading-outline.svg +4 -0
  236. package/src/index.tsx +2 -0
  237. package/src/locale/de-DE.ts +1 -0
  238. package/src/locale/en-US.ts +2 -1
  239. package/src/locale/zh-CN.ts +2 -1
  240. package/src/renderers/Action.tsx +84 -14
  241. package/src/renderers/CRUD.tsx +13 -33
  242. package/src/renderers/Card.tsx +21 -15
  243. package/src/renderers/Collapse.tsx +5 -1
  244. package/src/renderers/Dialog.tsx +3 -2
  245. package/src/renderers/Drawer.tsx +2 -1
  246. package/src/renderers/DropDownButton.tsx +21 -4
  247. package/src/renderers/Form/ButtonGroupSelect.tsx +3 -0
  248. package/src/renderers/Form/Combo.tsx +7 -0
  249. package/src/renderers/Form/Editor.tsx +19 -20
  250. package/src/renderers/Form/InputExcel.tsx +28 -3
  251. package/src/renderers/Form/InputImage.tsx +23 -8
  252. package/src/renderers/Form/InputNumber.tsx +113 -18
  253. package/src/renderers/Form/InputRange.tsx +5 -2
  254. package/src/renderers/Form/InputTable.tsx +88 -9
  255. package/src/renderers/Form/Options.tsx +3 -1
  256. package/src/renderers/Form/index.tsx +0 -15
  257. package/src/renderers/Form/wrapControl.tsx +2 -2
  258. package/src/renderers/Json.tsx +10 -1
  259. package/src/renderers/List.tsx +32 -19
  260. package/src/renderers/Nav.tsx +165 -36
  261. package/src/renderers/Page.tsx +20 -1
  262. package/src/renderers/Service.tsx +101 -3
  263. package/src/renderers/Steps.tsx +12 -9
  264. package/src/renderers/Table/TableBody.tsx +29 -10
  265. package/src/renderers/Table/TableCell.tsx +15 -1
  266. package/src/renderers/Table/TableContent.tsx +7 -1
  267. package/src/renderers/Table/TableRow.tsx +18 -17
  268. package/src/renderers/Table/index.tsx +112 -27
  269. package/src/schemaExtend.ts +66 -0
  270. package/src/store/crud.ts +34 -38
  271. package/src/store/formItem.ts +10 -6
  272. package/src/store/modal.ts +4 -0
  273. package/src/store/service.ts +0 -19
  274. package/src/store/table.ts +48 -0
  275. package/src/utils/api.ts +11 -0
  276. package/src/utils/attachmentAdpator.ts +90 -0
  277. package/src/utils/helper.ts +16 -0
  278. package/src/utils/resize-sensor.ts +7 -0
  279. package/src/utils/tpl-builtin.ts +36 -17
  280. package/src/utils/validations.ts +80 -12
@@ -35,6 +35,7 @@ import {HeadCellSearchDropDown} from './HeadCellSearchDropdown';
35
35
  import {TableContent} from './TableContent';
36
36
  import {
37
37
  BaseSchema,
38
+ SchemaApi,
38
39
  SchemaClassName,
39
40
  SchemaObject,
40
41
  SchemaTokenizeableString,
@@ -109,6 +110,26 @@ export type TableColumnObject = {
109
110
  */
110
111
  width?: number | string;
111
112
 
113
+ /**
114
+ * 列对齐方式
115
+ */
116
+ align?: 'left' | 'right' | 'center' | 'justify';
117
+
118
+ /**
119
+ * 列样式表
120
+ */
121
+ className?: string;
122
+
123
+ /**
124
+ * 单元格样式表达式
125
+ */
126
+ classNameExpr?: string;
127
+
128
+ /**
129
+ * 列头样式表
130
+ */
131
+ labelClassName?: string;
132
+
112
133
  /**
113
134
  * todo
114
135
  */
@@ -252,6 +273,11 @@ export interface TableSchema extends BaseSchema {
252
273
  * 是否可调整列宽
253
274
  */
254
275
  resizable?: boolean;
276
+
277
+ /**
278
+ * 行样式表表达式
279
+ */
280
+ rowClassNameExpr?: string;
255
281
  }
256
282
 
257
283
  export interface TableProps extends RendererProps {
@@ -321,6 +347,12 @@ export interface TableProps extends RendererProps {
321
347
  reUseRow?: boolean;
322
348
  }
323
349
 
350
+ type ExportExcelToolbar = SchemaNode & {
351
+ api?: SchemaApi;
352
+ columns?: string[];
353
+ filename?: string;
354
+ };
355
+
324
356
  /**
325
357
  * 将 url 转成绝对地址
326
358
  */
@@ -359,6 +391,7 @@ export default class Table extends React.Component<TableProps, object> {
359
391
  'itemDraggableOn',
360
392
  'checkOnItemClick',
361
393
  'hideCheckToggler',
394
+ 'itemAction',
362
395
  'itemActions',
363
396
  'combineNum',
364
397
  'combineFromIndex',
@@ -656,8 +689,14 @@ export default class Table extends React.Component<TableProps, object> {
656
689
  onAction(e, action, ctx);
657
690
  }
658
691
 
659
- handleCheck(item: IRow) {
660
- item.toggle();
692
+ handleCheck(item: IRow, value: boolean, shift?: boolean) {
693
+ const {store} = this.props;
694
+ if (shift) {
695
+ store.toggleShift(item);
696
+ } else {
697
+ item.toggle();
698
+ }
699
+
661
700
  this.syncSelected();
662
701
  }
663
702
 
@@ -1531,6 +1570,11 @@ export default class Table extends React.Component<TableProps, object> {
1531
1570
  props.style.width = column.pristine.width;
1532
1571
  }
1533
1572
 
1573
+ if (column.pristine.align) {
1574
+ props.style = props.style || {};
1575
+ props.style.textAlign = column.pristine.align;
1576
+ }
1577
+
1534
1578
  const resizeLine = (
1535
1579
  <div
1536
1580
  className={cx('Table-content-colDragLine')}
@@ -1542,18 +1586,20 @@ export default class Table extends React.Component<TableProps, object> {
1542
1586
  return (
1543
1587
  <th
1544
1588
  {...props}
1545
- className={cx(
1546
- props ? (props as any).className : '',
1547
- column.pristine.className,
1548
- {
1549
- 'TableCell--sortable': column.sortable,
1550
- 'TableCell--searchable': column.searchable,
1551
- 'TableCell--filterable': column.filterable,
1552
- 'Table-operationCell': column.type === 'operation'
1553
- }
1554
- )}
1589
+ className={cx(props ? (props as any).className : '', {
1590
+ 'TableCell--sortable': column.sortable,
1591
+ 'TableCell--searchable': column.searchable,
1592
+ 'TableCell--filterable': column.filterable,
1593
+ 'Table-operationCell': column.type === 'operation'
1594
+ })}
1555
1595
  >
1556
- <div className={cx(`${ns}TableCell--title`)}>
1596
+ <div
1597
+ className={cx(
1598
+ `${ns}TableCell--title`,
1599
+ column.pristine.className,
1600
+ column.pristine.labelClassName
1601
+ )}
1602
+ >
1557
1603
  {column.label ? render('tpl', column.label) : null}
1558
1604
 
1559
1605
  {column.remark
@@ -1782,7 +1828,8 @@ export default class Table extends React.Component<TableProps, object> {
1782
1828
  checkOnItemClick,
1783
1829
  buildItemProps,
1784
1830
  rowClassNameExpr,
1785
- rowClassName
1831
+ rowClassName,
1832
+ itemAction
1786
1833
  } = this.props;
1787
1834
  const hideHeader = store.filteredColumns.every(column => !column.label);
1788
1835
  const columnsGroup = store.columnGroup;
@@ -1843,6 +1890,7 @@ export default class Table extends React.Component<TableProps, object> {
1843
1890
  store.combineNum > 0 ? 'Table-table--withCombine' : '',
1844
1891
  tableClassName
1845
1892
  )}
1893
+ itemAction={itemAction}
1846
1894
  classnames={cx}
1847
1895
  render={render}
1848
1896
  renderCell={this.renderCell}
@@ -1969,7 +2017,7 @@ export default class Table extends React.Component<TableProps, object> {
1969
2017
  );
1970
2018
  }
1971
2019
 
1972
- renderExportExcel(toolbar: SchemaNode) {
2020
+ renderExportExcel(toolbar: ExportExcelToolbar) {
1973
2021
  const {
1974
2022
  store,
1975
2023
  env,
@@ -1993,8 +2041,8 @@ export default class Table extends React.Component<TableProps, object> {
1993
2041
  let tmpStore;
1994
2042
  let filename = 'data';
1995
2043
  // 支持配置 api 远程获取
1996
- if (typeof toolbar === 'object' && (toolbar as Schema).api) {
1997
- const res = await env.fetcher((toolbar as Schema).api, data);
2044
+ if (typeof toolbar === 'object' && toolbar.api) {
2045
+ const res = await env.fetcher(toolbar.api, data);
1998
2046
  if (!res.data) {
1999
2047
  env.notify('warning', __('placeholder.noData'));
2000
2048
  return;
@@ -2012,8 +2060,8 @@ export default class Table extends React.Component<TableProps, object> {
2012
2060
  rows = store.rows;
2013
2061
  }
2014
2062
 
2015
- if (typeof toolbar === 'object' && (toolbar as Schema).filename) {
2016
- filename = filter((toolbar as Schema).filename, data, '| raw');
2063
+ if (typeof toolbar === 'object' && toolbar.filename) {
2064
+ filename = filter(toolbar.filename, data, '| raw');
2017
2065
  }
2018
2066
 
2019
2067
  if (rows.length === 0) {
@@ -2027,7 +2075,17 @@ export default class Table extends React.Component<TableProps, object> {
2027
2075
  });
2028
2076
  worksheet.views = [{state: 'frozen', xSplit: 0, ySplit: 1}];
2029
2077
 
2030
- const firstRowLabels = columns.map(column => {
2078
+ const filteredColumns = toolbar.columns
2079
+ ? columns.filter(column => {
2080
+ const filterColumnsNames = toolbar.columns!;
2081
+ if (filterColumnsNames.indexOf(column.name) !== -1) {
2082
+ return true;
2083
+ }
2084
+ return false;
2085
+ })
2086
+ : columns;
2087
+
2088
+ const firstRowLabels = filteredColumns.map(column => {
2031
2089
  return column.label;
2032
2090
  });
2033
2091
  const firstRow = worksheet.getRow(1);
@@ -2042,14 +2100,15 @@ export default class Table extends React.Component<TableProps, object> {
2042
2100
  column: firstRowLabels.length
2043
2101
  }
2044
2102
  };
2103
+ // 用于 mapping source 的情况
2104
+ const remoteMappingCache: any = {};
2045
2105
  // 数据从第二行开始
2046
2106
  let rowIndex = 1;
2047
2107
  for (const row of rows) {
2048
2108
  rowIndex += 1;
2049
2109
  const sheetRow = worksheet.getRow(rowIndex);
2050
2110
  let columIndex = 0;
2051
- const cols = columns as any[]; // 为啥 ts 4.4 得这么做?
2052
- for (const column of cols) {
2111
+ for (const column of filteredColumns) {
2053
2112
  columIndex += 1;
2054
2113
  const name = column.name!;
2055
2114
  const value = getVariable(row.data, name);
@@ -2075,7 +2134,7 @@ export default class Table extends React.Component<TableProps, object> {
2075
2134
  }
2076
2135
 
2077
2136
  const type = (column as BaseSchema).type || 'plain';
2078
- if (type === 'image') {
2137
+ if (type === 'image' && value) {
2079
2138
  try {
2080
2139
  const imageData = await toDataURL(value);
2081
2140
  const imageDimensions = await getImageDimensions(imageData);
@@ -2135,7 +2194,30 @@ export default class Table extends React.Component<TableProps, object> {
2135
2194
  };
2136
2195
  } else if (type === 'mapping') {
2137
2196
  // 拷贝自 Mapping.tsx
2138
- const map = (column as MappingSchema).map;
2197
+ let map = (column as MappingSchema).map;
2198
+ const source = (column as MappingSchema).source;
2199
+ if (source) {
2200
+ let sourceValue = source;
2201
+ if (isPureVariable(source)) {
2202
+ sourceValue = resolveVariableAndFilter(
2203
+ source as string,
2204
+ data,
2205
+ '| raw'
2206
+ );
2207
+ }
2208
+
2209
+ const mapKey = JSON.stringify(source);
2210
+ if (mapKey in remoteMappingCache) {
2211
+ map = remoteMappingCache[mapKey];
2212
+ } else {
2213
+ const res = await env.fetcher(sourceValue, data);
2214
+ if (res.data) {
2215
+ remoteMappingCache[mapKey] = res.data;
2216
+ map = res.data;
2217
+ }
2218
+ }
2219
+ }
2220
+
2139
2221
  if (
2140
2222
  typeof value !== 'undefined' &&
2141
2223
  map &&
@@ -2148,9 +2230,10 @@ export default class Table extends React.Component<TableProps, object> {
2148
2230
  : value === false && map['0']
2149
2231
  ? map['0']
2150
2232
  : map['*']); // 兼容平台旧用法:即 value 为 true 时映射 1 ,为 false 时映射 0
2151
- sheetRow.getCell(columIndex).value = viewValue;
2233
+ sheetRow.getCell(columIndex).value =
2234
+ removeHTMLTag(viewValue);
2152
2235
  } else {
2153
- sheetRow.getCell(columIndex).value = value;
2236
+ sheetRow.getCell(columIndex).value = removeHTMLTag(value);
2154
2237
  }
2155
2238
  } else {
2156
2239
  if ((column as TplSchema).tpl) {
@@ -2423,7 +2506,8 @@ export default class Table extends React.Component<TableProps, object> {
2423
2506
  prefixRow,
2424
2507
  locale,
2425
2508
  affixRow,
2426
- translate
2509
+ translate,
2510
+ itemAction
2427
2511
  } = this.props;
2428
2512
 
2429
2513
  // 理论上来说 store.rows 应该也行啊
@@ -2436,6 +2520,7 @@ export default class Table extends React.Component<TableProps, object> {
2436
2520
  store.combineNum > 0 ? 'Table-table--withCombine' : '',
2437
2521
  tableClassName
2438
2522
  )}
2523
+ itemAction={itemAction}
2439
2524
  classnames={cx}
2440
2525
  columns={store.filteredColumns}
2441
2526
  columnsGroup={store.columnGroup}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * 扩展 Schema,目前用于实现 input-kv
3
+ */
4
+ import {Schema} from './types';
5
+ import {addSchemaFilter} from './factory';
6
+ import {isObject} from './utils/helper';
7
+
8
+ // input-kv 实际上是 combo 的一种扩展
9
+ addSchemaFilter(function (schema: Schema, renderer, props?: any) {
10
+ if (schema && schema.type === 'input-kv') {
11
+ return {
12
+ ...schema,
13
+ multiple: true,
14
+ pipeIn: (value: any) => {
15
+ if (!isObject(value)) {
16
+ return [];
17
+ }
18
+ const arr: Array<any> = [];
19
+ Object.keys(value).forEach(key => {
20
+ const valueType = typeof value[key];
21
+ arr.push({
22
+ key: key || '',
23
+ value:
24
+ valueType === 'string' ||
25
+ valueType === 'number' ||
26
+ valueType === 'boolean'
27
+ ? value[key]
28
+ : JSON.stringify(value[key])
29
+ });
30
+ });
31
+ return arr;
32
+ },
33
+ pipeOut: (value: any) => {
34
+ if (!Array.isArray(value)) {
35
+ return value;
36
+ }
37
+ const obj: any = {};
38
+ value.forEach((item: any) => {
39
+ const key: string = item.key || '';
40
+ let value: any = item.value;
41
+ try {
42
+ value = JSON.parse(value);
43
+ } catch (e) {}
44
+ obj[key] = value;
45
+ });
46
+ return obj;
47
+ },
48
+ items: [
49
+ {
50
+ placeholder: schema.keyPlaceholder ?? 'Key',
51
+ type: 'input-text',
52
+ unique: true,
53
+ name: 'key',
54
+ required: true
55
+ },
56
+ {
57
+ placeholder: schema.valuePlaceholder ?? 'Value',
58
+ type: schema.valueType || 'input-text',
59
+ name: 'value'
60
+ }
61
+ ]
62
+ };
63
+ }
64
+
65
+ return schema;
66
+ });
package/src/store/crud.ts CHANGED
@@ -482,6 +482,39 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
482
482
  self.reInitData(data);
483
483
  };
484
484
 
485
+ const exportAsCSV = async (
486
+ options: {loadDataOnce?: boolean; api?: Api; data?: any} = {}
487
+ ) => {
488
+ let items = options.loadDataOnce ? self.data.itemsRaw : self.data.items;
489
+
490
+ if (options.api) {
491
+ const env = getEnv(self);
492
+ const res = await env.fetcher(options.api, options.data);
493
+ if (!res.data) {
494
+ return;
495
+ }
496
+ if (Array.isArray(res.data)) {
497
+ items = res.data;
498
+ } else {
499
+ items = res.data.rows || res.data.items;
500
+ }
501
+ }
502
+
503
+ import('papaparse').then((papaparse: any) => {
504
+ const csvText = papaparse.unparse(items);
505
+ if (csvText) {
506
+ const blob = new Blob(
507
+ // 加上 BOM 这样 Excel 打开的时候就不会乱码
508
+ [new Uint8Array([0xef, 0xbb, 0xbf]), csvText],
509
+ {
510
+ type: 'text/plain;charset=utf-8'
511
+ }
512
+ );
513
+ saveAs(blob, 'data.csv');
514
+ }
515
+ });
516
+ };
517
+
485
518
  return {
486
519
  setPristineQuery,
487
520
  updateQuery,
@@ -495,44 +528,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
495
528
  setUnSelectedItems,
496
529
  setInnerModalOpened,
497
530
  initFromScope,
498
- async exportAsCSV(options: {loadDataOnce?: boolean; api?: Api} = {}) {
499
- let items = options.loadDataOnce ? self.data.itemsRaw : self.data.items;
500
-
501
- if (!options.loadDataOnce && options.api) {
502
- const json = await self.fetchData(
503
- options.api,
504
- {
505
- ...self.query,
506
- page: undefined,
507
- perPage: undefined,
508
- op: 'export-csv'
509
- },
510
- {
511
- autoAppend: true
512
- }
513
- );
514
- if (
515
- json.ok &&
516
- (Array.isArray(json.data.items) || Array.isArray(json.data.rows))
517
- ) {
518
- items = json.data.items || json.data.rows;
519
- }
520
- }
521
-
522
- import('papaparse').then((papaparse: any) => {
523
- const csvText = papaparse.unparse(items);
524
- if (csvText) {
525
- const blob = new Blob(
526
- // 加上 BOM 这样 Excel 打开的时候就不会乱码
527
- [new Uint8Array([0xef, 0xbb, 0xbf]), csvText],
528
- {
529
- type: 'text/plain;charset=utf-8'
530
- }
531
- );
532
- saveAs(blob, 'data.csv');
533
- }
534
- });
535
- }
531
+ exportAsCSV
536
532
  };
537
533
  });
538
534
 
@@ -285,13 +285,17 @@ export const FormItemStore = StoreNode.named('FormItemStore')
285
285
  isRequired: self.required
286
286
  };
287
287
 
288
- // if (typeof minLength === 'number') {
289
- // rules.minLength = minLength;
290
- // }
288
+ // todo 这个弄个配置由渲染器自己来决定
289
+ // 暂时先这样
290
+ if (~['input-text', 'textarea'].indexOf(self.type)) {
291
+ if (typeof minLength === 'number') {
292
+ rules.minLength = minLength;
293
+ }
291
294
 
292
- // if (typeof maxLength === 'number') {
293
- // rules.maxLength = maxLength;
294
- // }
295
+ if (typeof maxLength === 'number') {
296
+ rules.maxLength = maxLength;
297
+ }
298
+ }
295
299
 
296
300
  if (isObjectShallowModified(rules, self.rules)) {
297
301
  self.rules = rules;
@@ -24,6 +24,10 @@ export const ModalStore = ServiceStore.named('ModalStore')
24
24
  setFormData(obj: any) {
25
25
  self.form = obj;
26
26
  },
27
+ reset() {
28
+ self.form = {};
29
+ self.reInitData({}, true);
30
+ },
27
31
 
28
32
  setResizeCoord(value: number) {
29
33
  self.resizeCoord = value;
@@ -140,24 +140,6 @@ export const ServiceStore = iRendererStore
140
140
  }
141
141
  });
142
142
 
143
- const fetchWSData = (ws: string, afterDataFetch: (data: any) => any) => {
144
- const env = getEnv(self);
145
-
146
- env.wsFetcher(
147
- ws,
148
- (data: any) => {
149
- self.updateData(data, undefined, false);
150
- setHasRemoteData();
151
- // 因为 WebSocket 只会获取纯数据,所以没有 msg 之类的
152
- afterDataFetch({ok: true, data: data});
153
- },
154
- (error: any) => {
155
- updateMessage(error, true);
156
- env.notify('error', error);
157
- }
158
- );
159
- };
160
-
161
143
  const setHasRemoteData = () => {
162
144
  self.hasRemoteData = true;
163
145
  };
@@ -505,7 +487,6 @@ export const ServiceStore = iRendererStore
505
487
  markBusying,
506
488
  fetchInitData,
507
489
  fetchData,
508
- fetchWSData,
509
490
  reInitData,
510
491
  updateMessage,
511
492
  clearMessage,
@@ -984,11 +984,16 @@ export const TableStore = iRendererStore
984
984
  }
985
985
  }
986
986
 
987
+ // 记录最近一次点击的多选框,主要用于 shift 多选时判断上一个选的是什么
988
+ let lastCheckedRow: any = null;
989
+
987
990
  function toggle(row: IRow) {
988
991
  if (!row.checkable) {
989
992
  return;
990
993
  }
991
994
 
995
+ lastCheckedRow = row;
996
+
992
997
  const idx = self.selectedRows.indexOf(row);
993
998
 
994
999
  if (self.multiple) {
@@ -1000,6 +1005,48 @@ export const TableStore = iRendererStore
1000
1005
  }
1001
1006
  }
1002
1007
 
1008
+ // 按住 shift 的时候点击选项
1009
+ function toggleShift(row: IRow) {
1010
+ // 如果是同一个或非 multiple 模式下就和不用 shift 一样
1011
+ if (!lastCheckedRow || row === lastCheckedRow || !self.multiple) {
1012
+ toggle(row);
1013
+ return;
1014
+ }
1015
+
1016
+ const maxLength = self.maxKeepItemSelectionLength;
1017
+ const checkableRows = self.checkableRows;
1018
+ const lastCheckedRowIndex = checkableRows.findIndex(
1019
+ row => row === lastCheckedRow
1020
+ );
1021
+ const rowIndex = checkableRows.findIndex(rowItem => row === rowItem);
1022
+ const minIndex =
1023
+ lastCheckedRowIndex > rowIndex ? rowIndex : lastCheckedRowIndex;
1024
+ const maxIndex =
1025
+ lastCheckedRowIndex > rowIndex ? lastCheckedRowIndex : rowIndex;
1026
+
1027
+ const rows = checkableRows.slice(minIndex, maxIndex);
1028
+ rows.push(row); // 将当前行也加入进行判断
1029
+ for (const rowItem of rows) {
1030
+ const idx = self.selectedRows.indexOf(rowItem);
1031
+ if (idx === -1) {
1032
+ // 如果上一个是选中状态,则将之间的所有 check 都变成可选
1033
+ if (lastCheckedRow.checked) {
1034
+ if (maxLength && self.selectedRows.length < maxLength) {
1035
+ self.selectedRows.push(rowItem);
1036
+ } else {
1037
+ self.selectedRows.push(rowItem);
1038
+ }
1039
+ }
1040
+ } else {
1041
+ if (!lastCheckedRow.checked) {
1042
+ self.selectedRows.splice(idx, 1);
1043
+ }
1044
+ }
1045
+ }
1046
+
1047
+ lastCheckedRow = row;
1048
+ }
1049
+
1003
1050
  function updateCheckDisable() {
1004
1051
  if (!self.data) {
1005
1052
  return;
@@ -1134,6 +1181,7 @@ export const TableStore = iRendererStore
1134
1181
  updateSelected,
1135
1182
  toggleAll,
1136
1183
  toggle,
1184
+ toggleShift,
1137
1185
  toggleExpandAll,
1138
1186
  toggleExpanded,
1139
1187
  collapseAllAtDepth,
package/src/utils/api.ts CHANGED
@@ -22,6 +22,8 @@ interface ApiCacheConfig extends ApiObject {
22
22
 
23
23
  const apiCaches: Array<ApiCacheConfig> = [];
24
24
 
25
+ const isIE = !!(document as any).documentMode;
26
+
25
27
  export function normalizeApi(
26
28
  api: Api,
27
29
  defaultMethod: string = 'get'
@@ -293,6 +295,15 @@ export function wrapFetcher(
293
295
  api
294
296
  );
295
297
  }
298
+ // IE 下 get 请求会被缓存,所以自动加个时间戳
299
+ if (isIE && api && api.method?.toLocaleLowerCase() === 'get') {
300
+ const timeStamp = `_t=${Date.now()}`;
301
+ if (api.url.indexOf('?') === -1) {
302
+ api.url = api.url + `?${timeStamp}`;
303
+ } else {
304
+ api.url = api.url + `&${timeStamp}`;
305
+ }
306
+ }
296
307
  return wrapAdaptor(fn(api), api);
297
308
  };
298
309
  }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * 处理接口返回附件的情况,好几个地方用
3
+ * @param response
4
+ * @param __
5
+ * @returns
6
+ */
7
+
8
+ export default function attachmentAdpator(response: any, __: Function) {
9
+ if (response && response.headers && response.headers['content-disposition']) {
10
+ const disposition = response.headers['content-disposition'];
11
+ let filename = '';
12
+
13
+ if (disposition && disposition.indexOf('attachment') !== -1) {
14
+ // disposition 有可能是 attachment; filename="??.xlsx"; filename*=UTF-8''%E4%B8%AD%E6%96%87.xlsx
15
+ // 这种情况下最后一个才是正确的文件名
16
+ let filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)$/;
17
+
18
+ let matches = disposition.match(filenameRegex);
19
+ if (matches && matches.length) {
20
+ filename = matches[1].replace(`UTF-8''`, '').replace(/['"]/g, '');
21
+ }
22
+
23
+ // 很可能是中文被 url-encode 了
24
+ if (filename && filename.replace(/[^%]/g, '').length > 2) {
25
+ filename = decodeURIComponent(filename);
26
+ }
27
+
28
+ let type = response.headers['content-type'];
29
+ let blob =
30
+ response.data.toString() === '[object Blob]'
31
+ ? response.data
32
+ : new Blob([response.data], {type: type});
33
+ if (typeof (window.navigator as any).msSaveBlob !== 'undefined') {
34
+ // IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
35
+ (window.navigator as any).msSaveBlob(blob, filename);
36
+ } else {
37
+ let URL = window.URL || (window as any).webkitURL;
38
+ let downloadUrl = URL.createObjectURL(blob);
39
+ if (filename) {
40
+ // use HTML5 a[download] attribute to specify filename
41
+ let a = document.createElement('a');
42
+ // safari doesn't support this yet
43
+ if (typeof a.download === 'undefined') {
44
+ (window as any).location = downloadUrl;
45
+ } else {
46
+ a.href = downloadUrl;
47
+ a.download = filename;
48
+ document.body.appendChild(a);
49
+ a.click();
50
+ }
51
+ } else {
52
+ (window as any).location = downloadUrl;
53
+ }
54
+ setTimeout(function () {
55
+ URL.revokeObjectURL(downloadUrl);
56
+ }, 100); // cleanup
57
+ }
58
+
59
+ return {
60
+ ...response,
61
+ data: {
62
+ status: 0,
63
+ msg: __('Embed.downloading')
64
+ }
65
+ };
66
+ }
67
+ } else if (response.data.toString() === '[object Blob]') {
68
+ return new Promise((resolve, reject) => {
69
+ let reader = new FileReader();
70
+ reader.addEventListener('loadend', e => {
71
+ const text = reader.result as string;
72
+
73
+ try {
74
+ resolve({
75
+ ...response,
76
+ data: {
77
+ ...JSON.parse(text)
78
+ }
79
+ });
80
+ } catch (e) {
81
+ reject(e);
82
+ }
83
+ });
84
+
85
+ reader.readAsText(response.data);
86
+ });
87
+ }
88
+
89
+ return response;
90
+ }