@vtx/components 4.0.0-beta.8 → 4.0.0-beta.81

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 (196) hide show
  1. package/README.md +19 -19
  2. package/es/index.js +3 -0
  3. package/es/utils/components/LabelIconTip/index.js +7 -7
  4. package/es/utils/conversionMomentValue/index.js +25 -25
  5. package/es/utils/filterSpecialCharacters.js +53 -52
  6. package/es/utils/genCopyable/index.js +6 -6
  7. package/es/utils/getFieldPropsOrFormItemProps/index.js +7 -7
  8. package/es/utils/hooks/useDebounceFn/index.js +4 -4
  9. package/es/utils/hooks/useDebounceValue/index.js +6 -6
  10. package/es/utils/hooks/useDeepCompareMemo/index.js +7 -7
  11. package/es/utils/hooks/useLatest/index.js +2 -2
  12. package/es/utils/hooks/useRefCallback/index.js +5 -5
  13. package/es/utils/index.js +1 -2
  14. package/es/utils/isBrowser/index.js +7 -7
  15. package/es/utils/isUrl/index.js +4 -4
  16. package/es/utils/merge/index.js +4 -4
  17. package/es/utils/nanoid/index.js +4 -4
  18. package/es/utils/omitBoolean/index.js +4 -4
  19. package/es/utils/parseValueToMoment/index.js +4 -4
  20. package/es/utils/proFieldParsingText/index.js +10 -10
  21. package/es/utils/transformKeySubmitValue/index.js +57 -57
  22. package/es/utils/useEditableArray/index.js +46 -46
  23. package/es/utils/useEditableMap/index.js +22 -22
  24. package/es/utils/useMediaQuery/index.js +5 -5
  25. package/es/vtx-combogrid/Combogrid.js +5 -4
  26. package/es/vtx-combogrid/index.js +7 -4
  27. package/es/vtx-datagrid/Store/Provide.js +106 -137
  28. package/es/vtx-datagrid/ToolBar/components/ColumnSetting/index.js +11 -7
  29. package/es/vtx-datagrid/ToolBar/components/ColumnSetting/style.js +5 -2
  30. package/es/vtx-datagrid/ToolBar/components/Density/index.js +3 -0
  31. package/es/vtx-datagrid/ToolBar/components/TableStyle/index.js +3 -0
  32. package/es/vtx-datagrid/columnState.js +91 -0
  33. package/es/vtx-datagrid/index.js +124 -32
  34. package/es/vtx-datagrid/mergeComponents.js +15 -0
  35. package/es/vtx-datagrid/renderColumnButtons.js +30 -11
  36. package/es/vtx-datagrid/style/index.js +102 -20
  37. package/es/vtx-datagrid/style/index.less +242 -242
  38. package/es/vtx-date-picker/QdatePicker.js +1 -1
  39. package/es/vtx-date-picker/style/index.less +39 -39
  40. package/es/vtx-descriptions/Descriptions.js +29 -0
  41. package/es/vtx-descriptions/index.js +3 -0
  42. package/es/vtx-descriptions/style/index.js +19 -0
  43. package/es/vtx-ellipsis-text/index.js +7 -2
  44. package/es/vtx-ellipsis-text/style/index.js +3 -1
  45. package/es/vtx-export/index.js +33 -33
  46. package/es/vtx-export-async/History.js +15 -7
  47. package/es/vtx-export-async/index.js +45 -15
  48. package/es/vtx-export-async/util.js +16 -5
  49. package/es/vtx-form-layout/Card.js +10 -10
  50. package/es/vtx-form-layout/Divider.js +1 -1
  51. package/es/vtx-form-layout/FormItem.js +16 -16
  52. package/es/vtx-form-layout/Pane.js +23 -12
  53. package/es/vtx-icon/index.js +54 -45
  54. package/es/vtx-icon/index.js1 +90 -0
  55. package/es/vtx-image/Preview.js +11 -6
  56. package/es/vtx-image/style/index.js +0 -1
  57. package/es/vtx-import/index.js +211 -70
  58. package/es/vtx-import/result.js +28 -26
  59. package/es/vtx-import/style/index.js +16 -1
  60. package/es/vtx-import2/Content.js +2 -1
  61. package/es/vtx-import2/index.js +30 -19
  62. package/es/vtx-import2/style/index.js +60 -9
  63. package/es/vtx-modal/index.js +11 -6
  64. package/es/vtx-page-layout/Basic.js +2 -2
  65. package/es/vtx-page-layout/TabLayout.js +6 -6
  66. package/es/vtx-page-layout/TableLayout.js +10 -10
  67. package/es/vtx-page-layout/TreeLayout.js +6 -6
  68. package/es/vtx-page-layout/container.js +2 -2
  69. package/es/vtx-page-layout/style/index.js +4 -2
  70. package/es/vtx-provider/index.js +37 -33
  71. package/es/vtx-provider/intl.js +9 -9
  72. package/es/vtx-provider/locale/en_US.js +57 -3
  73. package/es/vtx-provider/locale/zh_CN.js +57 -3
  74. package/es/vtx-provider/useStyle/index.js +17 -17
  75. package/es/vtx-search/index.js +13 -9
  76. package/es/vtx-search/style/index.js +2 -1
  77. package/es/vtx-select/index.js +102 -36
  78. package/es/vtx-select/style/index.js +11 -56
  79. package/es/vtx-signature/index.js +5 -4
  80. package/es/vtx-signature/style/index.js +1 -1
  81. package/es/vtx-split-pane/Resizer.js +0 -1
  82. package/es/vtx-split-pane/SplitPane.js +42 -34
  83. package/es/vtx-split-pane/style/index.js +8 -112
  84. package/es/vtx-time-picker/index.js +27 -1
  85. package/es/vtx-transfer/Transfer.js +29 -0
  86. package/es/vtx-transfer/index.js +3 -0
  87. package/es/vtx-transfer/style/index.js +19 -0
  88. package/es/vtx-transfer-select/TransferSelect.js +143 -0
  89. package/es/vtx-transfer-select/index.js +3 -0
  90. package/es/vtx-transfer-select/style/index.js +19 -0
  91. package/es/vtx-tree/index.js +98 -35
  92. package/es/vtx-tree-select/index.js +71 -105
  93. package/es/vtx-tree-select/style/index.js +9 -3
  94. package/es/vtx-upload/FilePreview.js +2 -1
  95. package/es/vtx-wang-editor/index.js +93 -39
  96. package/es/vtx-wang-editor/style/index.less +12 -12
  97. package/es/vtx-wang-editor/wangEditorUtil.js +4 -0
  98. package/lib/index.js +36 -0
  99. package/lib/utils/components/LabelIconTip/index.js +7 -7
  100. package/lib/utils/conversionMomentValue/index.js +25 -25
  101. package/lib/utils/filterSpecialCharacters.js +54 -52
  102. package/lib/utils/genCopyable/index.js +6 -6
  103. package/lib/utils/getFieldPropsOrFormItemProps/index.js +7 -7
  104. package/lib/utils/hooks/useDebounceFn/index.js +4 -4
  105. package/lib/utils/hooks/useDebounceValue/index.js +6 -6
  106. package/lib/utils/hooks/useDeepCompareMemo/index.js +7 -7
  107. package/lib/utils/hooks/useLatest/index.js +2 -2
  108. package/lib/utils/hooks/useRefCallback/index.js +5 -5
  109. package/lib/utils/index.js +0 -7
  110. package/lib/utils/isBrowser/index.js +7 -7
  111. package/lib/utils/isUrl/index.js +4 -4
  112. package/lib/utils/merge/index.js +4 -4
  113. package/lib/utils/nanoid/index.js +4 -4
  114. package/lib/utils/omitBoolean/index.js +4 -4
  115. package/lib/utils/parseValueToMoment/index.js +4 -4
  116. package/lib/utils/proFieldParsingText/index.js +10 -10
  117. package/lib/utils/transformKeySubmitValue/index.js +57 -57
  118. package/lib/utils/useEditableArray/index.js +46 -46
  119. package/lib/utils/useEditableMap/index.js +22 -22
  120. package/lib/utils/useMediaQuery/index.js +5 -5
  121. package/lib/vtx-combogrid/Combogrid.js +5 -4
  122. package/lib/vtx-combogrid/index.js +7 -4
  123. package/lib/vtx-datagrid/Store/Provide.js +113 -143
  124. package/lib/vtx-datagrid/ToolBar/components/ColumnSetting/index.js +11 -7
  125. package/lib/vtx-datagrid/ToolBar/components/ColumnSetting/style.js +5 -2
  126. package/lib/vtx-datagrid/ToolBar/components/Density/index.js +3 -0
  127. package/lib/vtx-datagrid/ToolBar/components/TableStyle/index.js +3 -0
  128. package/lib/vtx-datagrid/columnState.js +100 -0
  129. package/lib/vtx-datagrid/index.js +124 -32
  130. package/lib/vtx-datagrid/mergeComponents.js +21 -0
  131. package/lib/vtx-datagrid/renderColumnButtons.js +30 -11
  132. package/lib/vtx-datagrid/style/index.js +102 -20
  133. package/lib/vtx-datagrid/style/index.less +242 -242
  134. package/lib/vtx-date-picker/QdatePicker.js +1 -1
  135. package/lib/vtx-date-picker/style/index.less +39 -39
  136. package/lib/vtx-descriptions/Descriptions.js +38 -0
  137. package/lib/vtx-descriptions/index.js +15 -0
  138. package/lib/vtx-descriptions/style/index.js +25 -0
  139. package/lib/vtx-ellipsis-text/index.js +7 -2
  140. package/lib/vtx-ellipsis-text/style/index.js +3 -1
  141. package/lib/vtx-export/index.js +34 -34
  142. package/lib/vtx-export-async/History.js +14 -8
  143. package/lib/vtx-export-async/index.js +43 -13
  144. package/lib/vtx-export-async/util.js +16 -5
  145. package/lib/vtx-form-layout/Card.js +9 -9
  146. package/lib/vtx-form-layout/Divider.js +1 -1
  147. package/lib/vtx-form-layout/FormItem.js +16 -16
  148. package/lib/vtx-form-layout/Pane.js +22 -11
  149. package/lib/vtx-icon/index.js +54 -52
  150. package/lib/vtx-icon/index.js1 +90 -0
  151. package/lib/vtx-image/Preview.js +11 -6
  152. package/lib/vtx-image/style/index.js +0 -1
  153. package/lib/vtx-import/index.js +209 -71
  154. package/lib/vtx-import/result.js +29 -27
  155. package/lib/vtx-import/style/index.js +16 -1
  156. package/lib/vtx-import2/Content.js +2 -1
  157. package/lib/vtx-import2/index.js +29 -18
  158. package/lib/vtx-import2/style/index.js +60 -9
  159. package/lib/vtx-modal/index.js +11 -6
  160. package/lib/vtx-page-layout/Basic.js +2 -2
  161. package/lib/vtx-page-layout/TabLayout.js +6 -6
  162. package/lib/vtx-page-layout/TableLayout.js +10 -10
  163. package/lib/vtx-page-layout/TreeLayout.js +6 -6
  164. package/lib/vtx-page-layout/container.js +2 -2
  165. package/lib/vtx-page-layout/style/index.js +4 -2
  166. package/lib/vtx-provider/index.js +37 -33
  167. package/lib/vtx-provider/intl.js +9 -9
  168. package/lib/vtx-provider/locale/en_US.js +57 -3
  169. package/lib/vtx-provider/locale/zh_CN.js +57 -3
  170. package/lib/vtx-provider/useStyle/index.js +17 -17
  171. package/lib/vtx-search/index.js +13 -9
  172. package/lib/vtx-search/style/index.js +2 -1
  173. package/lib/vtx-select/index.js +104 -38
  174. package/lib/vtx-select/style/index.js +11 -56
  175. package/lib/vtx-signature/index.js +4 -3
  176. package/lib/vtx-signature/style/index.js +1 -1
  177. package/lib/vtx-split-pane/Resizer.js +0 -1
  178. package/lib/vtx-split-pane/SplitPane.js +40 -31
  179. package/lib/vtx-split-pane/style/index.js +8 -112
  180. package/lib/vtx-time-picker/index.js +27 -1
  181. package/lib/vtx-transfer/Transfer.js +38 -0
  182. package/lib/vtx-transfer/index.js +15 -0
  183. package/lib/vtx-transfer/style/index.js +25 -0
  184. package/lib/vtx-transfer-select/TransferSelect.js +151 -0
  185. package/lib/vtx-transfer-select/index.js +15 -0
  186. package/lib/vtx-transfer-select/style/index.js +25 -0
  187. package/lib/vtx-tree/index.js +96 -33
  188. package/lib/vtx-tree-select/index.js +71 -105
  189. package/lib/vtx-tree-select/style/index.js +9 -3
  190. package/lib/vtx-upload/FilePreview.js +2 -1
  191. package/lib/vtx-wang-editor/index.js +91 -37
  192. package/lib/vtx-wang-editor/style/index.less +12 -12
  193. package/lib/vtx-wang-editor/wangEditorUtil.js +4 -0
  194. package/package.json +240 -225
  195. package/es/utils/hooks/useFetchData/index.js +0 -82
  196. package/lib/utils/hooks/useFetchData/index.js +0 -89
