@bit-sun/business-component 2.2.49 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/common/ENUM.d.ts +40 -0
  2. package/dist/components/Functional/BsAntdSula/BsCascader/index.d.ts +18 -0
  3. package/dist/components/Functional/BsAntdSula/index.d.ts +1 -0
  4. package/dist/components/Solution/RuleComponent/Formula.d.ts +8 -0
  5. package/dist/components/Solution/RuleComponent/services.d.ts +1 -0
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.esm.js +10513 -11455
  8. package/dist/index.js +10827 -11765
  9. package/dist/utils/index.d.ts +1 -0
  10. package/dist/utils/utils.d.ts +7 -0
  11. package/package.json +2 -1
  12. package/src/common/ENUM.ts +41 -0
  13. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +4 -0
  14. package/src/components/Business/JsonQueryTable/index.tsx +248 -33
  15. package/src/components/Functional/BsAntdSula/BsCascader/index.md +62 -0
  16. package/src/components/Functional/BsAntdSula/BsCascader/index.tsx +178 -0
  17. package/src/components/Functional/BsAntdSula/index.ts +2 -0
  18. package/src/components/Functional/EllipsisTooltip/index.d.ts +5 -0
  19. package/src/components/Functional/EllipsisTooltip/index.js +36 -0
  20. package/src/components/Functional/EllipsisTooltip/index.md +30 -0
  21. package/src/components/Solution/RuleComponent/Formula.tsx +335 -0
  22. package/src/components/Solution/RuleComponent/index.d.ts +29 -0
  23. package/src/components/Solution/RuleComponent/index.js +2028 -0
  24. package/src/components/Solution/RuleComponent/index.less +230 -0
  25. package/src/components/Solution/RuleComponent/renderSpecificAction.js +99 -0
  26. package/src/components/Solution/RuleComponent/ruleFiled.js +2074 -0
  27. package/src/components/Solution/RuleComponent/services.ts +13 -0
  28. package/src/components/Solution/RuleComponent/util.js +139 -0
  29. package/src/index.ts +4 -0
  30. package/src/utils/index.ts +1 -0
  31. package/src/utils/utils.ts +29 -0
@@ -1,3 +1,4 @@
1
1
  import './requestUtils';
2
2
  import './checkUtils';
3
3
  import './LocalstorageUtils';
4
+ import './utils';
@@ -14,3 +14,10 @@ export declare const handleBssulaColumnsSpecialParams: (col: any) => void;
14
14
  export declare const handleAntdColumnsSpecialParams: (col: any) => void;
15
15
  export declare const getDictionarySource: (dicCode: string, needConvertInterger?: boolean) => any;
16
16
  export declare function uuid(): string;
17
+ export declare const judgeIsEmpty: (value: any) => boolean;
18
+ /**
19
+ * 处理错误请求
20
+ * @param {*} response 返回结果
21
+ * @param {*} needBackError 是否需要将错误回传到页面单独处理
22
+ */
23
+ export declare function handleError(response: object, needBackError?: boolean): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bit-sun/business-component",
3
- "version": "2.2.49",
3
+ "version": "2.3.1",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -46,6 +46,7 @@
46
46
  "axios": "^0.24.0",
47
47
  "classnames": "^2.3.1",
48
48
  "lodash": "^4.17.21",
49
+ "moment": "^2.25.3",
49
50
  "querystring": "^0.2.1",
50
51
  "react": "^16.12.0",
51
52
  "react-beautiful-dnd": "10.0.0",
