@bit-sun/business-component 4.0.12-alpha.20 → 4.0.12-alpha.22

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.
@@ -0,0 +1,205 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { Checkbox } from 'antd';
3
+ import { CaretUpOutlined, CaretDownOutlined } from '@ant-design/icons';
4
+ import './index.less';
5
+ import { set } from "lodash";
6
+
7
+ interface PropertyItem {
8
+ name: string;
9
+ value: string;
10
+ isChecked: boolean;
11
+ isCommonUse: boolean;
12
+ }
13
+
14
+ interface propertyInfoProps {
15
+ propertyName: string;
16
+ propertyCode: string;
17
+ detailList: Array<PropertyItem>;
18
+ }
19
+
20
+ const PropertyGroup = (props: any) => {
21
+
22
+ const {
23
+ propertyData,
24
+ handleProperyItemChange,
25
+ modalVisilbe,
26
+ itemValue,
27
+ } = props;
28
+ const [commonUseProperty, setCommonUseProperty] = useState<Array<PropertyItem> | any>([]); // 常用属性值
29
+ const [notCommonUseProperty, setNotCommonUseProperty] = useState<Array<PropertyItem> | any>([]); // 非常用属性值
30
+ const [indeterminate, setIndeterminate] = useState(false);
31
+ const [showNotCommon, setShowNotCommon] = useState(false);
32
+
33
+ useEffect(() => {
34
+ const proItemValue = (itemValue.propertyList || []).find((item: any) => item.propertyCode === propertyData.propertyCode);
35
+ const checkedList = proItemValue?.detailList || [];
36
+
37
+ const proDetailList = JSON.parse(JSON.stringify( propertyData?.detailList || []));
38
+ proDetailList.forEach((item: any) => {
39
+ if (checkedList.some((checkItem: any) => checkItem.value === item.value)){
40
+ item.isChecked = true;
41
+ }
42
+ });
43
+ const commonUseProperty = (proDetailList).filter((item: any) => item.isCommonUse);
44
+
45
+ const notCommonUseProperty = (proDetailList).filter((item: any) => !item.isCommonUse);
46
+ if (checkedList.some((item: any) => !item.isCommonUse)) {
47
+ setShowNotCommon(true)
48
+ }
49
+ setCommonUseProperty(commonUseProperty);
50
+ setNotCommonUseProperty(notCommonUseProperty);
51
+ }, [modalVisilbe])
52
+
53
+ const parseDataToParent = (comUse: any[], notComUse: any[]) => {
54
+ let choosedPropertyList = (comUse|| []).filter(item => item.isChecked);
55
+ if (showNotCommon) {
56
+ choosedPropertyList = [...choosedPropertyList, ...((notComUse|| []).filter(item => item.isChecked))]
57
+ }
58
+ handleProperyItemChange({
59
+ propertyCode: propertyData?.propertyCode,
60
+ propertyName: propertyData?.propertyName,
61
+ propertyId: propertyData?.propertyId,
62
+ isCommonUse: propertyData?.isCommonUse,
63
+ detailList: choosedPropertyList
64
+ });
65
+ }
66
+
67
+
68
+ const handleChangeAll = (e: any) => {
69
+ if (showNotCommon) {
70
+ notCommonUseProperty.map((item: any) => item.isChecked = e.target.checked);
71
+ setNotCommonUseProperty([...notCommonUseProperty])
72
+ }
73
+ commonUseProperty.map((item: any) => item.isChecked = e.target.checked);
74
+ parseDataToParent(commonUseProperty, notCommonUseProperty)
75
+ setCommonUseProperty([...commonUseProperty])
76
+ setIndeterminate(false)
77
+ }
78
+
79
+ const handleIndeterminate = (commonUseProperty: any[], notCommonUseProperty: any[]) => {
80
+ let checkList = [...commonUseProperty];
81
+ if (showNotCommon) {
82
+ checkList = [...checkList, ...notCommonUseProperty]
83
+ }
84
+ const indeterminate = !!checkList.filter(item => item.isChecked).length && checkList.filter(item => item.isChecked).length !== checkList.length;
85
+ setIndeterminate(indeterminate);
86
+ }
87
+
88
+ const handleItemChecked = (e: any, item: any, type: number) => {
89
+ if (type === 1) { // 常用属性
90
+ (commonUseProperty || []).forEach((info: any) => {
91
+ if (info.value === item.value) {
92
+ info.isChecked = e.target.checked;
93
+ }
94
+ })
95
+ handleIndeterminate(commonUseProperty, notCommonUseProperty)
96
+ parseDataToParent(commonUseProperty, notCommonUseProperty)
97
+ setCommonUseProperty([...commonUseProperty])
98
+ }
99
+
100
+ if (type === 2) { // 非常用属性
101
+ (notCommonUseProperty || []).forEach((info: any) => {
102
+ if (info.value === item.value) {
103
+ info.isChecked = e.target.checked;
104
+ }
105
+ })
106
+ handleIndeterminate(commonUseProperty, notCommonUseProperty)
107
+ parseDataToParent(commonUseProperty, notCommonUseProperty)
108
+ setNotCommonUseProperty([...notCommonUseProperty])
109
+ }
110
+ }
111
+
112
+ const checkAllChecked = () => {
113
+ const checkData = showNotCommon ? [...commonUseProperty, ...notCommonUseProperty] : [...commonUseProperty];
114
+ return checkData.length && checkData.every(item => item.isChecked) ? true : false;
115
+ }
116
+
117
+
118
+ return (
119
+ <div className={'propertyGroup_container'}>
120
+ <div className={'propertyGroup_container_left'}>
121
+ <Checkbox
122
+ checked={checkAllChecked()}
123
+ indeterminate={indeterminate}
124
+ onChange={handleChangeAll}
125
+ >
126
+ <div title={propertyData.name} className="propertyGroup_checkbox_container">{propertyData.propertyName}</div>
127
+ </Checkbox>
128
+ </div>
129
+ <div className={'propertyGroup_container_right'}>
130
+ {
131
+ (commonUseProperty || []).map((item: any) => (
132
+ <Checkbox
133
+ checked={item.isChecked}
134
+ key={item.value}
135
+ onChange={(e) => {
136
+ handleItemChecked(e, item, 1)
137
+ }}
138
+ >
139
+ <div title={item.name} className="propertyGroup_checkbox_container">
140
+ {item.name}
141
+ </div>
142
+ </Checkbox>
143
+ ))
144
+
145
+ }
146
+ {
147
+ showNotCommon && (notCommonUseProperty || []).map((item: any) => (
148
+ <Checkbox
149
+ checked={item.isChecked}
150
+ key={item.value}
151
+ onChange={(e) => {
152
+ handleItemChecked(e, item, 2)
153
+ }}
154
+ >
155
+ <div title={item.name} className="propertyGroup_checkbox_container">
156
+ {item.name}
157
+ </div>
158
+ </Checkbox>
159
+ ))
160
+
161
+ }
162
+ {
163
+ !!notCommonUseProperty.length && (
164
+ <div
165
+ style={{
166
+ width: '50px',
167
+ cursor: 'pointer',
168
+ color: '#005cff',
169
+ fontSize: '10px',
170
+ display: 'flex',
171
+ alignItems: 'center',
172
+ }}
173
+ onClick={() => {
174
+ setShowNotCommon(!showNotCommon);
175
+ handleIndeterminate(commonUseProperty, notCommonUseProperty)
176
+ }}
177
+ >
178
+ {
179
+ showNotCommon && (
180
+ <>
181
+ <CaretUpOutlined />
182
+ 收起
183
+ </>
184
+ )
185
+ }
186
+ {
187
+ !showNotCommon && (
188
+ <>
189
+ <CaretDownOutlined />
190
+ 展开
191
+ </>
192
+ )
193
+ }
194
+ </div>
195
+ )
196
+ }
197
+ </div>
198
+ </div>
199
+ );
200
+ };
201
+
202
+ export default React.memo(PropertyGroup, (props, nextProps) => {
203
+ if (props.modalVisilbe !== nextProps.modalVisilbe) return false;
204
+ return true;
205
+ });
@@ -296,7 +296,8 @@ export function commonFun (type?: string, prefixUrl: any, parentProps?:any) {
296
296
  // 商品选择器sku
297
297
  if(type === 'skuCommodity') {
298
298
  requestConfig = {
299
- url: `${prefixUrl.selectPrefix}/sku/doPageBySelect/v3`,
299
+ url: `${prefixUrl.selectPrefix}/sku/doPageBySelect/v4`,
300
+ method: 'post',
300
301
  filter: 'skuCodeAndSkuName', // 过滤参数
301
302
  searchStartLength: 4,
302
303
  mappingTextField: 'name',
@@ -366,6 +367,9 @@ export function commonFun (type?: string, prefixUrl: any, parentProps?:any) {
366
367
  dropdownStyle: { maxHeight: 400, maxWidth: 100, overflow: 'auto' }
367
368
  },
368
369
  } },
370
+ { name: 'UNIQUE_SPEC', label: '属性', field: {
371
+ type: 'proppertySelector',
372
+ } },
369
373
  ]
