@bit-sun/business-component 1.2.3 → 2.0.2

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 (30) hide show
  1. package/.umirc.ts +31 -16
  2. package/dist/components/Business/SearchSelect/BusinessUtils.d.ts +1 -1
  3. package/dist/components/Business/SearchSelect/common.d.ts +5 -1
  4. package/dist/components/Business/SearchSelect/utils.d.ts +2 -1
  5. package/dist/components/Business/TreeSearchSelect/index.d.ts +3 -0
  6. package/dist/components/Business/TreeSearchSelect/utils.d.ts +2 -0
  7. package/dist/components/Functional/AddSelect/index.d.ts +3 -0
  8. package/dist/components/Functional/TreeSearchSelect/index.d.ts +2 -0
  9. package/dist/index.d.ts +3 -0
  10. package/dist/index.esm.js +1876 -89
  11. package/dist/index.js +1877 -87
  12. package/dist/utils/CheckOneUser/index.d.ts +1 -1
  13. package/package.json +1 -1
  14. package/src/components/Business/CommodityEntry/index.md +2 -2
  15. package/src/components/Business/CommodityEntry/index.tsx +1 -1
  16. package/src/components/Business/SearchSelect/BusinessUtils.ts +85 -6
  17. package/src/components/Business/SearchSelect/common.ts +20 -1
  18. package/src/components/Business/SearchSelect/index.md +60 -30
  19. package/src/components/Business/SearchSelect/index.tsx +2 -1
  20. package/src/components/Business/SearchSelect/utils.ts +27 -2
  21. package/src/components/Business/TreeSearchSelect/index.md +126 -0
  22. package/src/components/Business/TreeSearchSelect/index.tsx +34 -0
  23. package/src/components/Business/TreeSearchSelect/utils.ts +60 -0
  24. package/src/components/Functional/AddSelect/index.less +275 -0
  25. package/src/components/Functional/AddSelect/index.md +118 -0
  26. package/src/components/Functional/AddSelect/index.tsx +795 -0
  27. package/src/components/Functional/SearchSelect/index.tsx +24 -7
  28. package/src/components/Functional/TreeSearchSelect/index.md +47 -0
  29. package/src/components/Functional/TreeSearchSelect/index.tsx +148 -0
  30. package/src/index.ts +8 -0
@@ -7,7 +7,7 @@ import axios from 'axios';
7
7
  import { stringify } from 'querystring';
8
8
  import _ from "loadsh"
9
9
  import './index.less';
10
- import { BusinessSearchSelect } from '@/index';
10
+ import { BusinessSearchSelect, QueryMutipleInput } from '@/index';
11
11
 
12
12
  const { Option } = Select;
13
13
 