@@ -0,0 +1,41 @@
1
+ const ENUM = {
2
+ /**
3
+ * 事件动作类型枚举
4
+ */
5
+ VALUE_TYPE: {
6
+ STATUS: 1, // 流转状态
7
+ TAG: 2, // 添加标签
8
+ TIMING: 3, // 定时器
9
+ EDIT_FIELD: 4, // 字段变更
10
+ },
11
+ /**
12
+ * 执行动作枚举
13
+ */
14
+ EXCUSE_ACTION: {
15
+ SEND_MESSAGE: 1, // 发送消息
16
+ PUSH_TODO_TASK: 2, // 推送任务
17
+ },
18
+ EXCUSE_ACTION_TEXT: {
19
+ SEND_MESSAGE: '发送一条消息',
20
+ PUSH_TODO_TASK: '推送一条待办任务',
21
+ },
22
+ /**
23
+ * 消息接收人分组类型枚举
24
+ */
25
+ RECEIVER_GROUP_TYPE: {
26
+ EMPLOYEES: 1, // 指定员工
27
+ ORGANIZATION: 2, // 指定组织
28
+ ROLE: 3, // 指定角色
29
+ PERSON_IN_DOCUMENT: 4, // 单据内人员
30
+ SEND_ALL: 5, // 所有人
31
+ },
32
+ /**
33
+ * 消息发送类型枚举
34
+ */
35
+ MESSAGE_SENDTIME_TYPE: {
36
+ IMMEDIATELY_SEND: 1, // 立即发送
37
+ REGULARLY_SEND: 2, // 定时发送
38
+ },
39
+ };
40
+
41
+ export default ENUM;
@@ -12,6 +12,7 @@ export default (props:any)=>{
12
12
  codeProps='',
13
13
  moduleType,
14
14
  moduleRelationId,
15
+ tableFlag = false
15
16
  } = props;
16
17
 
17
18
  const ref = useRef(null);
