ls-pro-common 1.0.29 → 1.0.32

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.
@@ -18,7 +18,7 @@ var _excluded = ["type", "uploadable", "readonly", "allowClear", "title", "modal
18
18
  import React from "react";
19
19
  import { useMemo, useState, useEffect, useContext } from 'react';
20
20
  import { ProFormText, ProFormContext } from 'ls-pro-form';
21
- import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
21
+ import { PlusOutlined, UploadOutlined, SearchOutlined } from '@ant-design/icons';
22
22
  import { httpGet, httpPost } from '../http';
23
23
  import { getCache, toGatewayUrl, showError, showWarn, showSuccess } from '../utils';
24
24
  var fileCenter = getCache('file-center-api') || '/zuul/petrel-file-center-api/';
@@ -54,6 +54,11 @@ function IconSelector(prop) {
54
54
  list = _useState10[0],
55
55
  setList = _useState10[1];
56
56
 
57
+ var _useState11 = useState(''),
58
+ _useState12 = _slicedToArray(_useState11, 2),
59
+ searchKey = _useState12[0],
60
+ setSearchKey = _useState12[1];
61
+
57
62
  var type = prop.type,
58
63
  _prop$uploadable = prop.uploadable,
59
64
  uploadable = _prop$uploadable === void 0 ? true : _prop$uploadable,
@@ -77,7 +82,7 @@ function IconSelector(prop) {
77
82
  }, [type]);
78
83
 
79
84
  var loadData = /*#__PURE__*/function () {
80
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pageIndex) {
85
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pageIndex, keys) {
81
86
  var url, param, result, rows;
82
87
  return _regeneratorRuntime.wrap(function _callee$(_context) {
83
88
  while (1) {
@@ -90,16 +95,21 @@ function IconSelector(prop) {
90
95
  "page.pn": pageIndex,
91
96
  "page.size": pageSize
92
97
  };
93
- _context.next = 4;
98
+
99
+ if (keys) {
100
+ param['search.mongoName_like'] = keys;
101
+ }
102
+
103
+ _context.next = 5;
94
104
  return httpGet(url, param);
95
105
 
96
- case 4:
106
+ case 5:
97
107
  result = _context.sent;
98
108
  rows = result.rows || [];
99
109
  setList(rows);
100
110
  setTotal(result.total || 0);
101
111
 
102
- case 8:
112
+ case 9:
103
113
  case "end":
104
114
  return _context.stop();
105
115
  }
@@ -107,15 +117,15 @@ function IconSelector(prop) {
107
117
  }, _callee);
108
118
  }));
109
119
 
110
- return function loadData(_x) {
120
+ return function loadData(_x, _x2) {
111
121
  return _ref.apply(this, arguments);
112
122
  };
113
123
  }();
114
124
 
115
125
  useEffect(function () {
116
126
  if (!visible) return;
117
- loadData(page);
118
- }, [visible, page]);
127
+ loadData(page, searchKey);
128
+ }, [visible, page, searchKey]);
119
129
  var totalPage = useMemo(function () {
120
130
  if (total === 0) return 1;
121
131
  return Math.ceil(total / pageSize);
@@ -155,7 +165,7 @@ function IconSelector(prop) {
155
165
  if (page !== totalPage) {
156
166
  setPage(totalPage);
157
167
  } else {
158
- loadData(totalPage);
168
+ loadData(totalPage, searchKey);
159
169
  }
160
170
  } else {
161
171
  showSuccess(result.flag.retMsg);
@@ -185,14 +195,33 @@ function IconSelector(prop) {
185
195
  }
186
196
  }) : /*#__PURE__*/React.createElement(PlusOutlined, {
187
197
  onClick: function onClick() {
188
- return setVisible(true);
198
+ var _rest$fieldProps;
199
+
200
+ if ((rest === null || rest === void 0 ? void 0 : rest.disabled) || (rest === null || rest === void 0 ? void 0 : (_rest$fieldProps = rest.fieldProps) === null || _rest$fieldProps === void 0 ? void 0 : _rest$fieldProps.disabled)) {
201
+ return;
202
+ }
203
+
204
+ setVisible(true);
189
205
  }
190
206
  })
191
207
  }, rest.fieldProps, {
192
208
  readOnly: readonly,
193
209
  allowClear: allowClear
194
210
  }))), /*#__PURE__*/React.createElement(_Modal, {
195
- title: title,
211
+ title: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, title), /*#__PURE__*/React.createElement("span", {
212
+ style: {
213
+ display: 'inline-block',
214
+ width: 230,
215
+ marginLeft: 30
216
+ }
217
+ }, /*#__PURE__*/React.createElement(_Input, {
218
+ suffix: /*#__PURE__*/React.createElement(SearchOutlined, null),
219
+ placeholder: "\u8F93\u5165\u56FE\u7247\u540D\u67E5\u8BE2",
220
+ onPressEnter: function onPressEnter(e) {
221
+ setPage(1);
222
+ setSearchKey(e.target.value || '');
223
+ }
224
+ }))),
196
225
  visible: visible,