370
374
  Promise.all([
371
375
  loadSelectSource(`${prefixUrl.formSelectFix}/brand/queryBrandList`, {
@@ -2,16 +2,29 @@
2
2
  * @Description:
3
3
  * @Author: rodchen
4
4
  * @Date: 2021-12-01 10:52:08
5
- * @LastEditTime: 2021-12-29 19:14:56
6
- * @LastEditors: rodchen
5
+ * @LastEditTime: 2024-11-15 15:25:29
6
+ * @LastEditors: rodchen rodchen_king@outlook.com
7
7
  */
8
8
  // @ts-nocheck
9
9
  import React, { useState, useEffect } from 'react';
10
10
  import { useDebounceFn } from 'ahooks';
11
+ import { debounce } from 'lodash';
11
12
  import { Input, Button, Modal, ConfigProvider } from 'antd';
12
13
  import './index.less';
13
14
 
14
- const QueryMutipleInput = ({ onValueChange,onPressEnter }) => {
15
+ export const handlePressEnter = debounce((ctx) => {
16
+ if (ctx?.table) {
17
+ ctx?.form?.validateFields?.().then((data: any) => {
18
+ const {
19
+ pagination: { pageSize },
20
+ sorter,
21
+ } = ctx?.table?.getPaging();
22
+ ctx?.table?.refreshTable({ pageSize, current: 1 }, data, sorter);
23
+ });
24
+ }
25
+ }, 50);
26
+
27
+ const QueryMutipleInput = ({ onValueChange,onPressEnter, ctx }) => {
15
28
  const [isModalVisible, setIsModalVisible] = useState(false);
16
29
  const [value, setValue] = useState('');
17
30
  const [popvalue, setPopValue] = useState('');
@@ -77,7 +90,12 @@ const QueryMutipleInput = ({ onValueChange,onPressEnter }) => {
77
90
  style={{ width: 'calc(100%)' }}
78
91
  suffix={<div className="query_input_expand_button" onClick={showModal}>...</div>}
79
92
  placeholder="请输入(查询多个值请用 ; 或 , 分割)"
80
- onPressEnter={()=>onPressEnter?.()}
93
+ onPressEnter={(e) => {
94
+ if (onPressEnter) {
95
+ onPressEnter(e);
96
+ }
97
+ if(ctx) handlePressEnter(ctx);
98
+ }}
81
99
  />
82
100
  </div>
83
101
  <Modal
@@ -5,12 +5,25 @@ import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Chec
5
5
  import { SearchOutlined, CopyOutlined, CaretLeftOutlined } from '@ant-design/icons';
6
6
  import request from '@/utils/request';
7
7
  import { stringify } from 'querystring';
8
- import _, { escapeRegExp, isNil, values } from "lodash"
8
+ import _, { escapeRegExp, isNil, values, debounce } from "lodash"
9
9
  import './index.less';
10
10
  import { BusinessSearchSelect, QueryMutipleInput } from '@/index';
11
11
  import { handleSourceName, getFormRowInfo, hasMoreQueryFields, defaultVisibleFieldsCount, getRealStr, ColSpan, getTableHeigth, getCurrentSRKs, getRenderSource } from './utils';
12
12
  import { judgeIsRequestError } from '@/utils/requestUtils';
13
13
  import zhankaitiaojian from '../../../assets/zhankaitiaojian-icon.svg';
14
+ import PropertySelector from '@/components/Business/PropertyModal';
15
+
16
+ export const handlePressEnter = debounce((ctx) => {
17
+ if (ctx?.table) {
18
+ ctx?.form?.validateFields?.().then((data) => {
19
+ const {
20
+ pagination: { pageSize },
21
+ sorter,
22
+ } = ctx?.table?.getPaging();
23
+ ctx?.table?.refreshTable({ pageSize, current: 1 }, data, sorter);
24
+ });
25
+ }
26
+ }, 50);
14
27
 
15
28
  const { Option } = Select;
16
29
 
@@ -180,7 +193,7 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
180
193
  }))
181
194
 
182
195
  // 获取数据源 (type: 1下拉框 2/3弹框 不传值默认为下拉框)
183
- const getData = (params = {}, type = 1,callback?: any) => {
196
+ const getData = (params = {}, type = 1,callback?: any, bodyParams?: any,) => {
184
197
  if (!requestConfig) return;
185
198
 
186
199
  setFetching(true)
@@ -327,10 +340,112 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
327
340
  if (isNil(queryParams[selectParamsKey])) {
328
341
  queryParams[selectParamsKey] = searchValue;
329
342
  }
343
+
344
+ if (requestConfig?.method === 'post') {
345
+ request
346
+ .post(
347
+ `${url}?${stringify(queryParams)}`,
348
+ bodyParams || null,)
349
+ .then((result: any) => {
350
+ setFetching(false)
351
+ result = result.data;
352
+ if (judgeIsRequestError(result)) {
353
+ message.error(result.msg);
354
+ return;
355
+ }
356
+ const res = result.data;
357
+ let source = [];
358
+ if (isMap) {
359
+ source = Object.keys(res).map((d, i) => {
360
+ return {
361
+ text: Object.values(res)[i],
362
+ value: d,
363
+ };
364
+ });
365
+ } else {
366
+ const keys = res.list ? 'list' : 'items';
367
+ source = res
368
+ ? res[keys]
369
+ ? res[keys].map((item: any, index: number) => {
370
+ let textShowText = item[mappingTextField]
371
+ if (mappingTextShowTextField) {
372
+ textShowText = []
373
+ if (Array.isArray(mappingTextShowTextField)) {
374
+ mappingTextShowTextField.forEach((r: any) => {
375
+ textShowText.push(item[r])
376
+ })
377
+ } else {
378
+ textShowText = item[mappingTextShowTextField]
379
+ }
380
+ }
381
+ if (!item?.children?.length) { delete item?.children };
382
+ return {
383
+ ...item,
384
+ text: specialBracket
385
+ ? `【${item[mappingValueField]}】${item[mappingTextField]}`
386
+ : item[mappingTextField],
387
+ textShowText,
388
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
389
+ value: item[mappingValueField],
390
+ keyIndex: type != 1 ? ((queryParams?.currentPage - 1) * queryParams?.pageSize + index + 1) : (index + 1),
391
+ };
392
+ })
393
+ : Array.isArray(res) &&
394
+ res?.map((item: Record<string, any>, index: number) => {
395
+ let textShowText = item[mappingTextField]
396
+ if (mappingTextShowTextField) {
397
+ textShowText = []
398
+ if (Array.isArray(mappingTextShowTextField)) {
399
+ mappingTextShowTextField.forEach((r: any) => {
400
+ textShowText.push(item[r])
401
+ })
402
+ } else {
403
+ textShowText = item[mappingTextShowTextField]
404
+ }
405
+ }
406
+ if (!item?.children?.length) { delete item?.children };
407
+ return {
408
+ ...item,
409
+ text: specialBracket
410
+ ? `【${item[mappingValueField]}】${item[mappingTextField]}`
411
+ : item[mappingTextField],
412
+ textShowText,
413
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
414
+ value: item[mappingValueField],
415
+ keyIndex: type != 1 ? ((queryParams?.currentPage - 1) * queryParams?.pageSize + index + 1) : (index + 1),
416
+ };
417
+ })
418
+ : [];
419
+ }
420
+ // 补充搜索项--选中的数据添加到数据源中去
421
+ const currentSRKs = getCurrentSRKs(selectMode, labelInValue, value)
422
+ if (type === 1 && currentSRKs?.length && currentSRKs?.some(s => !source?.find(r => r.value == s))) {
423
+ const selectedOption = items.filter(option => currentSRKs?.includes(option.value)) || [];
424
+ source = (source || []).concat(selectedOption)
425
+ }
426
+ // 数据源 不可以有重复key
427
+ source = Array.isArray(source) ? _.uniqBy(source, 'value') : [];
428
+
429
+ if (callback) {
430
+ callback(source)
431
+ } else {
432
+ if (type === 1) {
433
+ ctx?.form?.setFieldSource(resultSourceKey, source)
434
+ setSelectDataSource(source, (Number(res?.total || res?.totalCount || source.length)))
435
+ } else {
436
+ setTableData(source)
437
+ setTablePagination({ ...tablePagination, total: Number(res?.total || res?.totalCount || source.length), pageSize: Number(res?.size || res?.pageSize || (params?.pageSize || pageSize)), current: Number(res?.page || res?.currentPage || (params?.currentPage || currentPage)) })
438
+ }
439
+ }
440
+ })
441
+ .catch((err) => { setFetching(false) });
442
+ return;
443
+ }
444
+
445
+
330
446
  request
331
447
  .get(
332
- `${url}?${stringify(queryParams)}`,
333
- {
448
+ `${url}?${stringify(queryParams)}`, {
334
449
  headers: { ...extralHeaders }
335
450
  })
336
451
  .then((result: any) => {
@@ -635,9 +750,14 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
635
750
 
636
751
  // const isHaveParams = params && Object.keys(params).filter(item => params[item]).length > 0;
637
752
  setModalSearched(true);
753
+
754
+ let unique_params = null;
755
+ if (params['UNIQUE_SPEC']) {
756
+ unique_params = params['UNIQUE_SPEC']?.propertyList || [];
757
+ }
638
758
 
639
759
  setTableFormParams(params);
640
- getData({ ...params, pageSize: tableInitPageSize }, 2)
760
+ getData({ ...params, pageSize: tableInitPageSize }, 2, null, unique_params);
641
761
  }
642
762
 
643
763
  const onResetTable = () => {
@@ -817,6 +937,16 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
817
937
  </Col>
818
938
  );
819
939
  }
940
+ if (i?.field?.type === 'proppertySelector') {
941
+ return (
942
+ <Col span={ColSpan} key={i.name}>
943
+ <Form.Item name={i.name} label={i.label} key={i.name}>
944
+ <PropertySelector
945
+ />
946
+ </Form.Item>
947
+ </Col>
948
+ );
949
+ }
820
950
 
821
951
  // 默认type是input
822
952
  return (
@@ -1113,6 +1243,22 @@ const SearchSelect = forwardRef((props: any, ref: any) => {
1113
1243
  )
1114
1244
  }
1115
1245
  onPopupScroll={SelectScroll}
1246
+ onKeyDown={(e) => {
1247
+ if ((e.key === 'Enter' || e.keyCode === 13) && !selectOpen) {
1248
+ if (props?.onPressEnter) {
1249
+ props.onPressEnter?.(e);
1250
+ }
1251
+ handlePressEnter(ctx);
1252
+ setSelectOpen(false)
1253
+ e.preventDefault();
1254
+ e.stopPropagation();
1255
+ return;
1256
+ } else if(e.keyCode === 9 || e.key === 'Tab') {
1257
+ setSelectOpen(false)
1258
+ } else {
1259
+ setSelectOpen(true)
1260
+ }
1261
+ }}
1116
1262
  style={{ width: 'calc(100%)' }}
1117
1263
  placeholder="请选择"
1118
1264
  maxTagPlaceholder={maxTagPlaceholder}
package/src/index.ts CHANGED
@@ -35,6 +35,7 @@ export { default as JsonQueryTable } from './components/Business/JsonQueryTable'
35
35
  export { default as TableColumnSetting} from './plugin/TableColumnSetting';
36
36
  export { default as AuthButton } from './components/Functional/AuthButton';
37
37
  export { default as CustomSelector } from './components/Solution/RuleComponent/CustomPlugin/CustomSelector';
38
+ export { default as PropertySelector} from './components/Business/PropertyModal';
38
39
 
39
40
  export { default as EllipsisTooltip} from './components/Functional/EllipsisTooltip';
40
41
  export * from './components/Functional/BsAntdSula/index';