@@ -33,6 +33,7 @@ const SearchSelect = (props: any) => {
33
33
  const tableInitPageSize = 10 // 弹框默认分页 条数
34
34
  const currentPage = 1
35
35
  const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
36
+ const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
36
37
  const currentSelectProps = {
37
38
  ...selectProps,
38
39
  // 以下属性不可更改----设计配置项
@@ -57,7 +58,7 @@ const SearchSelect = (props: any) => {
57
58
  // 优化搜索参数 支持传多个
58
59
  let searchParams = {};
59
60
  if(typeof selectParamsKey === 'string') {
60
- searchParams = { [selectParamsKey]: v ? initVal : searchValue }
61
+ searchParams = v ? { [selectParamsInitKey]: initVal } : { [selectParamsKey]: searchValue }
61
62
  }
62
63
  if(Array.isArray(selectParamsKey)) {
63
64
  selectParamsKey.forEach((i: any) => {
@@ -205,7 +206,7 @@ const SearchSelect = (props: any) => {
205
206
  .then((result: any) => {
206
207
  setFetching(false)
207
208
  result = result.data;
208
- if (result.status !== '0') {
209
+ if ((result?.status && result.status !== '0') || (result?.code && result.code !== '000000')) {
209
210
  message.error(result.msg);
210
211
  return;
211
212
  }
@@ -310,7 +311,6 @@ const SearchSelect = (props: any) => {
310
311
  useEffect(() => {
311
312
  if(value) {
312
313
  setPopValue(value);
313
- onChange(value);
314
314
  }
315
315
  }, [value]);
316
316
 
@@ -356,7 +356,7 @@ const SearchSelect = (props: any) => {
356
356
 
357
357
  const formaData = (value) => {
358
358
  if(labelInValue) {
359
- const formatResult = value.map((i: any) => ({ key: i.code, label: i.name, value: i.code }))
359
+ const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
360
360
  onChange(selectMode ? formatResult : formatResult[0])
361
361
  } else {
362
362
  const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
@@ -511,6 +511,9 @@ const SearchSelect = (props: any) => {
511
511
  onChange: (sks, srs) => {
512
512
  onChangeSelectedKeys(sks, srs)
513
513
  },
514
+ getCheckboxProps: () => ({
515
+ disabled: selectProps?.disabled || props?.disabled,
516
+ }),
514
517
  };
515
518
 
516
519
  const onDoubleClickSelect = (e, record) => {
@@ -546,7 +549,7 @@ const SearchSelect = (props: any) => {
546
549
  )
547
550
  }
548
551
 
549
- if(i?.type === 'businessSearchSelect') {
552
+ if(i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
550
553
  return (
551
554
  <div>
552
555
  <Form.Item name={i.name} label={i.label} key={i.name}>
@@ -556,6 +559,20 @@ const SearchSelect = (props: any) => {
556
559
  )
557
560
  }
558
561
 
562
+ if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
563
+ return (
564
+ <div>
565
+ <Form.Item name={i.name} label={i.label} key={i.name}>
566
+ <QueryMutipleInput onValueChange={(value) => {
567
+ form.setFieldsValue({
568
+ [i.name]: value
569
+ })
570
+ }} />
571
+ </Form.Item>
572
+ </div>
573
+ );
574
+ }
575
+
559
576
  // 默认type是input
560
577
  return (
561
578
  <Form.Item name={i.name} label={i.label} key={i.name}>
@@ -702,7 +719,7 @@ const SearchSelect = (props: any) => {
702
719
  };
703
720
  }}
704
721
  />
705
- {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} /> 全选所有页面</div> : ''}
722
+ {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} disabled={selectProps?.disabled || props?.disabled} /> 全选所有页面</div> : ''}
706
723
  </div>
707
724
  </div>
708
725
  </div>
@@ -0,0 +1,47 @@
1
+ ---
2
+ nav:
3
+ title: '组件'
4
+ order: 1
5
+ group:
6
+ title: 功能组件
7
+ order: 0
8
+ title: 树型选择器
9
+ order: 4
10
+ ---
11
+
12
+ ## TreeSearchSelect
13
+
14
+ 部门选择器Demo:
15
+
16
+ ```tsx
17
+ import React, { useState } from 'react';
18
+ import { TreeSearchSelect } from '../../../index';
19
+
20
+ export default () => {
21
+
22
+ const [value, setValue] = useState();
23
+
24
+ const props = {
25
+ mode: 'create',
26
+ remoteSource: {
27
+ url: `/user/orgViewNode/common/getTreeForOrgViewAndTenant`,
28
+ initialParams: { 'orgViewCode': 'administrative-organization-view' },
29
+ resKeyValue: ['code', 'name'],
30
+ },
31
+ value,
32
+ isChoose: false, // 控制是否父节点可选中,默认不可选中
33
+ treeCheckable: true,
34
+ onChange: (v) => {
35
+ setValue(v)
36
+ }
37
+ };
38
+
39
+ return (
40
+ <div>
41
+ <TreeSearchSelect {...props} />
42
+ </div>
43
+ );
44
+ };
45
+ ```
46
+
47
+ More skills for writing demo: https://d.umijs.org/guide/demo-principle
@@ -0,0 +1,148 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { TreeSelect, Tooltip, Tag } from 'antd';
3
+ import axios from 'axios';
4
+ import { stringify } from 'querystring';
5
+
6
+ const TreeSearchSelect = (props: any) => {
7
+ const [treeData, setTreeData] = useState([]);
8
+ const {
9
+ ctx, // ctx中有自己的name
10
+ value,
11
+ valueName, // 当labelInValue为true时,值为null
12
+ onChange,
13
+ onChangeName, // 当labelInValue为true时,此函数无意义,故无需传
14
+ placeholder,
15
+ remoteSource,
16
+ initialValue,
17
+ treeCheckable = false,
18
+ showSearch = true,
19
+ maxTagCount = 1,
20
+ multiple = false,
21
+ isChoose = false,
22
+ mode,
23
+ getPopupContainer,
24
+ labelInValue = false,
25
+ showArrow = true,
26
+ allowClear = true,
27
+ showCheckedStrategy = TreeSelect.SHOW_PARENT,
28
+ style = { width: '100%' },
29
+ getTreeData
30
+ } = props;
31
+
32
+ const {
33
+ url,
34
+ paramsKey = 'qp-name-like',
35
+ resKeyValue = ['id', 'name'],
36
+ initialParams = {},
37
+ } = remoteSource;
38
+
39
+ const mapSearchTree = (treeDataItem: any) => {
40
+ const haveChildren = Array.isArray(treeDataItem.children) && treeDataItem.children.length > 0;
41
+ return {
42
+ title: treeDataItem[resKeyValue[1]],
43
+ key: treeDataItem[resKeyValue[0]],
44
+ value: treeDataItem[resKeyValue[0]],
45
+ parentId: treeDataItem.parent,
46
+ data: { ...treeDataItem },
47
+ isLeaf: !haveChildren,
48
+ disabled: isDisabled(haveChildren),
49
+ children: haveChildren ? treeDataItem.children.map((i: any) => mapSearchTree(i)) : [],
50
+ };
51
+ };
52
+
53
+ const isDisabled = (children: any) => {
54
+ if (isChoose) {
55
+ return false;
56
+ }
57
+ return children;
58
+ }
59
+
60
+ /* 实时查询 但是目前用的直接是完整数据源, 所以没有使用 */
61
+ const handleSearch = (q: string) => {
62
+ const paramsData = {
63
+ [`${paramsKey}`]: q,
64
+ ...initialParams,
65
+ }
66
+ axios.get(`${url}?${stringify(paramsData)}`).then(async (res: any) => {
67
+ const resData = res?.data || [];
68
+ let coverData;
69
+
70
+ if(resData.status === '0') {
71
+ const { data } = resData;
72
+ if (remoteSource.converter) {
73
+ coverData = await remoteSource.converter({ data: [data] })
74
+ } else {
75
+ const dataList = (data && Array.isArray(data)) ? data : (data && [data] || []);
76
+ coverData = dataList.length && dataList.map((ites: any) => mapSearchTree(ites)) || [];
77
+ }
78
+ } else {
79
+ coverData = []
80
+ }
81
+
82
+ setTreeData(coverData);
83
+ ctx?.form?.setFieldSource(ctx.name, coverData);
84
+ });
85
+ };
86
+
87
+ const handleChange = (data: any, dataName: any) => {
88
+ onChange(data);
89
+ onChangeName && onChangeName(dataName);
90
+ getTreeData && getTreeData(treeData); // 把树节点暴露出去
91
+ ctx?.form?.setFieldValue(ctx.name, data);
92
+ };
93
+
94
+ useEffect(() => {
95
+ handleSearch(initialValue);
96
+ }, []);
97
+
98
+ const maxTagPlaceholder = (selectedValues: any) => {
99
+ const onClose = (e: any,item: any) => {
100
+ e.preventDefault();
101
+ const newValue = labelInValue ? JSON.parse(JSON.stringify(value)).filter((i: any) => i.value !== item.value): JSON.parse(JSON.stringify(value)).filter((i: any) => i !== item.value)
102
+ const newValueName = labelInValue ? null: JSON.parse(JSON.stringify(valueName)).filter((i: any) => i !== item.label)
103
+ handleChange(newValue, newValueName);
104
+ }
105
+ return (
106
+ <Tooltip title={selectedValues.map((i: any) => (
107
+ <Tag
108
+ closable={true}
109
+ onClose={(e) => onClose(e,i)}
110
+ style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
111
+ >
112
+ {i.label}
113
+ </Tag>
114
+ ))}>
115
+ {`+ ${selectedValues?.length}`}
116
+ </Tooltip>
117
+ )
118
+ }
119
+
120
+ return (
121
+ <div className={'tree_search_select'}>
122
+ <TreeSelect
123
+ treeCheckable={treeCheckable}
124
+ maxTagCount={maxTagCount}
125
+ showSearch={showSearch}
126
+ style={style}
127
+ value={value}
128
+ dropdownStyle={{ maxHeight: 400, maxWidth: 100, overflow: 'auto' }}
129
+ treeData={treeData}
130
+ placeholder={placeholder}
131
+ allowClear={allowClear}
132
+ labelInValue={labelInValue}
133
+ showArrow={showArrow}
134
+ showCheckedStrategy={showCheckedStrategy}
135
+ treeNodeFilterProp={'title'}
136
+ treeDefaultExpandAll
137
+ multiple={multiple} // 支持多选(当设置 treeCheckable 时自动变为 true)
138
+ maxTagPlaceholder={maxTagPlaceholder}
139
+ onChange={handleChange}
140
+ disabled={mode==='view' || ctx?.mode === 'view'}
141
+ getPopupContainer={() => (getPopupContainer && getPopupContainer()) || document.body}
142
+ >
143
+ </TreeSelect>
144
+ </div>
145
+ );
146
+ };
147
+
148
+ export default TreeSearchSelect;
package/src/index.ts CHANGED
@@ -12,11 +12,19 @@ import axios from 'axios';
12
12
  const resposne = JSON.parse(localStorage.getItem('userInfo') || '{}');
13
13
 
14
14
  axios.defaults.headers.common['sso-sessionid'] = resposne?.sessionId || '';
15
+ axios.defaults.headers.common['x-tenant-id'] = resposne?.tenantId || '1';
16
+ if (localStorage.getItem('x-user-auth-context')) {
17
+ // @ts-ignore
18
+ axios.defaults.headers.common['x-user-auth-context'] = localStorage.getItem('x-user-auth-context');
19
+ }
15
20
 
16
21
  export { default as DataValidation } from './components/Functional/DataValidation';
17
22
  export { default as DataImport } from './components/Functional/DataImport';
18
23
  export { default as QueryMutipleInput } from './components/Functional/QueryMutipleInput';
19
24
  export { default as SearchSelect } from './components/Functional/SearchSelect';
25
+ export { default as AddSelect } from './components/Functional/AddSelect';
20
26
  export { default as BusinessSearchSelect } from './components/Business/SearchSelect';
21
27
  export { default as CommodityEntry } from './components/Business/CommodityEntry';
22
28
  export { default as CheckOneUser } from './utils/CheckOneUser';
29
+ export { default as TreeSearchSelect } from './components/Functional/TreeSearchSelect';
30
+ export { default as BusinessTreeSearchSelect } from './components/Business/TreeSearchSelect';