197
226
  width: modalWidth,
198
227
  destroyOnClose: true,
@@ -236,9 +265,13 @@ function IconSelector(prop) {
236
265
  }
237
266
  }, "\u4E0B\u4E00\u9875"), /*#__PURE__*/React.createElement(_Button, {
238
267
  onClick: function onClick() {
239
- return loadData(page);
268
+ return loadData(page, searchKey);
240
269
  }
241
270
  }, "\u5237\u65B0"))
271
+ }, /*#__PURE__*/React.createElement("div", {
272
+ style: {
273
+ minHeight: '120px'
274
+ }
242
275
  }, list.map(function (o) {
243
276
  return /*#__PURE__*/React.createElement(_Card, {
244
277
  hoverable: true,
@@ -268,7 +301,8 @@ function IconSelector(prop) {
268
301
  formRef.current.setFieldsValue(val);
269
302
  setImgUrl(toGatewayUrl(o.mongoUrl));
270
303
  setVisible(false);
271
- }
304
+ },
305
+ key: o.id
272
306
  }, /*#__PURE__*/React.createElement("div", {
273
307
  style: {
274
308
  height: 80
@@ -287,7 +321,7 @@ function IconSelector(prop) {
287
321
  overflow: 'hidden'
288
322
  }
289
323
  }, o.mongoName));
290
- })));
324
+ }))));
291
325
  }
292
326
 
293
327
  export default IconSelector;
@@ -2,21 +2,43 @@
2
2
  import type { InputProps } from 'antd';
3
3
  import type { ProFormItemProps } from 'ls-pro-form';
4
4
  export declare type InputTableProps = ProFormItemProps<InputProps> & {
5
+ /**@name 弹框选择表格列配置 */
5
6
  columns: any[];
7
+ /**@name 调用后端API地址 */
6
8
  url: string;
9
+ /**@name 弹框表格高度,默认400 */
7
10
  tableHeight?: number;
11
+ /**@name 弹框表格宽度,默认650*/
8
12
  tableWidth?: number;
13
+ /**@name 是否支持多选 */
9
14
  multiple?: boolean;
15
+ /**@name 表单项name, 跟 form.item 的 name一致 */
10
16
  name: string;
17
+ /**@name 返回的值字段,表格中valueField配置的字段时返回给name */
11
18
  valueField: string;
19
+ /**@name 返回输入框显示的字段,textField字段值返回给textName */
12
20
  textField?: string;
21
+ /**@name 用于接收textField返回的值 */
13
22
  textName?: string;
23
+ /** @name 表格的其它配置 */
14
24
  tableConfig?: any;
25
+ /**@name 表单label宽度,默认70 */
15
26
  labelWidth?: number;
27
+ /**@name 是否2.0接口 */
16
28
  isV2?: boolean;
29
+ /**@name 是否支持跨页选择 */
17
30
  keepSelect?: boolean;
18
- onSelectChange?: (item: any) => void;
31
+ /**@name 回车事件查询关键字 */
32
+ searchField?: string;
33
+ /**@name 填充其它表单项目配置 */
34
+ fillMap?: Record<string, string>;
35
+ /**@name 输入后检查数据的触发方式,默认为entry回车触发 */
36
+ triggerCheck?: 'entry' | 'blur';
37
+ /**@name 选择行事件 */
38
+ onSelectChange?: (item: any, formRef?: any) => void;
39
+ /**@name 加载之前事件,param为查询条件对象,可以通过此方法调整 */
19
40
  beforeLoad?: (param: any) => void;
41
+ /**@name 加载之后事件,row为接口返回数据,可以通过此方法调整 */
20
42
  afterLoad?: (rows: any[]) => void;
21
43
  };
