@bit-sun/business-component 3.1.4 → 3.1.6

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 (225) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +5 -5
  3. package/.gitlab-ci.yml +179 -179
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/.yarnclean +45 -0
  8. package/README.md +27 -27
  9. package/dist/components/Business/DetailPageWrapper/utils.d.ts +3 -1
  10. package/dist/components/Functional/DataImport/index.d.ts +2 -0
  11. package/dist/components/Functional/DataValidation/index.d.ts +2 -0
  12. package/dist/index.esm.js +403 -43
  13. package/dist/index.js +405 -41
  14. package/dist/utils/LocalstorageUtils.d.ts +1 -0
  15. package/dist/utils/enumConfig.d.ts +1 -0
  16. package/dist/utils/index.d.ts +2 -0
  17. package/dist/utils/xlsxUtil.d.ts +6 -0
  18. package/docs/index.md +21 -21
  19. package/lib/assets/drag.svg +17 -17
  20. package/lib/assets/exportFail.svg +37 -37
  21. package/lib/assets/exportProcessing.svg +28 -28
  22. package/lib/assets/exportSuccess.svg +34 -34
  23. package/lib/assets/label_icon_bottom.svg +25 -25
  24. package/lib/assets/upExport.svg +22 -22
  25. package/package.json +88 -87
  26. package/src/assets/32.svg +27 -27
  27. package/src/assets/addIcon.svg +17 -17
  28. package/src/assets/allfunc.svg +27 -27
  29. package/src/assets/arrowRight.svg +24 -24
  30. package/src/assets/arrow_top.svg +17 -17
  31. package/src/assets/btn-delete.svg +29 -29
  32. package/src/assets/btn-edit.svg +19 -19
  33. package/src/assets/btn-more.svg +17 -17
  34. package/src/assets/btn-submit.svg +19 -19
  35. package/src/assets/caidan.svg +11 -11
  36. package/src/assets/close.svg +26 -26
  37. package/src/assets/drag.svg +17 -17
  38. package/src/assets/exportFail.svg +37 -37
  39. package/src/assets/exportProcessing.svg +28 -28
  40. package/src/assets/exportSuccess.svg +34 -34
  41. package/src/assets/fixed-left-active.svg +11 -11
  42. package/src/assets/fixed-left.svg +15 -15
  43. package/src/assets/fixed-right-active.svg +11 -11
  44. package/src/assets/fixed-right.svg +15 -15
  45. package/src/assets/guanbi.svg +15 -15
  46. package/src/assets/icon-quanping.svg +15 -15
  47. package/src/assets/icon-shezhi.svg +17 -17
  48. package/src/assets/label_icon_bottom.svg +25 -25
  49. package/src/assets/list-no-img.svg +21 -21
  50. package/src/assets/morentouxiang-32.svg +23 -23
  51. package/src/assets/scanning.svg +24 -24
  52. package/src/assets/upExport.svg +22 -22
  53. package/src/common/ENUM.ts +41 -41
  54. package/src/components/Business/AddSelectBusiness/index.md +398 -398
  55. package/src/components/Business/AddSelectBusiness/index.tsx +1116 -1116
  56. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +112 -112
  57. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  58. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  59. package/src/components/Business/BsLayouts/Components/ChooseStore/index.tsx +193 -193
  60. package/src/components/Business/BsLayouts/Components/ChooseStore/services.ts +10 -10
  61. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  62. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  63. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  64. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  65. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  66. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  67. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  68. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  69. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  70. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  71. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +163 -163
  72. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  73. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  74. package/src/components/Business/BsLayouts/Components/RightContent/i18n.ts +8 -8
  75. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +172 -172
  76. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  77. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  78. package/src/components/Business/BsLayouts/index.less +79 -79
  79. package/src/components/Business/BsLayouts/index.tsx +1606 -1606
  80. package/src/components/Business/BsLayouts/service.ts +10 -10
  81. package/src/components/Business/BsLayouts/utils.tsx +205 -205
  82. package/src/components/Business/BsSulaQueryTable/SearchItemSetting.tsx +566 -566
  83. package/src/components/Business/BsSulaQueryTable/bssulaquerytable.less +5 -5
  84. package/src/components/Business/BsSulaQueryTable/index.less +227 -227
  85. package/src/components/Business/BsSulaQueryTable/index.tsx +772 -772
  86. package/src/components/Business/BsSulaQueryTable/setting.tsx +888 -888
  87. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  88. package/src/components/Business/BsSulaQueryTable/utils.tsx +709 -709
  89. package/src/components/Business/CommodityEntry/index.md +84 -84
  90. package/src/components/Business/CommodityEntry/index.tsx +82 -82
  91. package/src/components/Business/CommonAlert/index.tsx +23 -23
  92. package/src/components/Business/CommonGuideWrapper/index.less +121 -121
  93. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  94. package/src/components/Business/CommonGuideWrapper/index.tsx +94 -94
  95. package/src/components/Business/DetailPageWrapper/index.less +87 -87
  96. package/src/components/Business/DetailPageWrapper/index.tsx +327 -326
  97. package/src/components/Business/DetailPageWrapper/utils.tsx +166 -164
  98. package/src/components/Business/HomePageWrapper/index.less +33 -33
  99. package/src/components/Business/HomePageWrapper/index.md +45 -45
  100. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  101. package/src/components/Business/JsonQueryTable/components/FieldsModifyModal.tsx +823 -823
  102. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +205 -205
  103. package/src/components/Business/JsonQueryTable/components/Formula.tsx +205 -205
  104. package/src/components/Business/JsonQueryTable/components/MaintainOptions.tsx +127 -127
  105. package/src/components/Business/JsonQueryTable/configButton/index.js +20 -20
  106. package/src/components/Business/JsonQueryTable/configTree/component/compactArrayView.js +25 -25
  107. package/src/components/Business/JsonQueryTable/configTree/component/compactObjectView.js +30 -30
  108. package/src/components/Business/JsonQueryTable/configTree/index.js +82 -82
  109. package/src/components/Business/JsonQueryTable/configTree/index.less +44 -44
  110. package/src/components/Business/JsonQueryTable/configTree/parser/highlight.js +57 -57
  111. package/src/components/Business/JsonQueryTable/configTree/parser/index.js +124 -124
  112. package/src/components/Business/JsonQueryTable/configTree/render/iconRender.js +29 -29
  113. package/src/components/Business/JsonQueryTable/configTree/render/nameRender.js +22 -22
  114. package/src/components/Business/JsonQueryTable/configTree/treeNode.js +116 -116
  115. package/src/components/Business/JsonQueryTable/drawer/index.tsx +12 -12
  116. package/src/components/Business/JsonQueryTable/function.ts +62 -62
  117. package/src/components/Business/JsonQueryTable/index.less +16 -16
  118. package/src/components/Business/JsonQueryTable/index.md +328 -328
  119. package/src/components/Business/JsonQueryTable/index.tsx +534 -534
  120. package/src/components/Business/JsonQueryTable/jsonEditor/index.js +346 -346
  121. package/src/components/Business/JsonQueryTable/jsonEditor/index.less +22 -22
  122. package/src/components/Business/JsonQueryTable/jsonEditor/lint/basicType.js +147 -147
  123. package/src/components/Business/JsonQueryTable/jsonEditor/lint/index.js +389 -389
  124. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/actions.js +118 -118
  125. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/dependency.js +22 -22
  126. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/index.js +21 -21
  127. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/request.js +65 -65
  128. package/src/components/Business/JsonQueryTable/static.ts +450 -450
  129. package/src/components/Business/SearchSelect/BusinessUtils.tsx +2162 -2160
  130. package/src/components/Business/SearchSelect/common.ts +134 -134
  131. package/src/components/Business/SearchSelect/index.md +1512 -1512
  132. package/src/components/Business/SearchSelect/index.tsx +55 -55
  133. package/src/components/Business/SearchSelect/utils.ts +125 -125
  134. package/src/components/Business/StateFlow/index.less +130 -130
  135. package/src/components/Business/StateFlow/index.md +60 -60
  136. package/src/components/Business/StateFlow/index.tsx +29 -29
  137. package/src/components/Business/TreeSearchSelect/index.md +211 -211
  138. package/src/components/Business/TreeSearchSelect/index.tsx +33 -33
  139. package/src/components/Business/TreeSearchSelect/utils.ts +104 -104
  140. package/src/components/Business/columnSettingTable/columnSetting.tsx +816 -816
  141. package/src/components/Business/columnSettingTable/index.less +253 -253
  142. package/src/components/Business/columnSettingTable/index.md +357 -357
  143. package/src/components/Business/columnSettingTable/index.tsx +226 -226
  144. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +233 -233
  145. package/src/components/Business/columnSettingTable/utils.tsx +87 -87
  146. package/src/components/Business/moreTreeTable/FixedScrollBar.tsx +87 -87
  147. package/src/components/Business/moreTreeTable/hooks/useSticky.ts +21 -21
  148. package/src/components/Business/moreTreeTable/index.less +99 -99
  149. package/src/components/Business/moreTreeTable/index.md +448 -448
  150. package/src/components/Business/moreTreeTable/index.tsx +387 -387
  151. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  152. package/src/components/Functional/AccessWrapper/index.tsx +33 -33
  153. package/src/components/Functional/AddSelect/helps.ts +81 -81
  154. package/src/components/Functional/AddSelect/index.less +367 -367
  155. package/src/components/Functional/AddSelect/index.md +155 -155
  156. package/src/components/Functional/AddSelect/index.tsx +1065 -1065
  157. package/src/components/Functional/AuthButton/index.tsx +15 -15
  158. package/src/components/Functional/BillEntry/index.less +371 -371
  159. package/src/components/Functional/BillEntry/index.md +39 -39
  160. package/src/components/Functional/BillEntry/index.tsx +772 -772
  161. package/src/components/Functional/BsAntdSula/BsCascader/index.md +62 -62
  162. package/src/components/Functional/BsAntdSula/BsCascader/index.tsx +178 -178
  163. package/src/components/Functional/BsAntdSula/index.ts +2 -2
  164. package/src/components/Functional/DataImport/index.less +63 -63
  165. package/src/components/Functional/DataImport/index.md +44 -44
  166. package/src/components/Functional/DataImport/index.tsx +783 -706
  167. package/src/components/Functional/DataValidation/index.less +63 -63
  168. package/src/components/Functional/DataValidation/index.md +52 -52
  169. package/src/components/Functional/DataValidation/index.tsx +788 -708
  170. package/src/components/Functional/EllipsisTooltip/index.d.ts +5 -5
  171. package/src/components/Functional/EllipsisTooltip/index.js +36 -36
  172. package/src/components/Functional/EllipsisTooltip/index.md +30 -30
  173. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  174. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +65 -65
  175. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  176. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  177. package/src/components/Functional/QueryMutipleInput/index.tsx +129 -129
  178. package/src/components/Functional/SearchSelect/index.less +121 -121
  179. package/src/components/Functional/SearchSelect/index.md +141 -141
  180. package/src/components/Functional/SearchSelect/index.tsx +1034 -1034
  181. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  182. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  183. package/src/components/Functional/TreeSearchSelect/index.tsx +224 -224
  184. package/src/components/Solution/RuleComponent/Formula.tsx +335 -335
  185. package/src/components/Solution/RuleComponent/InnerSelect.tsx +62 -62
  186. package/src/components/Solution/RuleComponent/RenderCompItem.tsx +670 -670
  187. package/src/components/Solution/RuleComponent/index.d.ts +29 -29
  188. package/src/components/Solution/RuleComponent/index.js +1601 -1601
  189. package/src/components/Solution/RuleComponent/index.less +247 -247
  190. package/src/components/Solution/RuleComponent/renderSpecificAction.js +99 -99
  191. package/src/components/Solution/RuleComponent/ruleFiled.js +2293 -2293
  192. package/src/components/Solution/RuleComponent/services.ts +13 -13
  193. package/src/components/Solution/RuleComponent/util.js +143 -143
  194. package/src/components/Solution/RuleSetter/RuleInstance.tsx +6 -6
  195. package/src/components/Solution/RuleSetter/baseRule.tsx +394 -394
  196. package/src/components/Solution/RuleSetter/function.ts +437 -437
  197. package/src/components/Solution/RuleSetter/index.less +221 -221
  198. package/src/components/Solution/RuleSetter/index.tsx +208 -208
  199. package/src/components/Solution/RuleSetter/service.js +276 -276
  200. package/src/index.ts +41 -41
  201. package/src/plugin/TableColumnSetting/index.less +247 -247
  202. package/src/plugin/TableColumnSetting/index.md +50 -50
  203. package/src/plugin/TableColumnSetting/index.tsx +725 -725
  204. package/src/plugin/TableColumnSetting/utils.ts +19 -19
  205. package/src/styles/bsDefault.less +1933 -1933
  206. package/src/utils/CheckOneUser/index.md +39 -39
  207. package/src/utils/CheckOneUser/index.ts +51 -51
  208. package/src/utils/CustomLoginInfo.ts +55 -55
  209. package/src/utils/LocalstorageUtils.ts +134 -128
  210. package/src/utils/TableUtils.less +51 -51
  211. package/src/utils/TableUtils.tsx +691 -691
  212. package/src/utils/auth.ts +38 -38
  213. package/src/utils/businessUtils.ts +434 -434
  214. package/src/utils/checkUtils.ts +39 -39
  215. package/src/utils/constant.ts +38 -38
  216. package/src/utils/enumConfig.ts +17 -16
  217. package/src/utils/getFormMode.js +12 -12
  218. package/src/utils/index.ts +19 -16
  219. package/src/utils/request.ts +53 -53
  220. package/src/utils/requestUtils.ts +193 -193
  221. package/src/utils/serialize.js +7 -7
  222. package/src/utils/utils.ts +238 -238
  223. package/src/utils/xlsxUtil.tsx +146 -0
  224. package/tsconfig.json +29 -29
  225. package/typings.d.ts +4 -4