@@ -0,0 +1,90 @@
1
+ import { lazy, memo, Suspense, useMemo } from 'react';
2
+ import AlignRightOutlined from './svg/alignRightOutlined.js';
3
+ import ColumnHeightOutlined from './svg/columnHeightOutlined.js';
4
+ import DownOutlined from './svg/downOutlined.js';
5
+ import Fullscreen from './svg/fullscreen.js';
6
+ import RedoOutlined from './svg/redoOutlined.js';
7
+ import RightOutlined from './svg/rightOutlined.js';
8
+ import SettingOutlined from './svg/settingOutlined.js';
9
+
10
+
11
+ const iconComponents = {
12
+ alignRightOutlined: AlignRightOutlined,
13
+ columnHeightOutlined: ColumnHeightOutlined,
14
+ downOutlined: DownOutlined,
15
+ fullscreen: Fullscreen,
16
+ redoOutlined: RedoOutlined,
17
+ rightOutlined: RightOutlined,
18
+ settingOutlined: SettingOutlined,
19
+ // 低频图标如果确实需要,可以再考虑 lazy
20
+ };
21
+
22
+ // const iconComponents = {
23
+ // // 核心:添加你需要的所有图标, 动态导入有的组件会失败
24
+ // alignRightOutlined: lazy(() => import('./svg/alignRightOutlined.js')),
25
+ // columnHeightOutlined: lazy(() => import('./svg/columnHeightOutlined.js')),
26
+ // downOutlined: lazy(() => import('./svg/downOutlined.js')),
27
+ // fullscreen: lazy(() => import('./svg/fullscreen.js')),
28
+ // redoOutlined: lazy(() => import('./svg/redoOutlined.js')),
29
+ // rightOutlined: lazy(() => import('./svg/rightOutlined.js')),
30
+ // settingOutlined: lazy(() => import('./svg/settingOutlined.js')),
31
+ // // 新增其他图标...
32
+ // };
33
+
34
+
35
+ const VtxIcon = memo(({
36
+ type,
37
+ size = 16,
38
+ className = '',
39
+ style = {},
40
+ color,
41
+ fileType = 'webp',
42
+ ...props
43
+ }) => {
44
+ const width = props.width || size;
45
+ const height = props.height || size;
46
+ if (!type) {
47
+ return null;
48
+ }
49
+ // const SvgComponent = useMemo(() => {
50
+ // // 动态导入并缓存结果
51
+ // return lazy(() => import(/* @vite-ignore */`./svg/${type}.js`));
52
+ // }, [type]);
53
+
54
+ const SvgComponent = useMemo(() => {
55
+ // 兜底:找不到对应图标时,返回一个空组件(避免报错)
56
+ return iconComponents[type] || lazy(() => Promise.resolve({ default: () => <svg width={width} height={height} /> }));
57
+ }, [type, width, height]);
58
+
59
+ // 默认返回空元素
60
+ if (fileType == 'svg') {
61
+ try {
62
+ // const SvgComponent = lazy(() => import(`./svg/${type}.js`));
63
+ return (
64
+ <Suspense fallback={<div style={{ width, height, ...style }} />}>
65
+ <SvgComponent
66
+ className={className}
67
+ style={{ width, height, ...style }}
68
+ fill={color}
69
+ {...props}
70
+ />
71
+ </Suspense>
72
+ );
73
+ } catch (error) {
74
+ // 如果动态导入失败,返回空的 SVG 元素
75
+ return (
76
+ <svg width={width} height={height} style={style} className={className} {...props} />
77
+ );
78
+ }
79
+ } else {
80
+ return (
81
+ // <img
82
+ // src={require(`./assets/${type}.${fileType}`)}
83
+ // style={{ width, height, ...style }}
84
+ // />
85
+ <></>
86
+ );
87
+ }
88
+ });
89
+ export { VtxIcon }
90
+ export default VtxIcon;
@@ -22,15 +22,12 @@ var VIEWER = 'viewer';
22
22
  // 多张