22
44
  declare function InputTable(prop: InputTableProps): JSX.Element;
@@ -10,14 +10,15 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
10
10
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
11
11
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
12
12
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
13
- var _excluded = ["columns", "url", "textName", "name", "tableConfig", "tableHeight", "tableWidth", "readonly", "multiple", "valueField", "labelWidth", "textField", "onSelectChange", "beforeLoad", "afterLoad", "isV2", "allowClear", "keepSelect", "fieldProps"],
13
+ var _excluded = ["columns", "url", "textName", "name", "tableConfig", "tableHeight", "tableWidth", "readonly", "multiple", "valueField", "labelWidth", "textField", "onSelectChange", "beforeLoad", "afterLoad", "isV2", "allowClear", "keepSelect", "fieldProps", "searchField", "fillMap", "triggerCheck"],
14
14
  _excluded2 = ["current", "pageSize"];
15
15
  import React from "react";
16
- import { useRef, useState, useEffect, useContext } from 'react';
16
+ import { useRef, useState, useEffect, useContext, useMemo } from 'react';
17
17
  import ProTable from 'ls-pro-table';
18
18
  import { ProFormText, ProFormContext } from 'ls-pro-form';
19
19
  import { MoreOutlined } from '@ant-design/icons';
20
20
  import { httpGet } from '../http';
21
+ import { showWarn } from '../utils';
21
22
 
