@bit-sun/business-component 2.0.0 → 2.0.3

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 (26) hide show
  1. package/dist/components/Business/AddSelectBusiness/index.d.ts +1 -0
  2. package/dist/components/Business/TreeSearchSelect/index.d.ts +3 -0
  3. package/dist/components/Business/TreeSearchSelect/utils.d.ts +2 -0
  4. package/dist/components/Functional/AddSelect/index.d.ts +3 -0
  5. package/dist/components/Functional/TreeSearchSelect/index.d.ts +2 -0
  6. package/dist/index.d.ts +4 -0
  7. package/dist/index.esm.js +2189 -140
  8. package/dist/index.js +2191 -138
  9. package/dist/utils/CheckOneUser/index.d.ts +1 -1
  10. package/package.json +1 -1
  11. package/src/components/Business/AddSelectBusiness/index.md +37 -0
  12. package/src/components/Business/AddSelectBusiness/index.tsx +295 -0
  13. package/src/components/Business/CommodityEntry/index.md +2 -2
  14. package/src/components/Business/CommodityEntry/index.tsx +5 -2
  15. package/src/components/Business/SearchSelect/BusinessUtils.ts +2 -0
  16. package/src/components/Business/TreeSearchSelect/index.md +126 -0
  17. package/src/components/Business/TreeSearchSelect/index.tsx +34 -0
  18. package/src/components/Business/TreeSearchSelect/utils.ts +60 -0
  19. package/src/components/Functional/AddSelect/index.less +284 -0
  20. package/src/components/Functional/AddSelect/index.md +118 -0
  21. package/src/components/Functional/AddSelect/index.tsx +882 -0
  22. package/src/components/Functional/DataImport/index.tsx +0 -1
  23. package/src/components/Functional/DataValidation/index.tsx +8 -1
  24. package/src/components/Functional/TreeSearchSelect/index.md +47 -0
  25. package/src/components/Functional/TreeSearchSelect/index.tsx +148 -0
  26. package/src/index.ts +8 -0
@@ -401,7 +401,6 @@ class DataImport extends React.Component {
401
401
  let sheetData = luckysheet.getSheetData();
402
402
  let data = JSON.parse(JSON.stringify(sheetData))
403
403
  .filter((item) => {
404
- debugger
405
404
  return item[0]
406
405
  })
407
406
  .map((item) => {
@@ -400,13 +400,20 @@ class DataValidation extends React.Component {
400
400
  };
401
401
 
402
402
  resetData = () => {
403
- const { validDataUrl, updateData, columns } = this.props;
403
+ const { validDataUrl, updateData, columns, isBrandAuth } = this.props;
404
404
  const resultData = this.getData().filter(d => {
405
405
  return _.compact(Object.values(d)).length
406
406
  })
407
407
 
408
+ // 处理业务参数
409
+ let otherParams={}
410
+ if(isBrandAuth){
411
+ otherParams = { brandAuth: 'ctl-withAuth' }
412
+ }
413
+
408
414
  axios
409
415
  .post(validDataUrl, {
416
+ ...otherParams,
410
417
  columns: columns,
411
418
  data: resultData,
412
419
  })
@@ -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
@@ -13,11 +13,19 @@ const resposne = JSON.parse(localStorage.getItem('userInfo') || '{}');
13
13
 
14
14
  axios.defaults.headers.common['sso-sessionid'] = resposne?.sessionId || '';
15
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
+ }
16
20
 
17
21
  export { default as DataValidation } from './components/Functional/DataValidation';
18
22
  export { default as DataImport } from './components/Functional/DataImport';
19
23
  export { default as QueryMutipleInput } from './components/Functional/QueryMutipleInput';
20
24
  export { default as SearchSelect } from './components/Functional/SearchSelect';
25
+ export { default as AddSelect } from './components/Functional/AddSelect';
21
26
  export { default as BusinessSearchSelect } from './components/Business/SearchSelect';
27
+ export * from './components/Business/AddSelectBusiness';
22
28
  export { default as CommodityEntry } from './components/Business/CommodityEntry';
23
29
  export { default as CheckOneUser } from './utils/CheckOneUser';
30
+ export { default as TreeSearchSelect } from './components/Functional/TreeSearchSelect';
31
+ export { default as BusinessTreeSearchSelect } from './components/Business/TreeSearchSelect';