23
23
  var GALLERY = 'gallery';
24
24
  function checkMode(x) {
25
- var mode = '';
26
- if (isObject(x)) {
27
- mode = VIEWER;
28
- }
29
25
  if (Array.isArray(x)) {
30
26
  var len = x.length;
31
- mode = len == 0 ? '' : len == 1 ? VIEWER : GALLERY;
27
+ if (len === 0) return null;
28
+ return len === 1 ? VIEWER : GALLERY;
32
29
  }
33
- return mode;
30
+ return isObject(x) ? VIEWER : null;
34
31
  }
35
32
  export default function Preview(props) {
36
33
  var _useState = useState(),
@@ -87,6 +84,9 @@ export default function Preview(props) {
87
84
  setContainer(container);
88
85
  setViewer(viewer);
89
86
  return function () {
87
+ if (container) {
88
+ container.innerHTML = '';
89
+ }
90
90
  viewer && viewer.destroy();
91
91
  };
92
92
  }, []);
@@ -96,6 +96,7 @@ export default function Preview(props) {
96
96
  container.innerHTML = '';
97
97
  }
98
98
  var mode = checkMode(photo);
99
+ if (!mode) return null;
99
100
  var newIndex = index;
100
101
  // 单张
101
102
  if (mode === VIEWER) {
@@ -126,6 +127,10 @@ export default function Preview(props) {
126
127
  }
127
128
  viewer.update();
128
129
  viewer.view(newIndex);
130
+ } else {
131
+ if (container) {
132
+ container.innerHTML = '';
133
+ }
129
134
  }