@@ -108,6 +109,9 @@ export default (props:any)=>{
108
109
  key: 'codeSnippet',
109
110
  title: '代码片段',
110
111
  render: ({text,record}:any) => {
112
+ if(tableFlag){
113
+ return <div> 列表:{`{"key": "extensionFields,${record.code}","dataIndex": "extensionFields,${record.code}","title": "${record.name}"},`}</div>
114
+ }
111
115
  if (!codeProps.columns) {
112
116
  return <div>表单:{`{"name": "extensionFields,${record.code}","label": "${record.name}"},`}</div>
113
117
  }
@@ -1,6 +1,6 @@
1
1
  // @ts-nocheck
2
- import React, { useState, useRef, useEffect } from 'react';
3
- import { message, Button, Table } from 'antd';
2
+ import React, { useState, useRef, useEffect, Fragment } from 'react';
3
+ import { message, Button, Table, Tabs } from 'antd';
4
4
  import Drawer from './drawer';
5
5
  import ConfigButton from './configButton';
6
6
  import Editor from './jsonEditor';
@@ -76,13 +76,28 @@ function convertFileds (fields, falltValue, faltFieldRange, containerName) {
76
76
  field.fields.forEach(item => {
77
77
  const targetValue = convertFileds(item, falltValue, faltFieldRange, field?.container?.name);
78
78
  if(targetValue){
79
+ if(item.dependency) {
80
+ targetValue.dependency = {
81
+ visible: {
82
+ ...item.dependency.visible,
83
+ type: (new Function('axios','ctx', item.dependency.visible.type)).bind(null, axios)
84
+ }
85
+ }
86
+ }
79
87
  filedsValue.push(targetValue)
80
88
  }
81
89
  })
82
90
  } else {
83
91
  const returnField = field.isStaticCode ? falltValue[containerName ? (containerName + field.name) : field.name] : faltFieldRange[field.name];
84
92
  if (returnField) {
85
- returnField.label = field?.label;
93
+ returnField.label = field?.label;
94
+ if(field?.disabled){ // 字段设置只读属性
95
+ returnField.field.props.disabled = true;
96
+ }
97
+ if(field?.invisible){ // 字段设置不可见属性
98
+ returnField.initialVisible = false;
99
+ }
100
+
86
101
  if(Array.isArray(returnField.name)&&returnField.name?.includes("extensionFields")){
87
102
  returnField.notShowLabel = true;
88
103
  }
@@ -120,16 +135,45 @@ function faltCustomerFieldRange(fileds) {
120
135
  return columnsValue;
121
136
  }
122
137
 
123
- function hanleCallbackValue(codeProps, value, customerFields) {
124
- const faltFieldRange = faltCustomerFieldRange(customerFields)
125
- const falltValue = flatFileds({fields: codeProps.fields})
138
+ //form存在新加container属性分组得情况 组合操作
139
+ function combineContainer(originFields, currentFields){
140
+ let newCurrentFields = [...originFields];
141
+ currentFields.map((item: any) => {
142
+ if(!originFields.find((i: any) => i?.container?.props?.name == item?.container?.name)){
143
+ newCurrentFields = [...newCurrentFields, {
144
+ container: {
145
+ type: 'card',
146
+ props: {
147
+ title: item?.container?.title,
148
+ level: 1,
149
+ id: Math.random(),
150
+ isWhiteCard: true,
151
+ bordered: false,
152
+ name: item?.container?.name,
153
+ },
154
+ },
155
+ fields: item?.fields || []
156
+ }];
157
+ }
158
+ })
159
+ return newCurrentFields;
160
+ }
161
+
162
+ function hanleCallbackValue(codeProps, value, customerFields, cacheColumns = []) {
163
+ const faltFieldRange = faltCustomerFieldRange(customerFields);
164
+ // const falltValue = flatFileds({fields: codeProps.fields})
165
+ const falltValue = flatFileds({fields: combineContainer(codeProps.fields, value?.fields)})
126
166
  let newCodeProps = {...codeProps};
127
167
  newCodeProps.fields = convertFileds({fields: value.fields}, falltValue, faltFieldRange).fields;
128
168
  if (codeProps.columns) {
129
169
  const faltColumnsValue = faltColumns(codeProps.columns)
130
170
  newCodeProps.columns = value.columns.map(item => {
131
171
  if (item.isStaticCode) {
132
- return faltColumnsValue[item.key]
172
+ const cacheFieldProperty = cacheColumns.find(k => (k.key||k.dataIndex) == (item.key||item.dataIndex));
173
+ return {
174
+ ...faltColumnsValue[item.key],
175
+ ...cacheFieldProperty
176
+ }
133
177
  } else {
134
178
  //自定义字段-列字段
135
179
  if(item?.key&&item?.key.includes('extensionFields')&&item?.key.includes(',')){
@@ -137,10 +181,19 @@ function hanleCallbackValue(codeProps, value, customerFields) {
137
181
  ...item,
138
182
  render: ({ record }: any) => {
139
183
  try{
140
- const lastName1= item?.key.split(',')[1]; //兼容没有fieldName的情况
141
- const lastName2 = `${lastName1}Name`;
142
- const target = record?.extensionFields || {};
143
- return target[lastName2] || target[lastName1] || '';
184
+ const { extensionFields = {} } = record;
185
+ const fieldName1= item?.key.split(',')[1]; //兼容没有fieldName的情况
186
+ const fieldName2 = `${fieldName1}Name`;
187
+ if(customerFields.length){
188
+ const targetField = customerFields.find(k => k.name.includes(fieldName1));
189
+ if(targetField){
190
+ const { initialSource = [] } = targetField
191
+ if(initialSource.length){
192
+ return initialSource.find((d => d.value == extensionFields[fieldName1]))?.text || extensionFields[fieldName1];
193
+ }
194
+ }
195
+ }
196
+ return extensionFields[fieldName2] || extensionFields[fieldName1] || '';
144
197
  }catch(e){
145
198
  console.log('e',e);
146
199
  }
@@ -205,11 +258,13 @@ const tableStyleList = [
205
258
  ];
206
259
  const JsonQueryTable = React.memo(props => {
207
260
  const {
208
- callBack,
209
- codeProps,
210
- customerFields,
211
- initialSetting,
212
- pageType
261
+ callBack, // 主保存函数回调
262
+ codeProps, // 整体的配置数据
263
+ customerFields, //可选的配置字段
264
+ initialSetting, //上一次添加自定义字段后保存的数据
265
+ pageType, //页面权限code
266
+ detailTablesSetting = [], //详情明细表格列配置数据
267
+ saveTableCallBack, //详情明细保存函数回调
213
268
  } = props;
214
269
 
215
270
  let codeFilter = {};
@@ -229,7 +284,6 @@ const JsonQueryTable = React.memo(props => {
229
284
  } else {
230
285
  codeFilter.fields = iterFileds({fields: codeProps.fields}).fields
231
286
  }
232
- console.log('codeFilter',codeFilter)
233
287
 
234
288
  const styleRef = useRef(null);
235
289
 
@@ -238,6 +292,9 @@ const JsonQueryTable = React.memo(props => {
238
292
  const [init, setInit] = useState(true);
239
293
  const [jsonEditorVal, setJsonEditorVal] = useState(initialSetting || codeFilter);
240
294
  const [moduleParams, setModuleParams] = useState({});
295
+ const [activeKey, setActiveKey] = useState('main'); //默认详情页配置
296
+ const [tablesConfigParams, setTablesConfigParams] = useState({});
297
+ const [tableJsonEditorValsArr, setTableJsonEditorValsArr] = useState([]);
241
298
 
242
299
  useEffect(()=>{
243
300
  Promise.all([
@@ -258,6 +315,69 @@ const JsonQueryTable = React.memo(props => {
258
315
  })
259
316
  },[]);
260
317
 
318
+ useEffect(()=>{
319
+ //明细表的配置数据
320
+ const axiosArr = detailTablesSetting.map((item:any) => axios.get(`/basic/flow/businessFieldGroup/one?moduleType=2&layoutPoint=${item.tableCode}`));
321
+ Promise.all(axiosArr).then(([...resArr])=> {
322
+ let configParams = {};
323
+ detailTablesSetting.map((item:any, index:number)=>{
324
+ const { code, data } = resArr[index]?.data || {};
325
+ if(data){
326
+ const { businessType, code:fieldGroup, moduleType } = data;
327
+ configParams [item.tableCode] = {
328
+ businessType,
329
+ fieldGroup,
330
+ moduleType,
331
+ tableFlag: true
332
+ }
333
+ }
334
+ })
335
+ setTablesConfigParams({
336
+ ...configParams,
337
+ });
338
+ })
339
+
340
+ const detailTableCodeFilter = detailTablesSetting.map(item => {
341
+ if(item?.initialSetting && item?.initialSetting.length){
342
+ return {
343
+ ...item,
344
+ columns: item?.initialSetting
345
+ }
346
+ }
347
+ return {
348
+ ...item,
349
+ columns: item?.columns.map(childItem => ({
350
+ key: childItem.key || childItem.dataIndex,
351
+ dataIndex: childItem.dataIndex || childItem.key,
352
+ isStaticCode: true,
353
+ title: childItem.title
354
+ }))
355
+ }
356
+ });
357
+ setTableJsonEditorValsArr([...detailTableCodeFilter]);
358
+ const lastRes = detailTableCodeFilter.map(item => {
359
+ if(item?.initialSetting && item?.initialSetting.length){
360
+ const codeProps = {
361
+ fields: [],
362
+ columns: item?.columns,
363
+ };
364
+ const newValue = {
365
+ fields: [],
366
+ columns: item.initialSetting
367
+ };
368
+ const result = hanleCallbackValue(codeProps, newValue, item?.customerFields, item?.cacheColumns);
369
+ return {
370
+ ...item,
371
+ columns: result?.columns
372
+ }
373
+ }
374
+ return item;
375
+ });
376
+ if(lastRes.length){
377
+ saveTableCallBack(lastRes, false);
378
+ }
379
+ },[detailTablesSetting.length]);
380
+
261
381
  const onClickRun = (value, isSave) => {
262
382
  setJsonEditorVal(value);
263
383
 
@@ -269,6 +389,38 @@ const JsonQueryTable = React.memo(props => {
269
389
  }
270
390
  };
271
391
 
392
+ //明细表保存
393
+ const onClickRunDetailTables = (value, isSave, tableCode, tableSouce) =>{
394
+ const targetCode = tableCode || activeKey;
395
+ const targetTableSource = tableSouce || tableJsonEditorValsArr;
396
+ const newArr = targetTableSource.map(item => {
397
+ if(item.tableCode == targetCode){
398
+ return {
399
+ ...item,
400
+ columns: value
401
+ }
402
+ }
403
+ return item
404
+ });
405
+ setTableJsonEditorValsArr([...newArr]);
406
+
407
+ try {
408
+ const target = targetTableSource.find(item=>item.tableCode == targetCode);
409
+ const codeProps = {
410
+ fields: [],
411
+ columns: target?.columns,
412
+ };
413
+ const newValue = {
414
+ fields: [],
415
+ columns: value
416
+ };
417
+ const result = hanleCallbackValue(codeProps, newValue, target?.customerFields, target?.cacheColumns);
418
+ saveTableCallBack({ columns: result.columns, tableCode: targetCode }, isSave, value);
419
+ } catch (e) {
420
+ message.error(e);
421
+ }
422
+ }
423
+
272
424
  React.useEffect(() => {
273
425
  localStorage.setItem('jsonEditorVal',JSON.stringify(jsonEditorVal||{}))
274
426
  }, [jsonEditorVal]);
@@ -291,25 +443,88 @@ const JsonQueryTable = React.memo(props => {
291
443
 
292
444
  return (
293
445
  <div>
294
- <Drawer visible={visible} width={800} onClose={() => setVisible(false)} className={'customFieldsDrawer'}>
295
- <div ref={styleRef}>
296
-
297
- </div>
298
- {
299
- isEmpty(moduleParams)?(
300
- <div style={{padding:"10px 0", fontSize:"16px", fontWeight:"bolder"}}>
301
- 提示:业务对象未维护,请在通用单据对应业务类型下维护业务对象
446
+ <Drawer visible={visible} width={1400} onClose={() => setVisible(false)} className={'customFieldsDrawer'}>
447
+ {
448
+ detailTablesSetting.length == 0 &&(
449
+ <div style={{display: 'flex'}}>
450
+ <div style={{flex: 1, width: 500}}>
451
+ {
452
+ isEmpty(moduleParams)?(
453
+ <div style={{padding:"10px 0", fontSize:"16px", fontWeight:"bolder"}}>
454
+ 提示:业务对象未维护,请在通用单据对应业务类型下维护业务对象
455
+ </div>
456
+ ):(
457
+ <FieldsSettingsTable {...tableParams}/>
458
+ )
459
+ }
460
+ </div>
461
+ <div style={{flex: 1}}>
462
+ <Editor
463
+ type="table"
464
+ onRun={onClickRun}
465
+ value={jsonEditorVal}
466
+ shallowHeight={height}
467
+ />
468
+ </div>
302
469
  </div>
303
- ):(
304
- <FieldsSettingsTable {...tableParams}/>
305
470
  )
306
471
  }
307
- <Editor
308
- type="table"
309
- onRun={onClickRun}
310
- value={jsonEditorVal}
311
- shallowHeight={height}
312
- />
472
+ {
473
+ detailTablesSetting.length > 0 && (
474
+ <Tabs defaultActiveKey={activeKey} onChange={(v: any) => setActiveKey(v)}>
475
+ <Tabs.TabPane tab="详情页配置" key="main">
476
+ <div style={{display: 'flex'}}>
477
+ <div style={{flex: 1, width: 500}}>
478
+ {
479
+ isEmpty(moduleParams)?(
480
+ <div style={{padding:"10px 0", fontSize:"16px", fontWeight:"bolder"}}>
481
+ 提示:业务对象未维护,请在通用单据对应业务类型下维护业务对象
482
+ </div>
483
+ ):(
484
+ <FieldsSettingsTable {...tableParams}/>
485
+ )
486
+ }
487
+ </div>
488
+ <div style={{flex: 1}}>
489
+ <Editor
490
+ type="table"
491
+ onRun={onClickRun}
492
+ value={jsonEditorVal}
493
+ shallowHeight={height}
494
+ />
495
+ </div>
496
+ </div>
497
+ </Tabs.TabPane>
498
+ {
499
+ tableJsonEditorValsArr.map((k:any)=>(
500
+ <Tabs.TabPane tab={k.title} key={k.tableCode}>
501
+ <div style={{display: 'flex'}}>
502
+ <div style={{flex: 1, width: 500}}>
503
+ {
504
+ !tablesConfigParams[k.tableCode]?(
505
+ <div style={{padding:"10px 0", fontSize:"16px", fontWeight:"bolder"}}>
506
+ 提示:业务对象未维护,请在通用单据对应业务类型下维护业务对象
507
+ </div>
508
+ ):(
509
+ <FieldsSettingsTable {...tablesConfigParams[k.tableCode]}/>
510
+ )
511
+ }
512
+ </div>
513
+ <div style={{flex: 1}}>
514
+ <Editor
515
+ type="table"
516
+ onRun={onClickRunDetailTables}
517
+ value={k.columns}
518
+ shallowHeight={height}
519
+ />
520
+ </div>
521
+ </div>
522
+ </Tabs.TabPane>
523
+ ))
524
+ }
525
+ </Tabs>
526
+ )
527
+ }
313
528
  </Drawer>
314
529
 
315
530
  {!visible && isAdmin() && <ConfigButton type='primary' onClick={() => setVisible(true)}>setting</ConfigButton>}
@@ -0,0 +1,62 @@
1
+ ---
2
+ nav:
3
+ title: '组件'
4
+ order: 1
5
+ group:
6
+ path: /components/functional
7
+ title: 功能组件
8
+ order: 0
9
+ title: 级联选择
10
+ order: 7
11
+ ---
12
+
13
+ ## BsCascader
14
+
15
+ Demo:
16
+
17
+ ```tsx
18
+ import React, { useState } from 'react';
19
+ import { BsCascader } from '../../../../index';
20
+ import { request } from 'bssula';
21
+
22
+ export default () => {
23
+ const [value, setValue] = useState()
24
+
25
+ return (
26
+ <div>
27
+ <BsCascader
28
+ isAll={true}
29
+ needNameAndCode={true}
30
+ notChangeOnSelect={true}
31
+ initRequestSource={async () => {
32
+ return await request({
33
+ url: '/basic/bscArea/getBscAreaList?qp-level-eq=1&qp-pid-eq=100000',
34
+ method: 'get',
35
+ converter: ({ data }) => {
36
+ const handleData =
37
+ data && data[0]
38
+ ? data?.map((item) => {
39
+ return {
40
+ text: item.name,
41
+ value: item.id,
42
+ level: item.level,
43
+ id: item.id,
44
+ };
45
+ })
46
+ : [];
47
+ return handleData;
48
+ },
49
+ });
50
+ }}
51
+ value={value}
52
+ onChange={(value) => {
53
+ setValue(value);
54
+ }}
55
+ getPopupContainer={() => document.body}
56
+ />
57
+ </div>
58
+ );
59
+ };
60
+ ```
61
+
62
+ More skills for writing demo: https://d.umijs.org/guide/demo-principle
@@ -0,0 +1,178 @@
1
+ // @ts-nocheck
2
+
3
+ import React, { useEffect, useState } from 'react';
4
+ import { Cascader, message } from 'antd';
5
+ import type { CascaderProps as ACascaderProps } from 'antd/lib/cascader';
6
+ import { request } from 'bssula';
7
+
8
+ export type CascaderSourceItem = {
9
+ text: any;
10
+ value: any;
11
+ };
12
+
13
+ export interface CascaderSource {
14
+ text: any;
15
+ value: any;
16
+ children: CascaderSourceItem[];
17
+ }
18
+
19
+ export interface CascaderProps extends ACascaderProps {
20
+ source: CascaderSource[];
21
+ }
22
+
23
+ const BsCascader = ({
24
+ source,
25
+ onChange,
26
+ value,
27
+ disabled,
28
+ needNameAndCode,
29
+ onlyCode,
30
+ requiredLength,
31
+ isAll,
32
+ notChangeOnSelect,
33
+ isFirstOnly,
34
+ initRequestSource,
35
+ style,
36
+ }: {
37
+ source: any;
38
+ onChange: Function;
39
+ }) => {
40
+ if (!source && !initRequestSource) return null;
41
+
42
+ const [handSource, setHandSource] = useState(
43
+ source?.map((item) => ({ ...item, label: item.text, isLeaf: false })) || [],
44
+ );
45
+ useEffect(async () => {
46
+ if (!source && initRequestSource) {
47
+ const resData = await initRequestSource();
48
+ const data =
49
+ resData?.map((item) => ({
50
+ ...item,
51
+ label: item.text,
52
+ isLeaf: false,
53
+ })) || [];
54
+ setHandSource(data);
55
+ }
56
+ }, []);
57
+
58
+ useEffect(() => {
59
+ setHandSource(
60
+ source?.map((item) => ({ ...item, label: item.text, isLeaf: false })) ||
61
+ [],
62
+ );
63
+ }, [source]);
64
+
65
+ const [valueSource, setValueSource] = useState([]);
66
+ const [options, setOptions] = React.useState(handSource);
67
+ if (options && handSource && options.length != handSource.length) {
68
+ setOptions(handSource);
69
+ }
70
+
71
+ useEffect(() => {
72
+ if (value && onlyCode) {
73
+ if (value?.length) {
74
+ request({
75
+ url: `/basic/bscArea/getBscAreaList?qp-code-in=${value}`,
76
+ method: 'get',
77
+ }).then((res) => {
78
+ res = res.sort((a, b) => {
79
+ return a.level - b.level;
80
+ });
81
+ setValueSource(res);
82
+ });
83
+ } else {
84
+ setValueSource([]);
85
+ }
86
+ }
87
+ }, [value]);
88
+
89
+ const onChangeInner = (value: string, selectedOptions: any[]) => {
90
+ if (requiredLength && value.length !== requiredLength) return;
91
+ if (needNameAndCode) {
92
+ onChange({
93
+ PCDName: selectedOptions
94
+ ? selectedOptions.map((item) => item.text)
95
+ : [],
96
+ PCDCode: selectedOptions
97
+ ? selectedOptions.map((item) => item.value)
98
+ : [],
99
+ });
100
+ } else if (onlyCode) {
101
+ onChange(
102
+ selectedOptions ? selectedOptions.map((item) => item.value) : [],
103
+ );
104
+ } else {
105
+ onChange(selectedOptions ? selectedOptions.map((item) => item.text) : []);
106
+ }
107
+ };
108
+
109
+ const loadData = (selectedOptions) => {
110
+ const targetOption = selectedOptions[selectedOptions.length - 1];
111
+ targetOption.loading = true;
112
+ request({
113
+ url: `/basic/bscArea/getBscAreaList?qp-pid-eq=${targetOption.id}`,
114
+ method: 'get',
115
+ converter: ({ data }) => {
116
+ const initialVal = data
117
+ ? data.map((item) => {
118
+ return {
119
+ text: item.name,
120
+ value: item.id,
121
+ label: item.name,
122
+ level: item.level,
123
+ isLeaf: item.level > (isAll ? 2 : 1),
124
+ id: item.id,
125
+ };
126
+ })
127
+ : [];
128
+ return initialVal;
129
+ },
130
+ })
131
+ .then((res) => {
132
+ targetOption.loading = false;
133
+ if (res.length) {
134
+ targetOption.children = res;
135
+ } else {
136
+ targetOption.children = undefined;
137
+ }
138
+ setOptions([...options]);
139
+ })
140
+ .catch((err: any) => {
141
+ message.error('网络错误');
142
+ });
143
+ };
144
+
145
+ const filter = (inputValue, path) => {
146
+ return path.some(
147
+ (option) =>
148
+ option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1,
149
+ );
150
+ };
151
+
152
+ let CascaderVal = value;
153
+ if (needNameAndCode) {
154
+ CascaderVal = value ? value.PCDName : value;
155
+ } else if (onlyCode) {
156
+ CascaderVal = valueSource?.map((item) => item.name)?.join() || [];
157
+ }
158
+
159
+ const showSearch = !!(options.length && options.length > 5);
160
+
161
+ if (disabled) return CascaderVal;
162
+
163
+ return (
164
+ <Cascader
165
+ key={1}
166
+ style={style}
167
+ disabled={disabled}
168
+ value={CascaderVal}
169
+ options={options}
170
+ loadData={loadData}
171
+ onChange={onChangeInner}
172
+ showSearch={showSearch ? filter : false}
173
+ changeOnSelect={!notChangeOnSelect}
174
+ />
175
+ );
176
+ };
177
+
178
+ export default BsCascader;