22
23
  function InputTable(prop) {
23
24
  //@ts-ignore
@@ -67,9 +68,37 @@ function InputTable(prop) {
67
68
  _prop$keepSelect = prop.keepSelect,
68
69
  keepSelect = _prop$keepSelect === void 0 ? false : _prop$keepSelect,
69
70
  fieldProps = prop.fieldProps,
70
- rest = _objectWithoutProperties(prop, _excluded);
71
+ searchField = prop.searchField,
72
+ fillMap = prop.fillMap,
73
+ _prop$triggerCheck = prop.triggerCheck,
74
+ triggerCheck = _prop$triggerCheck === void 0 ? 'entry' : _prop$triggerCheck,
75
+ rest = _objectWithoutProperties(prop, _excluded); //显示输入框绑定的name,如果不设置textName,设置为$name__text
71
76
 
72
- var textNameProp = textName || name + '__text';
77
+
78
+ var textNameProp = useMemo(function () {
79
+ return textName || name + '__text';
80
+ }, [textName, name]); // 输入框回车时,调用查询参数字段
81
+
82
+ var searchKey = useMemo(function () {
83
+ if (searchField) return searchField;
84
+ var col; //先取显示字段
85
+
86
+ if (textField) {
87
+ col = columns.find(function (o) {
88
+ return o.dataIndex === textField || o.key === textField;
89
+ });
90
+ } //取不到时取值字段
91
+
92
+
93
+ if (!col) {
94
+ col = columns.find(function (o) {
95
+ return o.dataIndex === valueField || o.key === valueField;
96
+ });
97
+ }
98
+
99
+ if (col) return col.searchField || col.dataIndex;
100
+ return textField || valueField;
101
+ }, [columns, searchField, valueField, textField]);
73
102
 
74
103
  var loadData = /*#__PURE__*/function () {
75
104
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
@@ -119,7 +148,7 @@ function InputTable(prop) {
119
148
 
120
149
  return _context.abrupt("return", {
121
150
  data: rows,
122
- total: result.total || 0,
151
+ total: Number(result.total || 0),
123
152
  success: true
124
153
  });
125
154
 
@@ -145,7 +174,112 @@ function InputTable(prop) {
145
174
  formValue[textNameProp] = formValue[name];
146
175
  formRef === null || formRef === void 0 ? void 0 : formRef.current.setFieldsValue(_objectSpread({}, formValue));
147
176
  }
148
- }, []);
177
+ }, []); // 处理返回数据
178
+
179
+ var handleValue = function handleValue(row) {
180
+ var _formRef$current2, _formRef$current3;
181
+
182
+ var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : _formRef$current2.getFieldsValue();
183
+ var txt; //支持多选
184
+
185
+ if (Array.isArray(row)) {
186
+ //返回值
187
+ formValue[name] = row.map(function (o) {
188
+ return o[valueField];
189
+ }).join(','); //显示值
190
+
191
+ txt = row.map(function (o) {
192
+ return o[textField || valueField];
193
+ }).join(','); //处理填充其它字段
194
+
195
+ if (fillMap) {
196
+ var _loop = function _loop(key) {
197
+ formValue[key] = row.map(function (o) {
198
+ return o[fillMap[key]];
199
+ }).join(',');
200
+ };
201
+
202
+ for (var key in fillMap) {
203
+ _loop(key);
204
+ }
205
+ }
206
+ } else {
207
+ formValue[name] = row[valueField] || '';
208
+ txt = row[textField || valueField] || '';
209
+
210
+ if (fillMap) {
211
+ for (var _key in fillMap) {
212
+ formValue[_key] = row[fillMap[_key]] || '';
213
+ }
214
+ }
215
+ }
216
+
217
+ formValue[textNameProp] = txt;
218
+ setText(txt);
219
+ setVisible(false);
220
+ (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : _formRef$current3.setFieldsValue(_objectSpread({}, formValue));
221
+ onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(row, formRef);
222
+ }; // 可输入时,回车或失去焦点调接口查询数据
223
+
224
+
225
+ var onQuery = function onQuery(e) {
226
+ if (rest.disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled) || readonly) return;
227
+ var val = e.target.value;
228
+
229
+ if (val) {
230
+ var param = {
231
+ current: 1,
232
+ pageSize: 10
233
+ };
234
+ param[searchKey] = val;
235
+ loadData(param).then(function (result) {
236
+ var rows = result.data || [];
237
+
238
+ if (!rows.length) {
239
+ handleValue({});
240
+ showWarn("".concat(val, "\u67E5\u627E\u4E0D\u5230\u5BF9\u5E94\u7684\u8BB0\u5F55\uFF01"));
241
+ } else if (multiple) {
242
+ handleValue(rows);
243
+ } else {
244
+ handleValue(rows[0]);
245
+ }
246
+ });
247
+ e.stopPropagation();
248
+ e.preventDefault();
249
+ }
250
+ }; //直接输入不回车,value 和 text 为同一个值
251
+
252
+
253
+ var onInput = function onInput(e) {
254
+ var _formRef$current4;
255
+
256
+ var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : _formRef$current4.getFieldsValue();
257
+ var val = e.target.value;
258
+ formValue[name] = val;
259
+ formValue[textNameProp] = val;
260
+ setText(val);
261
+ formRef.current.setFieldsValue(_objectSpread({}, formValue));
262
+ }; // 当表单重置或点clear时,处理值
263
+
264
+
265
+ var clearValue = function clearValue(e) {
266
+ if (!e.target.value) {
267
+ var _formRef$current5;
268
+
269
+ setText('');
270
+ var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : _formRef$current5.getFieldsValue();
271
+ formValue[name] = '';
272
+ formValue[textNameProp] = ''; // 不处理,其它表单自己清空
273
+ // if (fillMap) {
274
+ // for (let key in fillMap) {
275
+ // formValue[key] = '';
276
+ // }
277
+ // }
278
+
279
+ formRef.current.setFieldsValue(_objectSpread({}, formValue));
280
+ }
281
+ };
282
+
149
283
  var tableDom = /*#__PURE__*/React.createElement(ProTable, _extends({
150
284
  columns: columns,
151
285
  request: loadData,
@@ -176,36 +310,14 @@ function InputTable(prop) {
176
310
  onRow: function onRow(record) {
177
311
  return {
178
312
  onDoubleClick: function onDoubleClick() {
179
- var _formRef$current2, _formRef$current3;
180
-
181
- var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : _formRef$current2.getFieldsValue();
182
- formValue[name] = record[valueField];
183
- var txt = record[textField || valueField];
184
- formValue[textNameProp] = txt;
185
- setText(txt);
186
- (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : _formRef$current3.setFieldsValue(_objectSpread({}, formValue));
187
- setVisible(false);
188
- onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(record);
313
+ handleValue(record);
189
314
  }
190
315
  };
191
316
  },
192
317
  toolBarRender: function toolBarRender() {
193
318
  return [/*#__PURE__*/React.createElement(_Button, {
194
319
  onClick: function onClick() {
195
- var _formRef$current4, _formRef$current5;
196
-
197
- var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : _formRef$current4.getFieldsValue();
198
- formValue[name] = selectedRows.map(function (o) {
199
- return o[valueField];
200
- }).join(',');
201
- var txt = selectedRows.map(function (o) {
202
- return o[textField || valueField];
203
- }).join(',');
204
- formValue[textNameProp] = txt;
205
- setText(txt);
206
- (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : _formRef$current5.setFieldsValue(_objectSpread({}, formValue));
207
- onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(selectedRows);
208
- setVisible(false);
320
+ handleValue(selectedRows);
209
321
  }
210
322
  }, "\u786E\u8BA4")];
211
323
  },
@@ -234,30 +346,25 @@ function InputTable(prop) {
234
346
  onVisibleChange: setVisible
235
347
  }, /*#__PURE__*/React.createElement(MoreOutlined, {
236
348
  onClick: function onClick(e) {
349
+ if (rest.disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled)) return;
237
350
  setVisible(true);
238
351
  e.stopPropagation && e.stopPropagation();
239
352
  }
240
353
  })),
241
354
  onClick: function onClick() {
355
+ if (!readonly) return;
242
356
  setVisible(true);
243
357
  },
244
- onInput: function onInput(e) {
245
- var _formRef$current6;
246
-
247
- var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : _formRef$current6.getFieldsValue();
248
- var val = e.target.value;
249
- formValue[name] = val;
250
- formValue[textNameProp] = val;
251
- formRef.current.setFieldsValue(_objectSpread({}, formValue));
358
+ onInput: onInput,
359
+ onChange: clearValue,
360
+ onPressEnter: function onPressEnter(e) {
361
+ if (triggerCheck === 'entry') {
362
+ onQuery(e);
363
+ }
252
364
  },
253
- onChange: function onChange(e) {
254
- if (!e.target.value) {
255
- var _formRef$current7;
256
-
257
- var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : _formRef$current7.getFieldsValue();
258
- formValue[name] = '';
259
- formValue[textNameProp] = '';
260
- formRef.current.setFieldsValue(_objectSpread({}, formValue));
365
+ onBlur: function onBlur(e) {
366
+ if (triggerCheck === 'blur') {
367
+ onQuery(e);
261
368
  }
262
369
  },
263
370
  readOnly: readonly,
@@ -277,35 +384,26 @@ function InputTable(prop) {
277
384
  onVisibleChange: setVisible
278
385
  }, /*#__PURE__*/React.createElement(MoreOutlined, {
279
386
  onClick: function onClick(e) {
387
+ if (rest.disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled)) return;
280
388
  setVisible(true);
281
- e.stopPropagation && e.stopPropagation();
282
389
  }
283
390
  })),
284
391
  onClick: function onClick() {
392
+ if (!readonly) return;
285
393
  setVisible(true);
286
394
  },
287
- onInput: function onInput(e) {
288
- var _formRef$current8;
289
-
290
- var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 ? void 0 : _formRef$current8.getFieldsValue();
291
- var val = e.target.value;
292
- formValue[name] = val;
293
- formValue[textNameProp] = val;
294
- setText(val);
295
- formRef.current.setFieldsValue(_objectSpread({}, formValue));
395
+ onInput: onInput,
396
+ onPressEnter: function onPressEnter(e) {
397
+ if (triggerCheck === 'entry') {
398
+ onQuery(e);
399
+ }
296
400
  },
297
- onChange: function onChange(e) {
298
- //用于清除当前组件值
299
- if (!e.target.value) {
300
- var _formRef$current9;
301
-
302
- setText('');
303
- var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 ? void 0 : _formRef$current9.getFieldsValue();
304
- formValue[name] = '';
305
- formValue[textNameProp] = '';
306
- formRef.current.setFieldsValue(_objectSpread({}, formValue));
401
+ onBlur: function onBlur(e) {
402
+ if (triggerCheck === 'blur') {
403
+ onQuery(e);
307
404
  }
308
405
  },
406
+ onChange: clearValue,
309
407
  readOnly: readonly,
310
408
  value: text,
311
409
  allowClear: allowClear
@@ -82,6 +82,14 @@ export declare const treeEach: (list: any[], fn: (item: any, index: any, list: a
82
82
  * @returns 返回符合条件的第一条对象
83
83
  */
84
84
  export declare const treeFind: (list: any[], key: string, val: any, children?: string) => any;
85
+ /**
86
+ * 处理普通的尺码横排
87
+ * @param orgSizeHeader 后端返回的原始尺码组表头
88
+ * @param typeWidth 尺码组宽 sizeTypeNo,默认120
89
+ * @param sizeWidth 尺码宽f1~f100, 默认100
90
+ * @returns 返回已处理好的表头[{dataIndex:sizeTypeNo,title:'国标码',width:120,children[...]},{dataIndex:'f1',...}...]
91
+ */
92
+ export declare const handleSizeCols: (orgSizeHeader: any[], typeWidth?: number, sizeWidth?: number) => any[];
85
93
  export declare const isDev: boolean;
86
94
  export declare type UserType = {
87
95
  id?: string;
package/es/utils/index.js CHANGED
@@ -217,6 +217,99 @@ export var treeFind = function treeFind(list, key, val) {
217
217
 
218
218
  return item;
219
219
  };
220
+ /**
221
+ * 处理普通的尺码横排
222
+ * @param orgSizeHeader 后端返回的原始尺码组表头
223
+ * @param typeWidth 尺码组宽 sizeTypeNo,默认120
224
+ * @param sizeWidth 尺码宽f1~f100, 默认100
225
+ * @returns 返回已处理好的表头[{dataIndex:sizeTypeNo,title:'国标码',width:120,children[...]},{dataIndex:'f1',...}...]
226
+ */
227
+
228
+ export var handleSizeCols = function handleSizeCols(orgSizeHeader) {
229
+ var typeWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 120;
230
+ var sizeWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100;
231
+ // f1~f100 当所有尺码组都为null时,删除不需要的尺码。
232
+ var arr = orgSizeHeader.map(function (o) {
233
+ var _loop = function _loop(key) {
234
+ if (orgSizeHeader.every(function (item) {
235
+ return !item['f' + key];
236
+ })) {
237
+ delete o['f' + key];
238
+ }
239
+ };
240
+
241
+ for (var key = 1; key <= 100; key++) {
242
+ _loop(key);
243
+ }
244
+
245
+ return o;
246
+ }); // 多表头时找到最底层的表头
247
+
248
+ var findNext = function findNext(item) {
249
+ if (item.children.length) {
250
+ return findNext(item.children[0]);
251
+ }
252
+
253
+ return item;
254
+ };
255
+
256
+ var headers = []; // 用于保存返回表头
257
+
258
+ var header; // 用于保存每个配码的表头信息
259
+
260
+ arr.forEach(function (h, i) {
261
+ // 先处理尺码组
262
+ header = {
263
+ dataIndex: 'sizeTypeNo',
264
+ title: h.sizeTypeNo,
265
+ width: typeWidth,
266
+ ellipsis: true
267
+ }; //当返回多个尺码组时,需要用children支持多表头
268
+
269
+ if (arr.length > i + 1) {
270
+ header.children = [];
271
+ } // 第一个尺码组,直接添加,第二个之后,加到上一个的children中。
272
+
273
+
274
+ if (i === 0) {
275
+ headers.push(header);
276
+ } else {
277
+ findNext(headers.find(function (o) {
278
+ return o.dataIndex === 'sizeTypeNo';
279
+ })).children.push(header);
280
+ } // 处理 f1~f100
281
+
282
+
283
+ var _loop2 = function _loop2(k) {
284
+ if (k === 'sizeTypeNo') return "continue";
285
+ header = {
286
+ dataIndex: k,
287
+ title: h[k] || ' ',
288
+ width: sizeWidth,
289
+ ellipsis: true
290
+ };
291
+
292
+ if (arr.length > i + 1) {
293
+ header.children = [];
294
+ }
295
+
296
+ if (i === 0) {
297
+ headers.push(header);
298
+ } else {
299
+ findNext(headers.find(function (o) {
300
+ return o.dataIndex === k;
301
+ })).children.push(header);
302
+ }
303
+ };
304
+
305
+ for (var k in h) {
306
+ var _ret = _loop2(k);
307
+
308
+ if (_ret === "continue") continue;
309
+ }
310
+ });
311
+ return headers;
312
+ };
220
313
  export var isDev = location.href.includes("//localhost");
221
314
  /** @name 用户信息 */
222
315