130
135
  }, [visible]);
131
136
  return /*#__PURE__*/_jsx(_Fragment, {});
@@ -20,7 +20,6 @@ var center = function center() {
20
20
  };
21
21
  var genVtxImageStyle = function genVtxImageStyle(token) {
22
22
  var componentCls = token.componentCls;
23
- console.log('componentCls', componentCls);
24
23
  return _defineProperty(_defineProperty(_defineProperty({}, componentCls, _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, '&-aspectFit', {
25
24
  position: 'relative',
26
25
  height: '100%',
@@ -1,30 +1,37 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
4
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
5
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
6
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
- import React, { useRef, useEffect, useContext } from 'react';
14
- import { ConfigProvider, message, Button, Modal } from 'antd';
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ import { useContext, useEffect, useRef } from 'react';
14
+ import { getSignature, getVtxToken } from '@vtx/utils';
15
+ import { Button, Tooltip, message } from 'antd';
16
+ import md5 from 'md5';
15
17
  import PropTypes from 'prop-types';
18
+ import { useMemo } from 'react';
19
+ import getToken from "../utils/getToken";
16
20
  import useSet from "../utils/useSet";
21
+ import VtxModal from "../vtx-modal";
22
+ import { VtxProvider, useIntl } from "../vtx-provider";
17
23
  import VtxImportResult from "./result";
18
- import getToken from "../utils/getToken";
19
- var token = getToken();
20
- import md5 from 'md5';
21
- import { getVtxToken, getSignature } from '@vtx/utils';
22
- import classnames from 'classnames';
23
24
  import { useStyle } from "./style/index";
24
- import { VtxProvider, useIntl } from "../vtx-provider";
25
- import { jsx as _jsx } from "react/jsx-runtime";
26
25
  import { jsxs as _jsxs } from "react/jsx-runtime";
26
+ import { jsx as _jsx } from "react/jsx-runtime";
27
27
  function VtxImport(props) {
28
+ var templateURL = props.templateURL,
29
+ uploadURL = props.uploadURL,
30
+ afterUpload = props.afterUpload,
31
+ beforeUpload = props.beforeUpload;
32
+ var token = useMemo(function () {
33
+ return props.token || getToken();
34
+ }, [props.token]);
28
35
  var intl = useIntl();
29
36
  var _useContext = useContext(VtxProvider),
30
37
  getPrefixCls = _useContext.getPrefixCls;
@@ -32,14 +39,35 @@ function VtxImport(props) {
32
39
  var _useStyle = useStyle(prefixCls),
33
40
  wrapSSR = _useStyle.wrapSSR,
34
41
  hashId = _useStyle.hashId;
42
+ var TextEnum = _objectSpread({
43
+ rowNumberText: intl.getMessage('import.rowNumber', '行号'),
44
+ errorMessageText: intl.getMessage('import.errorMessage', '错误说明'),
45
+ resultTitleText: intl.getMessage('import.result', '导入结果'),
46
+ btnCloseText: intl.getMessage('switch.close', '关闭'),
47
+ operationText: intl.getMessage('import.operation', '导入'),
48
+ uploadFailedText: intl.getMessage('import.error', '上传失败'),
49
+ parseResponseFailedText: intl.getMessage('import.error', '解析响应失败'),
50
+ uploadSuccessText: intl.getMessage('import.success', '上传成功'),
51
+ parseResponseDataFailedText: intl.getMessage('import.error', '解析响应数据失败'),
52
+ downloadTemplateText: intl.getMessage('import.downloadTemplate', '下载模板'),
53
+ pleaseSelectFileText: intl.getMessage('import.pleaseSelectFile', '请选择需要上传的文件'),
54
+ uploadText: intl.getMessage('import.upload', '上传'),
55
+ selectFileText: intl.getMessage('import.selectFile', '选择文件'),
56
+ noFileSelectedText: intl.getMessage('import.noFileSelected', '未选择任何文件')
57
+ }, props.customEnumText);
58
+
59
+ // 用 useRef 管理 DOM 引用,而不是 state
60
+ var fileInputRef = useRef(null);
61
+ var iframeRef = useRef(null);
62
+ var formRef = useRef(null);
63
+
64
+ // 用于追踪当前 XHR 请求,方便取消
65
+ var xhrRef = useRef(null);
35
66
  var indexRef = useRef(0);
36
67
  var _useSet = useSet({
37
- fileForm: null,
38
- // form表单
39
- fileInput: null,
40
- // 保存上传的文件
41
- iframe: null,
42
- // form表单提交之后跳转的
68
+ // fileForm: null, // form表单
69
+ // fileInput: null, // 保存上传的文件
70
+ // iframe: null, // form表单提交之后跳转的
43
71
  useFormData: window.FormData ? true : false,
44
72
  // 是否查看
45
73
  uploading: false,
@@ -53,13 +81,22 @@ function VtxImport(props) {
53
81
  // 导入结果查看
54
82
  modalWidth: props.modalWidth || 800,
55
83
  columns: props.columns || [{
56
- title: '行号',
84
+ title: TextEnum.rowNumberText,
57
85
  dataIndex: 'lineNum',
58
86
  key: 'lineNum'
59
87
  }, {
60
- title: '错误说明',
88
+ title: TextEnum.errorMessageText,
61
89
  dataIndex: 'messages',
62
- key: 'messages'
90
+ key: 'messages',
91
+ render: function render(val) {
92
+ return /*#__PURE__*/_jsxs("div", {
93
+ style: {
94
+ display: 'flex',
95
+ width: 600
96
+ },
97
+ children: [" ", val]
98
+ });
99
+ }
63
100
  }],
64
101
  step: 1,
65
102
  chunkSize: props.chunkSize || 10 * 1024 * 1024,
@@ -67,7 +104,8 @@ function VtxImport(props) {
67
104
  currentIndex: 0,
68
105
  chunkId: '',
69
106
  chunks: [],
70
- operation: props.operation || intl.getMessage('import.operation', '导入')
107
+ operation: props.operation || TextEnum.operationText,
108
+ fileName: ''
71
109
  }),
72
110
  _useSet2 = _slicedToArray(_useSet, 2),
73
111
  state = _useSet2[0],
@@ -102,7 +140,7 @@ function VtxImport(props) {
102
140
  data.append('chunkNo', i + 1);
103
141
  data.append('chunkId', state.chunkId);
104
142
  data.append('tenantId', getVtxToken('tenantId'));
105
- data.append('file', new File([e], state.fileInput.files[0].name));
143
+ data.append('file', new File([e], fileInputRef.current.files[0].name));
106
144
  dataArr.push(data);
107
145
  });
108
146
  uploadAsync(dataArr);
@@ -112,6 +150,7 @@ function VtxImport(props) {
112
150
  function uploadAsync(list) {
113
151
  if (indexRef.current < list.length) {
114
152
  var xhr = new XMLHttpRequest();
153
+ xhrRef.current = xhr;
115
154
  xhr.onload = function () {
116
155
  if (xhr.status === 200) {
117
156
  setState({
@@ -122,10 +161,12 @@ function VtxImport(props) {
122
161
  }
123
162
  };
124
163
  xhr.onerror = function () {
125
- message.error(intl.getMessage('import.error', '上传失败'));
164
+ message.error(TextEnum.uploadFailedText);
126
165
  };
127
166
  // 发送请求
128
167
  xhr.open('POST', '/cloudFile/common/uploadChunk', true);
168
+ xhr.setRequestHeader('Authorization', token ? "Bearer ".concat(token) : '');
169
+ xhr.setRequestHeader('access_token', token ? "".concat(token) : '');
129
170
  xhr.send(list[indexRef.current]);
130
171
  } else {
131
172
  mergeFile();
@@ -135,28 +176,42 @@ function VtxImport(props) {
135
176
  // 合并分片
136
177
  function mergeFile() {
137
178
  var xhr = new XMLHttpRequest();
179
+ xhrRef.current = xhr;
138
180
  // 当上传完成时调用
139
181
  xhr.onload = function () {
140
182
  if (xhr.status === 200) {
141
- var res = JSON.parse(xhr.responseText);
142
- if ((res === null || res === void 0 ? void 0 : res.result) == 0) {
143
- message.success(intl.getMessage('import.success', '上传成功'));
183
+ var _res;
184
+ var res;
185
+ try {
186
+ res = JSON.parse(xhr.responseText);
187
+ } catch (e) {
188
+ message.error(TextEnum.parseResponseFailedText);
189
+ setState({
190
+ uploading: false
191
+ });
192
+ return;
193
+ }
194
+ if (((_res = res) === null || _res === void 0 ? void 0 : _res.result) == 0) {
195
+ message.success(TextEnum.uploadSuccessText);
144
196
  chunkUpload(res.data);
145
197
  } else {
146
- message.error((res === null || res === void 0 ? void 0 : res.msg) || intl.getMessage('import.error', '上传失败'));
198
+ var _res2;
199
+ message.error(((_res2 = res) === null || _res2 === void 0 ? void 0 : _res2.msg) || TextEnum.uploadFailedText);
147
200
  }
148
201
  }
149
202
  };
150
203
  xhr.onerror = function () {
151
- message.error(intl.getMessage('import.error', '上传失败'));
204
+ message.error(TextEnum.uploadFailedText);
152
205
  };
153
206
  // 发送请求
154
207
  xhr.open('POST', '/cloudFile/common/mergeChunk', true);
208
+ xhr.setRequestHeader('Authorization', token ? "Bearer ".concat(token) : '');
209
+ xhr.setRequestHeader('access_token', token ? "".concat(token) : '');
155
210
  var data = new FormData();
156
211
  data.append('chunkId', state.chunkId);
157
212
  data.append('tenantId', getVtxToken('tenantId'));
158
213
  data.append('chunkSize', state.chunks.length);
159
- data.append('fileName', state.fileInput.files[0].name);
214
+ data.append('fileName', fileInputRef.current.files[0].name);
160
215
  xhr.send(data);
161
216
  }
162
217
 
@@ -166,6 +221,7 @@ function VtxImport(props) {
166
221
  var postData = props.postData || {};
167
222
  if (state.useFormData) {
168
223
  var request = new XMLHttpRequest();
224
+ xhrRef.current = request;
169
225
  // 发送请求
170
226
  request.open('POST', postUrl);
171
227
  request.setRequestHeader('Authorization', token ? "Bearer ".concat(token) : '');
@@ -196,6 +252,7 @@ function VtxImport(props) {
196
252
  var postData = props.postData || {};
197
253
  if (state.useFormData) {
198
254
  var request = new XMLHttpRequest();
255
+ xhrRef.current = request;
199
256
  // 发送请求
200
257
  request.open('POST', postUrl);
201
258
  request.setRequestHeader('Authorization', token ? "Bearer ".concat(token) : '');
@@ -216,7 +273,7 @@ function VtxImport(props) {
216
273
  };
217
274
  //创建formdata对象
218
275
  var fmd = new FormData();
219
- fmd.append(state.fileKey, state.fileInput.files[0]);
276
+ fmd.append(state.fileKey, fileInputRef.current.files[0]);
220
277
  request.send(fmd);
221
278
  }
222
279
  }
@@ -247,7 +304,9 @@ function VtxImport(props) {
247
304
  return postArray.length > 0 ? "".concat(postUrl, "?").concat(postArray.join('&')) : postUrl;
248
305
  };
249
306
  var closeModal = function closeModal() {
250
- state.fileInput.value = '';
307
+ if (fileInputRef.current) {
308
+ fileInputRef.current.value = '';
309
+ }
251
310
  if (typeof props.close === 'function') {
252
311
  props.close();
253
312
  } else {
@@ -258,15 +317,24 @@ function VtxImport(props) {
258
317
  };
259
318
  // 上传之后的回调 - 展示报错信息
260
319
  var uploadSuccess = function uploadSuccess(data) {
261
- state.fileInput.value = '';
320
+ var _parseData;
321
+ if (fileInputRef.current) {
322
+ fileInputRef.current.value = '';
323
+ }
262
324
  setState({
263
325
  uploading: false
264
326
  });
327
+ var parseData;
328
+ try {
329
+ parseData = JSON.parse(data);
330
+ } catch (e) {
331
+ message.error(TextEnum.parseResponseDataFailedText);
332
+ return;
333
+ }
265
334
  if (typeof props.afterUpload === 'function') {
266
335
  afterUpload(data);
267
336
  }
268
- var parseData = JSON.parse(data);
269
- if (Array.isArray(parseData === null || parseData === void 0 ? void 0 : parseData.data)) {
337
+ if (Array.isArray((_parseData = parseData) === null || _parseData === void 0 ? void 0 : _parseData.data)) {
270
338
  setState({
271
339
  resultVisible: true,
272
340
  resultData: parseData.data.map(function (item, index) {
@@ -281,47 +349,46 @@ function VtxImport(props) {
281
349
  } else {
282
350
  // 新增其他错误提示
283
351
  if (parseData.result !== 0) {
284
- message.error((parseData === null || parseData === void 0 ? void 0 : parseData.msg) || intl.getMessage('import.success', '上传成功'));
352
+ var _parseData2;
353
+ message.error(((_parseData2 = parseData) === null || _parseData2 === void 0 ? void 0 : _parseData2.msg) || TextEnum.uploadSuccessText);
285
354
  }
286
355
  }
287
356
  };
288
- var templateURL = props.templateURL,
289
- uploadURL = props.uploadURL,
290
- afterUpload = props.afterUpload,
291
- beforeUpload = props.beforeUpload;
292
357
  var modalProps = {
293
358
  className: "".concat(prefixCls, "-modal"),
294
359
  open: state.visible,
295
- title: intl.getMessage('import.operation', '导入'),
360
+ title: TextEnum.operationText,
296
361
  onCancel: function onCancel() {
297
362
  return closeModal();
298
363
  },
299
- maskClosable: false,
364
+ // maskClosable: false,
365
+ mask: {
366
+ closable: false
367
+ },
300
368
  footer: [templateURL ? /*#__PURE__*/_jsx(Button, {
301
369
  onClick: function onClick() {
302
370
  window.open(templateURL);
303
371
  },
304
- children: intl.getMessage('import.downloadTemplate', '下载模板')
372
+ children: TextEnum.downloadTemplateText
305
373
  }, "downloadTemple") : null, /*#__PURE__*/_jsx(Button, {
306
374
  type: "primary",
307
375
  loading: state.uploading,
308
376
  onClick: function onClick() {
377
+ var _fileInputRef$current2;
309
378
  if (typeof props.beforeUpload === 'function') {
310
- var flag = beforeUpload(state.fileInput.files[0]);
379
+ var _fileInputRef$current;
380
+ var flag = beforeUpload((_fileInputRef$current = fileInputRef.current) === null || _fileInputRef$current === void 0 || (_fileInputRef$current = _fileInputRef$current.files) === null || _fileInputRef$current === void 0 ? void 0 : _fileInputRef$current[0]);
311
381
  if (!flag) {
312
- state.fileInput.value = '';
313
- setState({
314
- fileInput: null
315
- });
382
+ fileInputRef.current.value = '';
316
383
  return;
317
384
  }
318
385
  }
319
- if (state.fileInput.value) {
386
+ if ((_fileInputRef$current2 = fileInputRef.current) !== null && _fileInputRef$current2 !== void 0 && _fileInputRef$current2.value) {
320
387
  setState({
321
388
  uploading: true
322
389
  });
323
390
  // 上传文件
324
- checkFile(state.fileInput.files[0]);
391
+ checkFile(fileInputRef.current.files[0]);
325
392
  // const postUrl = getPostURL();
326
393
  // if (state.useFormData) {
327
394
  // const request = new XMLHttpRequest();
@@ -341,16 +408,17 @@ function VtxImport(props) {
341
408
  // request.send(fmd);
342
409
  // }
343
410
  } else {
344
- message.info(intl.getMessage('import.pleaseSelectFile', '请选择需要上传的文件'));
411
+ message.info(TextEnum.pleaseSelectFileText);
345
412
  }
346
413
  },
347
- children: intl.getMessage('import.upload', '上传')
414
+ children: TextEnum.uploadText
348
415
  }, "uploadSubmit"), /*#__PURE__*/_jsx(Button, {
349
416
  onClick: function onClick() {
350
417
  closeModal();
351
418
  },
352
- children: intl.getMessage('switch.close', '关闭')
353
- }, "closeWindow")]
419
+ children: TextEnum.btnCloseText
420
+ }, "closeWindow")],
421
+ width: 520
354
422
  };
355
423
  var resultProps = {
356
424
  visible: state.resultVisible,
@@ -361,38 +429,109 @@ function VtxImport(props) {
361
429
  resultVisible: false
362
430
  });
363
431
  },
364
- modalWidth: state.modalWidth
432
+ modalWidth: state.modalWidth,
433
+ TextEnum: TextEnum
365
434
  };
435
+
436
+ // 组件卸载时清理
437
+ useEffect(function () {
438
+ return function () {
439
+ // 取消进行中的 XHR 请求
440
+ if (xhrRef.current) {
441
+ xhrRef.current.abort();
442
+ xhrRef.current = null;
443
+ }
444
+ // 清理文件输入
445
+ if (fileInputRef.current) {
446
+ fileInputRef.current.value = '';
447
+ }
448
+ };
449
+ }, []);
366
450
  useEffect(function () {
367
451
  if (state.chunkId) {
368
452
  startUpload();
369
453
  }
370
454
  }, [state.chunkId]);
371
- return wrapSSR( /*#__PURE__*/_jsxs(Modal, _objectSpread(_objectSpread({}, modalProps), {}, {
372
- children: [props.children, /*#__PURE__*/_jsx("form", {
455
+ var truncateFileName = function truncateFileName(fileName) {
456
+ var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 28;
457
+ if (fileName.length <= maxLength) return fileName;
458
+ var extIndex = fileName.lastIndexOf('.');
459
+ var ext = extIndex !== -1 ? fileName.slice(extIndex) : '';
460
+ var name = extIndex !== -1 ? fileName.slice(0, extIndex) : fileName;
461
+ var availableLength = maxLength - ext.length - 3; // 3 是 "..."
462
+ if (availableLength <= 0) return "...".concat(ext);
463
+ var startLength = Math.ceil(availableLength / 2);
464
+ var endLength = Math.floor(availableLength / 2);
465
+ var start = name.slice(0, startLength);
466
+ var end = name.slice(-endLength);
467
+ return "".concat(start, "...").concat(end).concat(ext);
468
+ };
469
+
470
+ // 处理文件选择变化
471
+ var handleFileChange = function handleFileChange(event) {
472
+ var _event$target$files;
473
+ var file = (_event$target$files = event.target.files) === null || _event$target$files === void 0 ? void 0 : _event$target$files[0];
474
+ if (file) {
475
+ setState(function (prev) {
476
+ return _objectSpread(_objectSpread({}, prev), {}, {
477
+ fileName: truncateFileName(file.name)
478
+ });
479
+ });
480
+ // 这里可以添加文件上传或其他处理逻辑
481
+ // 例如:uploadFile(file);
482
+ } else {
483
+ setState(function (prev) {
484
+ return _objectSpread(_objectSpread({}, prev), {}, {
485
+ fileName: ''
486
+ });
487
+ });
488
+ }
489
+ };
490
+ var handleSelectFile = function handleSelectFile() {
491
+ var _fileInputRef$current3;
492
+ (_fileInputRef$current3 = fileInputRef.current) === null || _fileInputRef$current3 === void 0 || _fileInputRef$current3.click();
493
+ };
494
+ return wrapSSR( /*#__PURE__*/_jsxs(VtxModal, _objectSpread(_objectSpread({}, modalProps), {}, {
495
+ children: [props.children, /*#__PURE__*/_jsxs("form", {
373
496
  encType: "multipart/form-data",
374
497
  method: "post",
375
498
  target: "tmp",
376
499
  action: uploadURL,
377
- ref: function ref(dom) {
378
- if (dom) state.fileForm = dom;
379
- },
380
- children: /*#__PURE__*/_jsx("input", {
500
+ ref: formRef,
501
+ children: [/*#__PURE__*/_jsxs("div", {
502
+ className: "".concat(prefixCls, "-btn"),
503
+ children: [/*#__PURE__*/_jsx(Button, {
504
+ onClick: handleSelectFile,
505
+ children: /*#__PURE__*/_jsx("span", {
506
+ className: "".concat(prefixCls, "-label"),
507
+ children: TextEnum.selectFileText
508
+ })
509
+ }), state.fileName ? /*#__PURE__*/_jsx(Tooltip, {
510
+ title: state.fileName,
511
+ children: /*#__PURE__*/_jsx("div", {
512
+ className: "".concat(prefixCls, "-file-name"),
513
+ children: state.fileName
514
+ })
515
+ }) : /*#__PURE__*/_jsx("div", {
516
+ className: "".concat(prefixCls, "-file-name"),
517
+ children: TextEnum.noFileSelectedText
518
+ })]
519
+ }), /*#__PURE__*/_jsx("input", {
381
520
  type: "file",
382
521
  name: state.fileKey,
383
522
  accept: state.accept,
384
- ref: function ref(dom) {
385
- if (dom) state.fileInput = dom;
386
- }
387
- })
523
+ ref: fileInputRef,
524
+ style: {
525
+ display: 'none'
526
+ },
527
+ onChange: handleFileChange
528
+ })]
388
529
  }), /*#__PURE__*/_jsx("iframe", {
389
530
  name: "tmp",
390
531
  style: {
391
532
  display: 'none'
392
533
  },
393
- ref: function ref(dom) {
394
- if (dom) state.iframe = dom;
395
- }
534
+ ref: iframeRef
396
535
  }), state.resultVisible && /*#__PURE__*/_jsx(VtxImportResult, _objectSpread({}, resultProps))]
397
536
  })));
398
537
  }
@@ -403,11 +542,13 @@ VtxImport.propTypes = {
403
542
  postData: PropTypes.object,
404
543
  fileKey: PropTypes.string,
405
544
  accept: PropTypes.string,
545
+ token: PropTypes.string,
406
546
  operation: PropTypes.string,
407
547
  close: PropTypes.func,
408
548
  afterUpload: PropTypes.func,
409
549
  modalWidth: PropTypes.number,
410
550
  columns: PropTypes.array,
551
+ customEnumText: PropTypes.object,
411
552
  children: PropTypes.object,
412
553
  beforeUpload: PropTypes.func,
413
554
  chunkSize: PropTypes.number