@@ -1,706 +1,783 @@
1
- /*
2
- * @Description:
3
- * @Author: rodchen
4
- * @Date: 2021-12-01 10:52:08
5
- * @LastEditTime: 2024-07-11 19:20:39
6
- * @LastEditors: rodchen rodchen_king@outlook.com
7
- */
8
- // @ts-nocheck
9
- import React from 'react';
10
- import {
11
- Button,
12
- Card,
13
- Radio,
14
- Checkbox,
15
- Space,
16
- Dropdown,
17
- Menu,
18
- Tooltip,
19
- message,
20
- } from 'antd';
21
- import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
22
- import {
23
- ExclamationCircleOutlined,
24
- DownOutlined,
25
- ProfileTwoTone,
26
- UnorderedListOutlined,
27
- } from '@ant-design/icons';
28
- import request from '@/utils/request';
29
- import './index.less';
30
- import _ from "lodash"
31
- import { judgeIsRequestError } from '@/utils/requestUtils';
32
-
33
- // const luckysheet = window.luckysheet;
34
-
35
- let itemsTemp = [];
36
- let luckysheet;
37
-
38
- // const mapping = [
39
- // { "key": "skuCode", "name": "SKU编码", "rule": "skuCode" },
40
- // { "key": "quantity", "name": "数量", "rule": "quantity" },
41
- // { "key": "price", "name": "单价", "rule": "price" }
42
- // ]
43
-
44
- const mapping = new Map([
45
- ['skuCode', 'SKU编码'],
46
- ['quantity', '数量'],
47
- ['price', '单价'],
48
- ['regionCode', '库区'],
49
- ['checkQuantity', '实盘数量'],
50
- ['shareRatio', '共享比例'],
51
- ['lotNumberCode', '批号'],
52
- ['warehouseCode', '仓库编码'],
53
- ['regionCode', '库区'],
54
- ['locationCode', '货位'],
55
- ['rowNumber', '货位排数'],
56
- ['layerNumber', '货位层数'],
57
- ['gridNumber', '货位格号'],
58
- ['oldUniqueCode', '原始唯一码'],
59
- ['newUniqueCode', '新唯一码'],
60
- ['relationRecordCode', '单据编码'],
61
- ['remark', '备注'],
62
- ['externalCode', 'JDE商品编码'],
63
- ['realWarehouseCode', '仓库编码'],
64
- ['syncRate', '按百分比'],
65
- ['assignQuantity', '按指定数量'],
66
- ['retainQuantity', ' 按保留数量'],
67
- ['priority', ' 优先级'],
68
- ['stockBizTypeCode', ' 库存类型'],
69
- ]);
70
-
71
- // for dnd
72
- // fake data generator
73
- const getItems = (count) =>
74
- Array.from({ length: count }, (v, k) => k).map((k) => ({
75
- id: `item-${k}`,
76
- content: `item ${k}`,
77
- }));
78
-
79
- // a little function to help us with reordering the result
80
- const reorder = (list, startIndex, endIndex) => {
81
- const result = Array.from(list);
82
- const [removed] = result.splice(startIndex, 1);
83
- result.splice(endIndex, 0, removed);
84
-
85
- return result;
86
- };
87
-
88
- const grid = 8;
89
-
90
- const getItemStyle = (isDragging, draggableStyle) => ({
91
- // some basic styles to make the items look a bit nicer
92
- userSelect: 'none',
93
- padding: `4px`,
94
- margin: `4px`,
95
- // change background colour if dragging
96
-
97
- // styles we need to apply on draggables
98
- ...draggableStyle,
99
- });
100
-
101
- const getListStyle = (isDraggingOver) => ({
102
- background: isDraggingOver ? '#fff' : '#fff',
103
- display: 'flex',
104
- padding: grid,
105
- overflow: 'auto',
106
- });
107
-
108
- const filterLetters = (i) => {
109
- if (i >= 0 && i <= 25) {
110
- return String.fromCharCode(65 + i);
111
- } else {
112
- return undefined;
113
- }
114
- };
115
-
116
- // 抽象出创建对象的共通逻辑
117
- function createItem(idPrefix: string, index: number, title: string, name: string, format: { fa: string, t: string }): any {
118
- return {
119
- id: `${idPrefix}${index}`,
120
- content: title,
121
- code: name,
122
- "ct": format //单元格值格式
123
- };
124
- }
125
- // 定义[单元格值]常量以避免魔术字符串
126
- const FORMAT_NAME_GENERAL = "General"; //格式名称为自动格式
127
- const FORMAT_TYPE_STRING = "s"; //格式类型为数字类型
128
-
129
- class DataImport extends React.Component {
130
- constructor(props) {
131
- super(props);
132
- this.props.onRef(this);
133
-
134
- const format = { fa: FORMAT_NAME_GENERAL, t: FORMAT_TYPE_STRING };
135
- debugger
136
- if (props?.customerColumnsMapping?.length) {
137
- itemsTemp = props?.customerColumnsMapping?.map((item, index) => {
138
- return createItem('item-0', index, item.title, item.name, format);
139
- })||[]
140
- } else {
141
- itemsTemp = props?.columns?.map((item, index) => {
142
- if (!mapping.get(item))
143
- throw Error(
144
- `${item} is not in DataValidation component, please fix this error`,
145
- );
146
- return createItem('item-0', index, mapping.get(item), item, format);
147
- })||[];
148
- }
149
- console.log(itemsTemp, 'itemsTemp')
150
- luckysheet = window.luckysheet || window.top.luckysheet;
151
- this.state = {
152
- showErrorData: false,
153
- data: [],
154
- items: [...itemsTemp],
155
- resultData: [],
156
- errorListCheck: false,
157
- };
158
- }
159
-
160
- onDragEnd(result) {
161
- // dropped outside the list
162
- if (!result.destination) {
163
- return;
164
- }
165
-
166
- const items = reorder(
167
- this.state.items,
168
- result.source.index,
169
- result.destination.index,
170
- );
171
-
172
- this.setState({
173
- items,
174
- });
175
-
176
- itemsTemp = items;
177
-
178
- luckysheet.refresh();
179
- }
180
-
181
- getCount = () => {
182
- const { resultData } = this.state;
183
- return {
184
- total: resultData.length,
185
- error: resultData.filter((item) => !item.flag).length,
186
- };
187
- };
188
-
189
- setConfig = (data) => {
190
- const { items } = this.state;
191
- const { notValid } = this.props;
192
- return {
193
- container: 'luckysheet',
194
- showtoolbar: false,
195
- hook: {
196
- columnTitleCellRenderBefore: function (columnAbc, postion, ctx) {
197
- if (columnAbc.name) {
198
- let charCode = columnAbc.name.charCodeAt();
199
- let codeLen = (65+23 * (columnAbc.name.length-1))
200
- if (charCode - codeLen <= items.length) {
201
- columnAbc.name = itemsTemp[charCode - codeLen]
202
- ? itemsTemp[charCode - codeLen].content
203
- : (!notValid ? '校验结果' : '');
204
- } else {
205
- columnAbc.name = '';
206
- }
207
- }
208
- },
209
- cellRenderBefore: function (cell, postion, sheetFile, ctx) {
210
- if (cell) {
211
- cell.fs = 10;
212
-
213
-
214
- if (typeof cell.v === 'string') {
215
- cell.m = cell.v = cell.m.trim();
216
- }
217
- if (cell && cell.m && cell.m.indexOf('E+') !== -1) {
218
- cell.v = cell.v.toString()
219
- cell.m = cell.v
220
- }
221
- if (typeof cell.v === 'number') {
222
- cell.v = cell.m
223
- }
224
- }
225
- // console.log(postion);
226
- },
227
- cellAllRenderBefore: function (data, sheetFile, ctx) {
228
- sheetFile.config.borderInfo = [];
229
- // console.info(data,sheetFile,ctx)
230
- },
231
- },
232
- // showtoolbarConfig: {
233
- // undoRedo: true, //撤销重做,注意撤消重做是两个按钮,由这一个配置决定显示还是隐藏
234
- // paintFormat: false, //格式刷
235
- // currencyFormat: false, //货币格式
236
- // percentageFormat: false, //百分比格式
237
- // numberDecrease: false, // '减少小数位数'
238
- // numberIncrease: false, // '增加小数位数
239
- // moreFormats: false, // '更多格式'
240
- // font: true, // '字体'
241
- // fontSize: true, // '字号大小'
242
-
243
- // },
244
- data: [
245
- {
246
- name: 'Cell', //工作表名称
247
- color: '', //工作表颜色
248
- index: 0, //工作表索引
249
- status: 1, //激活状态
250
- order: 0, //工作表的下标
251
- hide: 0, //是否隐藏
252
- row: 36, //行数
253
- column: 18, //列数
254
- defaultRowHeight: 20, //自定义行高
255
- defaultColWidth: 120, //自定义列宽
256
- config: {},
257
- // celldata:
258
- // data && data.length !== 0 ? data : _.flattenDeep(Array.from({ length: 100 }).map((a, b) => Array.from({ length: 100 }).map((c, d) => ({
259
- // "r": b,
260
- // "c": d,
261
- // "v": { "ct": { "fa": "@", "t": "s" }, }
262
- // }))))
263
- // ,
264
- celldata:
265
- data && data.length !== 0 ? data : _.flattenDeep(Array.from({ length: 100 }).map((a, b) => Array.from({ length: 100 }).map((c, d) => ({
266
- "r": b,
267
- "c": d,
268
- "v": { "ct": { "fa": "@", "t": "s" }, }
269
- }))))
270
- ,
271
- scrollLeft: 0, //左右滚动条位置
272
- // "scrollTop": 315, //上下滚动条位置
273
- luckysheet_select_save: [], //选中的区域
274
- calcChain: [], //公式链
275
- isPivotTable: false, //是否数据透视表
276
- pivotTable: {}, //数据透视表设置
277
- filter_select: {}, //筛选范围
278
- filter: null, //筛选配置
279
- luckysheet_alternateformat_save: [], //交替颜色
280
- luckysheet_alternateformat_save_modelCustom: [], //自定义交替颜色
281
- luckysheet_conditionformat_save: {}, //条件格式
282
- frozen: {}, //冻结行列配置
283
- chart: [], //图表配置
284
- zoomRatio: 1, // 缩放比例
285
- image: [], //图片
286
- showGridLines: 1, //是否显示网格线
287
- dataVerification: {}, //数据验证配置
288
- luckysheet_alternateformat_save: [
289
- {
290
- cellrange: {
291
- //单元格范围
292
- row: [0, 1000],
293
- column: [0, 18],
294
- },
295
- format: {
296
- head: {
297
- //页眉颜色
298
- fc: '#6aa84f',
299
- bc: '#ffffff',
300
- },
301
- one: {
302
- //第一种颜色
303
- bc: '#ffffff',
304
- },
305
- two: {
306
- //第二种颜色
307
- bc: '#f2f4f5',
308
- },
309
- foot: {
310
- //页脚颜色
311
- fc: '#000',
312
- bc: '#a5efcc',
313
- },
314
- },
315
- hasRowHeader: false, //含有页眉
316
- hasRowFooter: false, //含有页脚
317
- },
318
- ], //交替颜色
319
- luckysheet_alternateformat_save_modelCustom: [
320
- {
321
- head: {
322
- //页眉颜色
323
- fc: '#6aa84f',
324
- bc: '#ffffff',
325
- },
326
- one: {
327
- //第一种颜色
328
- fc: '#000',
329
- bc: '#ffffff',
330
- },
331
- two: {
332
- //第二种颜色
333
- fc: '#000',
334
- bc: '#e5fbee',
335
- },
336
- foot: {
337
- //页脚颜色
338
- fc: '#000',
339
- bc: '#a5efcc',
340
- },
341
- },
342
- ], //自定义交替颜色
343
- },
344
- ],
345
- cellRightClickConfig: {
346
- copy: false, // 复制
347
- copyAs: false, // 复制为
348
- paste: false, // 粘贴
349
- insertRow: false, // 插入行
350
- insertColumn: false, // 插入列
351
- // deleteRow: false, // 删除选中行
352
- // deleteColumn: false, // 删除选中列
353
- deleteCell: false, // 删除单元格
354
- hideRow: false, // 隐藏选中行和显示选中行
355
- hideColumn: false, // 隐藏选中列和显示选中列
356
- rowHeight: false, // 行高
357
- columnWidth: false, // 列宽
358
- clear: false, // 清除内容
359
- matrix: false, // 矩阵操作选区
360
- sort: false, // 排序选区
361
- filter: false, // 筛选选区
362
- chart: false, // 图表生成
363
- image: false, // 插入图片
364
- link: false, // 插入链接
365
- data: false, // 数据验证
366
- cellFormat: false, // 设置单元格格式
367
- },
368
- showsheetbar: false,
369
- optionstate: false,
370
- showstatisticBarConfig: {
371
- count: false, // 计数栏
372
- view: false, // 打印视图
373
- zoom: false, // 缩放
374
- },
375
- column: 10, //列数
376
- columnHeaderHeight: 30,
377
- lang: 'zh',
378
- defaultFontSize: '10',
379
- frozen: {
380
- type: 'rangeBoth',
381
- range: { row_focus: 1, column_focus: 1 },
382
- },
383
- };
384
- };
385
-
386
- componentDidMount() {
387
- luckysheet.create(this.setConfig([]));
388
- }
389
-
390
- componentWillUnmount() {
391
- // luckysheet.create(this.setConfig([]));
392
- luckysheet.destroy();
393
- }
394
-
395
- getValidateData = () => {
396
- const { resultData } = this.state;
397
-
398
- return {
399
- successData: resultData
400
- .filter((item) => item.flag)
401
- .map(({ flag, checkResults, ...item }) => item),
402
- failData: resultData
403
- .filter((item) => !item.flag)
404
- .map(({ flag, checkResults, ...item }) => item),
405
- };
406
- };
407
-
408
- getData = () => {
409
- console.time();
410
- let sheetData = luckysheet.getSheetData();
411
- let data = JSON.parse(JSON.stringify(sheetData))
412
- .filter((item) => item[0])
413
- .map((item) => {
414
- let obj = {};
415
-
416
- item.slice(0, itemsTemp.length).map((innerItem, index) => {
417
- obj[this.state.items[index].code] = innerItem && (innerItem.v === innerItem.m ? innerItem.m : innerItem.v);
418
- });
419
-
420
- return obj;
421
- });
422
-
423
- return data;
424
- };
425
-
426
- resetData = () => {
427
- const { validDataUrl, validDataParams, updateData, columns, isBrandAuth, isCheckStockNum = true, customerColumnsMapping } = this.props;
428
- const resultData = this.getData().filter(d => {
429
- return _.compact(Object.values(d)).length
430
- })
431
- const resultColumns = customerColumnsMapping?.length? customerColumnsMapping?.filter((c: any) => !c?.name)?.map((c: any) => c.name) : columns
432
-
433
- // 处理业务参数
434
- let otherParams={}
435
- if(isBrandAuth){
436
- otherParams = { brandAuth: 'ctl-withAuth' }
437
- }
438
-
439
- request
440
- .post(validDataUrl, {
441
- ...otherParams,
442
- ...validDataParams,
443
- columns: resultColumns,
444
- data: resultData,
445
- checkStockNum: isCheckStockNum
446
- })
447
- .then((result) => {
448
- result = result.data;
449
- if (judgeIsRequestError(result)) {
450
- message.error(result.msg);
451
- return;
452
- }
453
- const { items } = this.state;
454
- let validIndex = items.length;
455
- let res = result.data;
456
-
457
- let sheetData = luckysheet.getSheetData();
458
-
459
- sheetData.map((item, index) => {
460
- if (!res[index]) return item;
461
-
462
- const changeVMIndex = resultColumns?.findIndex(i => i === 'skuCode');
463
- if(resultColumns?.find(i => i === 'skuCode') && item[changeVMIndex].v !== res[index].skuCode) {
464
- item[changeVMIndex].v = res[index].skuCode;
465
- item[changeVMIndex].m = res[index].skuCode;
466
- }
467
-
468
- if (res[index].flag) {
469
- item[validIndex] = {
470
- ...item[validIndex],
471
- v: '通过',
472
- m: '通过',
473
- fc: 'green', //字体颜色为 "#990000"
474
- };
475
- } else {
476
- item[validIndex] = {
477
- ...item[validIndex],
478
- v: res[index].checkResults,
479
- m: res[index].checkResults,
480
- fc: 'red', //字体颜色为 "#990000"
481
- };
482
- }
483
-
484
- item[validIndex].ct = { fa: 'General', t: 'g' };
485
- });
486
- // sheetData.map((item, index) => {
487
- // luckysheet.setCellValue(index + 1, 4, 345)
488
- // })
489
-
490
- luckysheet.create(
491
- this.setConfig(luckysheet.transToCellData(sheetData)),
492
- );
493
- this.setState({
494
- data: luckysheet.transToCellData(sheetData),
495
- errorListCheck: false,
496
- resultData: res,
497
- });
498
-
499
- console.log(setExportData);
500
- setExportData([123123]);
501
- })
502
- .catch((err: any) => { });
503
- };
504
-
505
- filterData = (type: string) => {
506
- const { showErrorData, data, resultData } = this.state;
507
- let sheetData = luckysheet.transToData(data).filter((item, index) => {
508
- if (type === 'all') {
509
- return false;
510
- }
511
- if (type === 'error') {
512
- return item[itemsTemp.length] && item[itemsTemp.length].v === '通过';
513
- }
514
- });
515
-
516
- luckysheet.create(this.setConfig(luckysheet.transToCellData(sheetData)));
517
- this.setState({
518
- data: luckysheet.transToCellData(sheetData),
519
- errorListCheck: false,
520
- resultData: type === 'all' ? [] : resultData.filter((item) => item.flag),
521
- });
522
- };
523
-
524
- toggleData = () => {
525
- const { showErrorData, data } = this.state;
526
-
527
- if (showErrorData) {
528
- luckysheet.create(this.setConfig(data));
529
- } else {
530
- let sheetData = luckysheet.getSheetData();
531
- sheetData = sheetData.filter((item, index) => {
532
- return !item[itemsTemp.length] || item[itemsTemp.length].v !== '通过';
533
- });
534
-
535
- luckysheet.create(this.setConfig(luckysheet.transToCellData(sheetData)));
536
- }
537
-
538
- this.setState({
539
- showErrorData: !showErrorData,
540
- });
541
- };
542
-
543
- onChange = (e) => {
544
- this.setState({
545
- radioValue: e.target.value,
546
- });
547
- this.toggleData();
548
- };
549
-
550
- errorChange = (e: any) => {
551
- this.toggleData();
552
- this.setState({
553
- errorListCheck: e.target.checked,
554
- });
555
- };
556
-
557
- menuList = (
558
- <Menu>
559
- <Menu.Item key="1" className="sheet_table-menu_item_text">
560
- <a onClick={() => this.filterData('all')}>清空全部数据</a>
561
- </Menu.Item>
562
- <Menu.Divider />
563
- {!this.props.notValid && <Menu.Item key="2" className="sheet_table-menu_item_text">
564
- <a onClick={() => this.filterData('error')}>仅清空错误数据</a>
565
- </Menu.Item>}
566
- </Menu>
567
- );
568
-
569
- leftMenu = (
570
- <Menu>
571
- <Menu.Item key="3" className="sheet_table-menu_item_text">
572
- <span className="sheet_table_text">请拖动字段来对应列</span>
573
- </Menu.Item>
574
- <Menu.Divider />
575
- <div>
576
- <DragDropContext onDragEnd={(e) => this.onDragEnd(e)}>
577
- <Droppable droppableId="droppable" direction="vertical">
578
- {(provided, snapshot) => (
579
- <div
580
- ref={provided.innerRef}
581
- style={{
582
- ...getListStyle(snapshot.isDraggingOver),
583
- flexDirection: 'column',
584
- }}
585
- {...provided.droppableProps}
586
- >
587
- {this.state.items.map((item, index) => (
588
- <Draggable key={item.id} draggableId={item.id} index={index}>
589
- {(provided, snapshot) => (
590
- <div
591
- ref={provided.innerRef}
592
- {...provided.draggableProps}
593
- {...provided.dragHandleProps}
594
- style={getItemStyle(
595
- snapshot.isDragging,
596
- provided.draggableProps.style,
597
- )}
598
- >
599
- <Space>
600
- <span>{filterLetters(index)} 列 </span>
601
- <Space className="sheet_table_dnd_text">
602
- <UnorderedListOutlined />
603
- {item.content}
604
- </Space>
605
- </Space>
606
- </div>
607
- )}
608
- </Draggable>
609
- ))}
610
- {provided.placeholder}
611
- </div>
612
- )}
613
- </Droppable>
614
- </DragDropContext>
615
- </div>
616
- </Menu>
617
- );
618
-
619
- render() {
620
- const { errorListCheck } = this.state;
621
- const { title, notValid } = this.props;
622
-
623
- let totalSummary = this.getCount();
624
-
625
- const luckyCss = {
626
- margin: '0px',
627
- padding: '0px',
628
- position: 'absolute',
629
- width: '100%',
630
- height: '100%',
631
- left: '0px',
632
- top: '0px',
633
- };
634
- return (
635
- <>
636
- <div className="sheet_table_top">
637
- <Space>
638
- <span>排序列</span>
639
- <Dropdown
640
- trigger={['click']}
641
- overlay={this.leftMenu}
642
- placement="bottomLeft"
643
- >
644
- <a>
645
- <ProfileTwoTone />
646
- </a>
647
- </Dropdown>
648
- <Tooltip
649
- title={
650
- <>
651
- <span>使用指南:</span>
652
- <br></br>
653
- <span>
654
- 1、拖动数据项,以适配源数据的顺序,如您Excel中数据排序依次为编码、价格和数量,则您也可以将数据项的顺序调整为一致
655
- </span>
656
- <br></br>
657
- <span>2、复制文件数据(多列一起),在文本框内进行粘贴</span>
658
- <br></br>
659
- <span>
660
- 3、点击识别按钮进行数据校验,如全部正确,则点击录入按钮可录入数据,如存在错误数据,则需修改后再进行录入
661
- </span>
662
- </>
663
- }
664
- >
665
- <ExclamationCircleOutlined />
666
- </Tooltip>
667
- </Space>
668
- <Space>
669
- <Dropdown
670
- trigger={['click']}
671
- overlay={this.menuList}
672
- placement="bottomRight"
673
- >
674
- <Button>
675
- 清空
676
- <DownOutlined />
677
- </Button>
678
- </Dropdown>
679
-
680
- {!notValid && <Button type="primary" onClick={this.resetData}>
681
- 识别
682
- </Button>}
683
- </Space>
684
- </div>
685
-
686
- <div style={{ position: 'relative', height: '400px' }}>
687
- <div id="luckysheet" style={luckyCss}></div>
688
- </div>
689
- {!this.props.notValid && <div className="sheet_table_footer">
690
- <span className="sheet_table_footer_l">
691
- 共 {totalSummary.total} 条数据{!notValid && `, 其中错误 ${totalSummary.error} 项`}
692
- </span>
693
- {!notValid && <Space className="sheet_table_footer_r">
694
- <Checkbox
695
- checked={errorListCheck}
696
- onClick={this.errorChange}
697
- ></Checkbox>
698
- 仅展示错误数据
699
- </Space>}
700
- </div>}
701
- </>
702
- );
703
- }
704
- }
705
-
706
- export default DataImport;
1
+ /*
2
+ * @Description:
3
+ * @Author: rodchen
4
+ * @Date: 2021-12-01 10:52:08
5
+ * @LastEditTime: 2024-07-11 19:20:39
6
+ * @LastEditors: rodchen rodchen_king@outlook.com
7
+ */
8
+ // @ts-nocheck
9
+ import React from 'react';
10
+ import {
11
+ Button,
12
+ Card,
13
+ Radio,
14
+ Checkbox,
15
+ Space,
16
+ Dropdown,
17
+ Menu,
18
+ Tooltip,
19
+ message,
20
+ Upload
21
+ } from 'antd';
22
+ import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
23
+ import {
24
+ ExclamationCircleOutlined,
25
+ DownOutlined,
26
+ ProfileTwoTone,
27
+ UnorderedListOutlined,
28
+ } from '@ant-design/icons';
29
+ import request from '@/utils/request';
30
+ import './index.less';
31
+ import _ from "lodash"
32
+ import { judgeIsRequestError } from '@/utils/requestUtils';
33
+ import { readerXlsxToList } from '@/utils/xlsxUtil';
34
+
35
+ // const luckysheet = window.luckysheet;
36
+
37
+ let itemsTemp = [];
38
+ let luckysheet;
39
+
40
+ // const mapping = [
41
+ // { "key": "skuCode", "name": "SKU编码", "rule": "skuCode" },
42
+ // { "key": "quantity", "name": "数量", "rule": "quantity" },
43
+ // { "key": "price", "name": "单价", "rule": "price" }
44
+ // ]
45
+
46
+ const mapping = new Map([
47
+ ['skuCode', 'SKU编码'],
48
+ ['quantity', '数量'],
49
+ ['price', '单价'],
50
+ ['regionCode', '库区'],
51
+ ['checkQuantity', '实盘数量'],
52
+ ['shareRatio', '共享比例'],
53
+ ['lotNumberCode', '批号'],
54
+ ['warehouseCode', '仓库编码'],
55
+ ['regionCode', '库区'],
56
+ ['locationCode', '货位'],
57
+ ['rowNumber', '货位排数'],
58
+ ['layerNumber', '货位层数'],
59
+ ['gridNumber', '货位格号'],
60
+ ['oldUniqueCode', '原始唯一码'],
61
+ ['newUniqueCode', '新唯一码'],
62
+ ['relationRecordCode', '单据编码'],
63
+ ['remark', '备注'],
64
+ ['externalCode', 'JDE商品编码'],
65
+ ['realWarehouseCode', '仓库编码'],
66
+ ['syncRate', '按百分比'],
67
+ ['assignQuantity', '按指定数量'],
68
+ ['retainQuantity', ' 按保留数量'],
69
+ ['priority', ' 优先级'],
70
+ ['stockBizTypeCode', ' 库存类型'],
71
+ ]);
72
+
73
+ // for dnd
74
+ // fake data generator
75
+ const getItems = (count) =>
76
+ Array.from({ length: count }, (v, k) => k).map((k) => ({
77
+ id: `item-${k}`,
78
+ content: `item ${k}`,
79
+ }));
80
+
81
+ // a little function to help us with reordering the result
82
+ const reorder = (list, startIndex, endIndex) => {
83
+ const result = Array.from(list);
84
+ const [removed] = result.splice(startIndex, 1);
85
+ result.splice(endIndex, 0, removed);
86
+
87
+ return result;
88
+ };
89
+
90
+ const grid = 8;
91
+
92
+ const getItemStyle = (isDragging, draggableStyle) => ({
93
+ // some basic styles to make the items look a bit nicer
94
+ userSelect: 'none',
95
+ padding: `4px`,
96
+ margin: `4px`,
97
+ // change background colour if dragging
98
+
99
+ // styles we need to apply on draggables
100
+ ...draggableStyle,
101
+ });
102
+
103
+ const getListStyle = (isDraggingOver) => ({
104
+ background: isDraggingOver ? '#fff' : '#fff',
105
+ display: 'flex',
106
+ padding: grid,
107
+ overflow: 'auto',
108
+ });
109
+
110
+ const filterLetters = (i) => {
111
+ if (i >= 0 && i <= 25) {
112
+ return String.fromCharCode(65 + i);
113
+ } else {
114
+ return undefined;
115
+ }
116
+ };
117
+
118
+ // 抽象出创建对象的共通逻辑
119
+ function createItem(idPrefix: string, index: number, title: string, name: string, format: { fa: string, t: string }): any {
120
+ return {
121
+ id: `${idPrefix}${index}`,
122
+ content: title,
123
+ code: name,
124
+ "ct": format //单元格值格式
125
+ };
126
+ }
127
+ // 定义[单元格值]常量以避免魔术字符串
128
+ const FORMAT_NAME_GENERAL = "General"; //格式名称为自动格式
129
+ const FORMAT_TYPE_STRING = "s"; //格式类型为数字类型
130
+
131
+ class DataImport extends React.Component {
132
+ constructor(props) {
133
+ super(props);
134
+ this.props.onRef(this);
135
+
136
+ const format = { fa: FORMAT_NAME_GENERAL, t: FORMAT_TYPE_STRING };
137
+ if (props?.customerColumnsMapping?.length) {
138
+ itemsTemp = props?.customerColumnsMapping?.map((item, index) => {
139
+ return createItem('item-0', index, item.title, item.name, format);
140
+ })||[]
141
+ } else {
142
+ itemsTemp = props?.columns?.map((item, index) => {
143
+ if (!mapping.get(item))
144
+ throw Error(
145
+ `${item} is not in DataValidation component, please fix this error`,
146
+ );
147
+ return createItem('item-0', index, mapping.get(item), item, format);
148
+ })||[];
149
+ }
150
+ luckysheet = window.luckysheet || window.top.luckysheet;
151
+ this.state = {
152
+ showErrorData: false,
153
+ data: [],
154
+ items: [...itemsTemp],
155
+ resultData: [],
156
+ errorListCheck: false,
157
+ };
158
+ }
159
+
160
+ onDragEnd(result) {
161
+ // dropped outside the list
162
+ if (!result.destination) {
163
+ return;
164
+ }
165
+
166
+ const items = reorder(
167
+ this.state.items,
168
+ result.source.index,
169
+ result.destination.index,
170
+ );
171
+
172
+ this.setState({
173
+ items,
174
+ });
175
+
176
+ itemsTemp = items;
177
+
178
+ luckysheet.refresh();
179
+ }
180
+
181
+ getCount = () => {
182
+ const { resultData } = this.state;
183
+ return {
184
+ total: resultData.length,
185
+ error: resultData.filter((item) => !item.flag).length,
186
+ };
187
+ };
188
+
189
+ setConfig = (data) => {
190
+ const { items } = this.state;
191
+ const { notValid } = this.props;
192
+ return {
193
+ container: 'luckysheet',
194
+ showtoolbar: false,
195
+ hook: {
196
+ columnTitleCellRenderBefore: function (columnAbc, postion, ctx) {
197
+ if (columnAbc.name) {
198
+ let charCode = columnAbc.name.charCodeAt();
199
+ let codeLen = (65+23 * (columnAbc.name.length-1))
200
+ if (charCode - codeLen <= items.length) {
201
+ columnAbc.name = itemsTemp[charCode - codeLen]
202
+ ? itemsTemp[charCode - codeLen].content
203
+ : (!notValid ? '校验结果' : '');
204
+ } else {
205
+ columnAbc.name = '';
206
+ }
207
+ }
208
+ },
209
+ cellRenderBefore: function (cell, postion, sheetFile, ctx) {
210
+ if (cell) {
211
+ cell.fs = 10;
212
+
213
+
214
+ if (typeof cell.v === 'string') {
215
+ cell.m = cell.v = cell.m.trim();
216
+ }
217
+ if (cell && cell.m && cell.m.indexOf('E+') !== -1) {
218
+ cell.v = cell.v.toString()
219
+ cell.m = cell.v
220
+ }
221
+ if (typeof cell.v === 'number') {
222
+ cell.v = cell.m
223
+ }
224
+ }
225
+ // console.log(postion);
226
+ },
227
+ cellAllRenderBefore: function (data, sheetFile, ctx) {
228
+ sheetFile.config.borderInfo = [];
229
+ // console.info(data,sheetFile,ctx)
230
+ },
231
+ },
232
+ // showtoolbarConfig: {
233
+ // undoRedo: true, //撤销重做,注意撤消重做是两个按钮,由这一个配置决定显示还是隐藏
234
+ // paintFormat: false, //格式刷
235
+ // currencyFormat: false, //货币格式
236
+ // percentageFormat: false, //百分比格式
237
+ // numberDecrease: false, // '减少小数位数'
238
+ // numberIncrease: false, // '增加小数位数
239
+ // moreFormats: false, // '更多格式'
240
+ // font: true, // '字体'
241
+ // fontSize: true, // '字号大小'
242
+
243
+ // },
244
+ data: [
245
+ {
246
+ name: 'Cell', //工作表名称
247
+ color: '', //工作表颜色
248
+ index: 0, //工作表索引
249
+ status: 1, //激活状态
250
+ order: 0, //工作表的下标
251
+ hide: 0, //是否隐藏
252
+ row: 36, //行数
253
+ column: 18, //列数
254
+ defaultRowHeight: 20, //自定义行高
255
+ defaultColWidth: 120, //自定义列宽
256
+ config: {},
257
+ celldata:
258
+ data && data.length !== 0 ? data : _.flattenDeep(Array.from({ length: 100 }).map((a, b) => Array.from({ length: 100 }).map((c, d) => ({
259
+ "r": b,
260
+ "c": d,
261
+ "v": { "ct": { "fa": "@", "t": "s" }, }
262
+ }))))
263
+ ,
264
+ scrollLeft: 0, //左右滚动条位置
265
+ // "scrollTop": 315, //上下滚动条位置
266
+ luckysheet_select_save: [], //选中的区域
267
+ calcChain: [], //公式链
268
+ isPivotTable: false, //是否数据透视表
269
+ pivotTable: {}, //数据透视表设置
270
+ filter_select: {}, //筛选范围
271
+ filter: null, //筛选配置
272
+ luckysheet_alternateformat_save: [], //交替颜色
273
+ luckysheet_alternateformat_save_modelCustom: [], //自定义交替颜色
274
+ luckysheet_conditionformat_save: {}, //条件格式
275
+ frozen: {}, //冻结行列配置
276
+ chart: [], //图表配置
277
+ zoomRatio: 1, // 缩放比例
278
+ image: [], //图片
279
+ showGridLines: 1, //是否显示网格线
280
+ dataVerification: {}, //数据验证配置
281
+ luckysheet_alternateformat_save: [
282
+ {
283
+ cellrange: {
284
+ //单元格范围
285
+ row: [0, 1000],
286
+ column: [0, 18],
287
+ },
288
+ format: {
289
+ head: {
290
+ //页眉颜色
291
+ fc: '#6aa84f',
292
+ bc: '#ffffff',
293
+ },
294
+ one: {
295
+ //第一种颜色
296
+ bc: '#ffffff',
297
+ },
298
+ two: {
299
+ //第二种颜色
300
+ bc: '#f2f4f5',
301
+ },
302
+ foot: {
303
+ //页脚颜色
304
+ fc: '#000',
305
+ bc: '#a5efcc',
306
+ },
307
+ },
308
+ hasRowHeader: false, //含有页眉
309
+ hasRowFooter: false, //含有页脚
310
+ },
311
+ ], //交替颜色
312
+ luckysheet_alternateformat_save_modelCustom: [
313
+ {
314
+ head: {
315
+ //页眉颜色
316
+ fc: '#6aa84f',
317
+ bc: '#ffffff',
318
+ },
319
+ one: {
320
+ //第一种颜色
321
+ fc: '#000',
322
+ bc: '#ffffff',
323
+ },
324
+ two: {
325
+ //第二种颜色
326
+ fc: '#000',
327
+ bc: '#e5fbee',
328
+ },
329
+ foot: {
330
+ //页脚颜色
331
+ fc: '#000',
332
+ bc: '#a5efcc',
333
+ },
334
+ },
335
+ ], //自定义交替颜色
336
+ },
337
+ ],
338
+ cellRightClickConfig: {
339
+ copy: false, // 复制
340
+ copyAs: false, // 复制为
341
+ paste: false, // 粘贴
342
+ insertRow: false, // 插入行
343
+ insertColumn: false, // 插入列
344
+ // deleteRow: false, // 删除选中行
345
+ // deleteColumn: false, // 删除选中列
346
+ deleteCell: false, // 删除单元格
347
+ hideRow: false, // 隐藏选中行和显示选中行
348
+ hideColumn: false, // 隐藏选中列和显示选中列
349
+ rowHeight: false, // 行高
350
+ columnWidth: false, // 列宽
351
+ clear: false, // 清除内容
352
+ matrix: false, // 矩阵操作选区
353
+ sort: false, // 排序选区
354
+ filter: false, // 筛选选区
355
+ chart: false, // 图表生成
356
+ image: false, // 插入图片
357
+ link: false, // 插入链接
358
+ data: false, // 数据验证
359
+ cellFormat: false, // 设置单元格格式
360
+ },
361
+ showsheetbar: false,
362
+ optionstate: false,
363
+ showstatisticBarConfig: {
364
+ count: false, // 计数栏
365
+ view: false, // 打印视图
366
+ zoom: false, // 缩放
367
+ },
368
+ column: 10, //列数
369
+ columnHeaderHeight: 30,
370
+ lang: 'zh',
371
+ defaultFontSize: '10',
372
+ frozen: {
373
+ type: 'rangeBoth',
374
+ range: { row_focus: 1, column_focus: 1 },
375
+ },
376
+ };
377
+ };
378
+
379
+ componentDidMount() {
380
+ luckysheet.create(this.setConfig([]));
381
+ }
382
+
383
+ componentWillUnmount() {
384
+ // luckysheet.create(this.setConfig([]));
385
+ luckysheet.destroy();
386
+ }
387
+
388
+ getValidateData = () => {
389
+ const { resultData } = this.state;
390
+
391
+ return {
392
+ successData: resultData
393
+ .filter((item) => item.flag)
394
+ .map(({ flag, checkResults, ...item }) => item),
395
+ failData: resultData
396
+ .filter((item) => !item.flag)
397
+ .map(({ flag, checkResults, ...item }) => item),
398
+ };
399
+ };
400
+
401
+ getData = () => {
402
+ console.time();
403
+ let sheetData = luckysheet.getSheetData();
404
+ let data = JSON.parse(JSON.stringify(sheetData))
405
+ .filter((item) => item[0])
406
+ .map((item) => {
407
+ let obj = {};
408
+
409
+ item.slice(0, itemsTemp.length).map((innerItem, index) => {
410
+ obj[this.state.items[index].code] = innerItem && (innerItem.v === innerItem.m ? innerItem.m : innerItem.v);
411
+ });
412
+
413
+ return obj;
414
+ });
415
+
416
+ // 解决 没有输入的行不要录入进去
417
+ return data.filter(d => _.compact(Object.values(d)).length);
418
+ };
419
+
420
+ resetData = () => {
421
+ const { validDataUrl, validDataParams, updateData, columns, isBrandAuth, isCheckStockNum = true, customerColumnsMapping } = this.props;
422
+ const resultData = this.getData().filter(d => {
423
+ return _.compact(Object.values(d)).length
424
+ })
425
+ const resultColumns = customerColumnsMapping?.length? customerColumnsMapping?.filter((c: any) => !c?.name)?.map((c: any) => c.name) : columns
426
+
427
+ // 处理业务参数
428
+ let otherParams={}
429
+ if(isBrandAuth){
430
+ otherParams = { brandAuth: 'ctl-withAuth' }
431
+ }
432
+
433
+ request
434
+ .post(validDataUrl, {
435
+ ...otherParams,
436
+ ...validDataParams,
437
+ columns: resultColumns,
438
+ data: resultData,
439
+ checkStockNum: isCheckStockNum
440
+ })
441
+ .then((result) => {
442
+ result = result.data;
443
+ if (judgeIsRequestError(result)) {
444
+ message.error(result.msg);
445
+ return;
446
+ }
447
+ const { items } = this.state;
448
+ let validIndex = items.length;
449
+ let res = result.data;
450
+
451
+ let sheetData = luckysheet.getSheetData();
452
+
453
+ sheetData.map((item, index) => {
454
+ if (!res[index]) return item;
455
+
456
+ const changeVMIndex = resultColumns?.findIndex(i => i === 'skuCode');
457
+ if(resultColumns?.find(i => i === 'skuCode') && item[changeVMIndex].v !== res[index].skuCode) {
458
+ item[changeVMIndex].v = res[index].skuCode;
459
+ item[changeVMIndex].m = res[index].skuCode;
460
+ }
461
+
462
+ if (res[index].flag) {
463
+ item[validIndex] = {
464
+ ...item[validIndex],
465
+ v: '通过',
466
+ m: '通过',
467
+ fc: 'green', //字体颜色为 "#990000"
468
+ };
469
+ } else {
470
+ item[validIndex] = {
471
+ ...item[validIndex],
472
+ v: res[index].checkResults,
473
+ m: res[index].checkResults,
474
+ fc: 'red', //字体颜色为 "#990000"
475
+ };
476
+ }
477
+
478
+ item[validIndex].ct = { fa: 'General', t: 'g' };
479
+ });
480
+ // sheetData.map((item, index) => {
481
+ // luckysheet.setCellValue(index + 1, 4, 345)
482
+ // })
483
+
484
+ luckysheet.create(
485
+ this.setConfig(luckysheet.transToCellData(sheetData)),
486
+ );
487
+ this.setState({
488
+ data: luckysheet.transToCellData(sheetData),
489
+ errorListCheck: false,
490
+ resultData: res,
491
+ });
492
+
493
+ console.log(setExportData);
494
+ setExportData([123123]);
495
+ })
496
+ .catch((err:any) => { });
497
+ };
498
+
499
+ filterData = (type: string) => {
500
+ const { showErrorData, data, resultData } = this.state;
501
+ let sheetData = luckysheet.transToData(data).filter((item, index) => {
502
+ if (type === 'all') {
503
+ return false;
504
+ }
505
+ if (type === 'error') {
506
+ return item[itemsTemp.length] && item[itemsTemp.length].v === '通过';
507
+ }
508
+ });
509
+
510
+ luckysheet.create(this.setConfig(luckysheet.transToCellData(sheetData)));
511
+ this.setState({
512
+ data: luckysheet.transToCellData(sheetData),
513
+ errorListCheck: false,
514
+ resultData: type === 'all' ? [] : resultData.filter((item) => item.flag),
515
+ });
516
+ };
517
+
518
+ toggleData = () => {
519
+ const { showErrorData, data } = this.state;
520
+
521
+ if (showErrorData) {
522
+ luckysheet.create(this.setConfig(data));
523
+ } else {
524
+ let sheetData = luckysheet.getSheetData();
525
+ sheetData = sheetData.filter((item, index) => {
526
+ return !item[itemsTemp.length] || item[itemsTemp.length].v !== '通过';
527
+ });
528
+
529
+ luckysheet.create(this.setConfig(luckysheet.transToCellData(sheetData)));
530
+ }
531
+
532
+ this.setState({
533
+ showErrorData: !showErrorData,
534
+ });
535
+ };
536
+
537
+ onChange = (e) => {
538
+ this.setState({
539
+ radioValue: e.target.value,
540
+ });
541
+ this.toggleData();
542
+ };
543
+
544
+ errorChange = (e: any) => {
545
+ this.toggleData();
546
+ this.setState({
547
+ errorListCheck: e.target.checked,
548
+ });
549
+ };
550
+
551
+ menuList = (
552
+ <Menu>
553
+ <Menu.Item key="1" className="sheet_table-menu_item_text">
554
+ <a onClick={() => this.filterData('all')}>清空全部数据</a>
555
+ </Menu.Item>
556
+ <Menu.Divider />
557
+ {!this.props.notValid && <Menu.Item key="2" className="sheet_table-menu_item_text">
558
+ <a onClick={() => this.filterData('error')}>仅清空错误数据</a>
559
+ </Menu.Item>}
560
+ </Menu>
561
+ );
562
+
563
+ leftMenu = (
564
+ <Menu>
565
+ <Menu.Item key="3" className="sheet_table-menu_item_text">
566
+ <span className="sheet_table_text">请拖动字段来对应列</span>
567
+ </Menu.Item>
568
+ <Menu.Divider />
569
+ <div>
570
+ <DragDropContext onDragEnd={(e) => this.onDragEnd(e)}>
571
+ <Droppable droppableId="droppable" direction="vertical">
572
+ {(provided, snapshot) => (
573
+ <div
574
+ ref={provided.innerRef}
575
+ style={{
576
+ ...getListStyle(snapshot.isDraggingOver),
577
+ flexDirection: 'column',
578
+ }}
579
+ {...provided.droppableProps}
580
+ >
581
+ {this.state.items.map((item, index) => (
582
+ <Draggable key={item.id} draggableId={item.id} index={index}>
583
+ {(provided, snapshot) => (
584
+ <div
585
+ ref={provided.innerRef}
586
+ {...provided.draggableProps}
587
+ {...provided.dragHandleProps}
588
+ style={getItemStyle(
589
+ snapshot.isDragging,
590
+ provided.draggableProps.style,
591
+ )}
592
+ >
593
+ <Space>
594
+ <span>{filterLetters(index)} 列 </span>
595
+ <Space className="sheet_table_dnd_text">
596
+ <UnorderedListOutlined />
597
+ {item.content}
598
+ </Space>
599
+ </Space>
600
+ </div>
601
+ )}
602
+ </Draggable>
603
+ ))}
604
+ {provided.placeholder}
605
+ </div>
606
+ )}
607
+ </Droppable>
608
+ </DragDropContext>
609
+ </div>
610
+ </Menu>
611
+ );
612
+
613
+ getSheetMap = () => {
614
+ const { customerColumnsMapping, columns } = this.props;
615
+ const sheetData = customerColumnsMapping || columns.map(s => ({ title: mapping.get(s), name: s })) || [];
616
+ const sheetMap = {};
617
+ sheetData.forEach((item, index) => {
618
+ sheetMap[item.name] = item?.title;
619
+ });
620
+ return sheetMap;
621
+ };
622
+
623
+ importExcelToLuckySheet = (resultData) => {
624
+ const res = resultData || [];
625
+ let sheetData = luckysheet.getSheetData();
626
+
627
+ sheetData.map((item, index) => {
628
+ if (!res?.[index]) return item;
629
+
630
+ const rowItem = res[index];
631
+ item?.forEach((element,colIndex) => {
632
+ const colKey = (Object.keys(rowItem)||[])?.[colIndex];
633
+ if(!rowItem?.[colKey]) return element;
634
+
635
+ element.m = rowItem[colKey];
636
+ element.v = rowItem[colKey];
637
+ });
638
+ });
639
+
640
+ luckysheet.create(this.setConfig(luckysheet.transToCellData(sheetData)));
641
+ this.setState({
642
+ data: luckysheet.transToCellData(sheetData),
643
+ errorListCheck: false,
644
+ resultData,
645
+ });
646
+ }
647
+
648
+ render() {
649
+ const { errorListCheck } = this.state;
650
+ const { title, notValid, notExcelImport, excelImportConfig } = this.props;
651
+ const { size, accept, suffixRule } = excelImportConfig || {}
652
+
653
+ let totalSummary = this.getCount();
654
+ const sheetMap = this.getSheetMap();
655
+ const callBackFun = this.importExcelToLuckySheet;
656
+
657
+ const uploadProps = {
658
+ name: 'file',
659
+ action: '',
660
+ headers: {},
661
+ accept: accept || ['.xlsx', '.xls'],
662
+ showUploadList: false,
663
+ beforeUpload:(file: any) => {
664
+ // 文件校验
665
+ const extName = file.name
666
+ .substring(file.name.lastIndexOf('.'))
667
+ .toLowerCase();
668
+ if (size && file.size > size * 1024 * 1024) {
669
+ message.error(`上传文件不能超过${size}M!`);
670
+ return Upload.LIST_IGNORE;
671
+ }
672
+ if (suffixRule && suffixRule.length > 0 && !suffixRule.includes(extName)) {
673
+ message.error(`请上传${suffixRule.toString()}等格式的文件!`);
674
+ return Upload.LIST_IGNORE;
675
+ }
676
+ return true;
677
+ },
678
+ onChange(info) {
679
+ if(!(sheetMap && Object.keys(sheetMap)?.length)) return;
680
+ if (info.file.status !== 'uploading') {
681
+ const { file, fileList } = info||{};
682
+ readerXlsxToList(file, fileList, null, null,{
683
+ callback: (excelData: any) => {
684
+ callBackFun(excelData)
685
+ },
686
+ sheetMap,
687
+ })
688
+ }
689
+ if (info.file.status === 'done') {
690
+ message.success(`${info.file.name} 已上传,请检验数据无误后保存`);
691
+ } else if (info.file.status === 'error') {
692
+ message.error(`${info.file.name} 上传失败.请重新上传`);
693
+ }
694
+ },
695
+ }
696
+
697
+ const luckyCss = {
698
+ margin: '0px',
699
+ padding: '0px',
700
+ position: 'absolute',
701
+ width: '100%',
702
+ height: '100%',
703
+ left: '0px',
704
+ top: '0px',
705
+ };
706
+ return (
707
+ <>
708
+ <div className="sheet_table_top">
709
+ <Space>
710
+ <span>排序列</span>
711
+ <Dropdown
712
+ trigger={['click']}
713
+ overlay={this.leftMenu}
714
+ placement="bottomLeft"
715
+ >
716
+ <a>
717
+ <ProfileTwoTone />
718
+ </a>
719
+ </Dropdown>
720
+ <Tooltip
721
+ title={
722
+ <>
723
+ <span>使用指南:</span>
724
+ <br></br>
725
+ <span>
726
+ 1、拖动数据项,以适配源数据的顺序,如您Excel中数据排序依次为编码、价格和数量,则您也可以将数据项的顺序调整为一致
727
+ </span>
728
+ <br></br>
729
+ <span>2、复制文件数据(多列一起),在文本框内进行粘贴</span>
730
+ <br></br>
731
+ <span>
732
+ 3、点击识别按钮进行数据校验,如全部正确,则点击录入按钮可录入数据,如存在错误数据,则需修改后再进行录入
733
+ </span>
734
+ </>
735
+ }
736
+ >
737
+ <ExclamationCircleOutlined />
738
+ </Tooltip>
739
+ </Space>
740
+ <Space>
741
+ {!notExcelImport && (
742
+ <Upload {...uploadProps}>
743
+ <Button>导入</Button>
744
+ </Upload>
745
+ )}
746
+ <Dropdown
747
+ trigger={['click']}
748
+ overlay={this.menuList}
749
+ placement="bottomRight"
750
+ >
751
+ <Button>
752
+ 清空
753
+ <DownOutlined />
754
+ </Button>
755
+ </Dropdown>
756
+
757
+ {!notValid && <Button type="primary" onClick={this.resetData}>
758
+ 识别
759
+ </Button>}
760
+ </Space>
761
+ </div>
762
+
763
+ <div style={{ position: 'relative', height: '400px' }}>
764
+ <div id="luckysheet" style={luckyCss}></div>
765
+ </div>
766
+ {!this.props.notValid && <div className="sheet_table_footer">
767
+ <span className="sheet_table_footer_l">
768
+ 共 {totalSummary.total} 条数据{!notValid && `, 其中错误 ${totalSummary.error} 项`}
769
+ </span>
770
+ {!notValid && <Space className="sheet_table_footer_r">
771
+ <Checkbox
772
+ checked={errorListCheck}
773
+ onClick={this.errorChange}
774
+ ></Checkbox>
775
+ 仅展示错误数据
776
+ </Space>}
777
+ </div>}
778
+ </>
779
+ );
780
+ }
781
+ }
782
+
783
+ export default DataImport;