@bit-sun/business-component 2.0.0 → 2.0.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.
@@ -1,2 +1,2 @@
1
- declare const _default: (storageKeyString: string, seconds?: number, tipsCallFunction?: (() => {}) | undefined) => void;
1
+ declare const _default: (storageKeyString: string, seconds?: number, tipsCallFunction?: () => {}) => void;
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bit-sun/business-component",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -21,11 +21,11 @@ export default () => {
21
21
  const [choosedSku, setChoosedSku] = useState([]);
22
22
 
23
23
  const callbackHideModal = () => {
24
- alert('关闭弹窗处理函数回调,可以处理刷新表格等操作(非必传)')
24
+ console.log('关闭弹窗处理函数回调,可以处理刷新表格等操作(非必传)')
25
25
  }
26
26
 
27
27
  const callbackHandleOk = (resultData, callback) => {
28
- alert('确定操作,可获取到成功录入的商品,做一系列操作')
28
+ console.log('确定操作,可获取到成功录入的商品,做一系列操作')
29
29
  console.log(resultData)
30
30
  // 一般拿到导入数据是做请求接口操作
31
31
  // import {request} from "bssula";
@@ -12,7 +12,7 @@ const CommodityEntry = (props: any) => {
12
12
  callbackHideModal,
13
13
  callbackHandleOk,
14
14
  columns=["skuCode", "quantity", "price"],
15
- validDataUrl="/bop/api/recordDetailImport/check"
15
+ validDataUrl="/items/api/recordDetailImport/check"
16
16
  } = props;
17
17
 
18
18
  const [modalProps, setModalProps]: any = useState({
@@ -381,6 +381,7 @@ export function commonFun (type?: string, prefixUrl: any, requestConfigProp?: an
381
381
  loadSelectSource(`${prefixUrl.formSelectFix}/brand/queryBrandList`, {
382
382
  pageSize: 5000,
383
383
  currentPage: 1,
384
+ 'ctl-withAuth': true
384
385
  }),
385
386
  loadSelectSource(`${prefixUrl.formSelectFix}/category/queryCategoryTree`, {
386
387
  pageSize: 5000,
@@ -549,6 +550,7 @@ export function commonFun (type?: string, prefixUrl: any, requestConfigProp?: an
549
550
  loadSelectSource(`${prefixUrl.formSelectFix}/brand/queryBrandList`, {
550
551
  pageSize: 5000,
551
552
  currentPage: 1,
553
+ 'ctl-withAuth': true
552
554
  }),
553
555
  loadSelectSource(`${prefixUrl.formSelectFix}/category/queryCategoryTree`, {
554
556
  pageSize: 5000,
@@ -0,0 +1,126 @@
1
+ ---
2
+ nav:
3
+ title: '组件'
4
+ order: 1
5
+ group:
6
+ title: 业务组件
7
+ order: 1
8
+ title: 树型业务选择器
9
+ order: 2
10
+ ---
11
+
12
+ ## BusinessTreeSearchSelect
13
+
14
+ Demo
15
+
16
+ 部门选择器:
17
+
18
+ ```tsx
19
+ import React, { useState } from 'react';
20
+ import { BusinessTreeSearchSelect } from '../../../index';
21
+
22
+ export default () => {
23
+
24
+ const [value, setValue] = useState();
25
+
26
+ const props = {
27
+ mode: 'create',
28
+ value,
29
+ onChange: (v) => {
30
+ setValue(v)
31
+ },
32
+ businessType: 'department'
33
+ };
34
+
35
+ return (
36
+ <div>
37
+ <BusinessTreeSearchSelect {...props} />
38
+ </div>
39
+ );
40
+ };
41
+ ```
42
+
43
+
44
+ 销售组织选择器:
45
+
46
+ ```tsx
47
+ import React, { useState } from 'react';
48
+ import { BusinessTreeSearchSelect } from '../../../index';
49
+
50
+ export default () => {
51
+
52
+ const [value, setValue] = useState();
53
+
54
+ const props = {
55
+ mode: 'create',
56
+ value,
57
+ onChange: (v) => {
58
+ setValue(v)
59
+ },
60
+ businessType: 'sales-organization'
61
+ };
62
+
63
+ return (
64
+ <div>
65
+ <BusinessTreeSearchSelect {...props} />
66
+ </div>
67
+ );
68
+ };
69
+ ```
70
+
71
+ 采购组织选择器:
72
+
73
+ ```tsx
74
+ import React, { useState } from 'react';
75
+ import { BusinessTreeSearchSelect } from '../../../index';
76
+
77
+ export default () => {
78
+
79
+ const [value, setValue] = useState();
80
+
81
+ const props = {
82
+ mode: 'create',
83
+ value,
84
+ onChange: (v) => {
85
+ setValue(v)
86
+ },
87
+ businessType: 'purchase-organization'
88
+ };
89
+
90
+ return (
91
+ <div>
92
+ <BusinessTreeSearchSelect {...props} />
93
+ </div>
94
+ );
95
+ };
96
+ ```
97
+
98
+ 库存组织选择器:
99
+
100
+ ```tsx
101
+ import React, { useState } from 'react';
102
+ import { BusinessTreeSearchSelect } from '../../../index';
103
+
104
+ export default () => {
105
+
106
+ const [value, setValue] = useState();
107
+
108
+ const props = {
109
+ mode: 'create',
110
+ value,
111
+ isChoose: false, // 控制是否父节点可选中,默认不可选中
112
+ onChange: (v) => {
113
+ setValue(v)
114
+ },
115
+ businessType: 'stock-organization'
116
+ };
117
+
118
+ return (
119
+ <div>
120
+ <BusinessTreeSearchSelect {...props} />
121
+ </div>
122
+ );
123
+ };
124
+ ```
125
+
126
+ More skills for writing demo: https://d.umijs.org/guide/demo-principle
@@ -0,0 +1,34 @@
1
+ import React, { useMemo } from 'react';
2
+ import { handleDefaultProps } from './utils';
3
+ import TreeSearchSelect from '@/components/Functional/TreeSearchSelect';
4
+
5
+ const MemoTreeSearchSelect = React.memo(TreeSearchSelect)
6
+
7
+ const BusinessTreeSearchSelect = (props: any) => {
8
+ const businessType = props?.businessType || 'department';
9
+
10
+ const handleBusinessProps = handleDefaultProps(businessType);
11
+
12
+ const currentProps = useMemo(() => {
13
+ return {
14
+ ...handleBusinessProps,
15
+ ...props,
16
+ }
17
+ }, [props?.value])
18
+
19
+ return (
20
+ <div>
21
+ <MemoTreeSearchSelect {...currentProps} />
22
+ </div>
23
+ );
24
+ };
25
+
26
+ export default React.memo(BusinessTreeSearchSelect, (props, nextProps) => {
27
+ if(props && props.labelInValue && props.value && JSON.stringify(props.value) !== JSON.stringify(nextProps.value)) {
28
+ return false
29
+ }
30
+ if(props && props.value !== nextProps.value) {
31
+ return false
32
+ }
33
+ return true
34
+ });
@@ -0,0 +1,60 @@
1
+ const handleDefaultProps = (type: string) => {
2
+ let result = {};
3
+ switch (type){
4
+ case 'department':
5
+ result = {
6
+ treeCheckable: true,
7
+ isChoose: true,
8
+ remoteSource: {
9
+ url: `/user/orgViewNode/common/getTreeForOrgViewAndTenant`,
10
+ initialParams: { 'orgViewCode': 'administrative-organization-view' },
11
+ resKeyValue: ['code', 'name'],
12
+ },
13
+ };
14
+ break;
15
+ case 'sales-organization':
16
+ result = {
17
+ isChoose: true,
18
+ remoteSource: {
19
+ url: `/user/orgViewNode/common/getTreeForOrgViewAndTenant`,
20
+ initialParams: { 'orgViewCode': 'sales-organizational-view' },
21
+ resKeyValue: ['code', 'name'],
22
+ },
23
+ };
24
+ break;
25
+ case 'purchase-organization':
26
+ result = {
27
+ isChoose: true,
28
+ remoteSource: {
29
+ url: `/user/orgViewNode/common/getTreeForOrgViewAndTenant`,
30
+ initialParams: { 'orgViewCode': 'purchase-organizational-view' },
31
+ resKeyValue: ['code', 'name'],
32
+ },
33
+ };
34
+ break;
35
+ case 'stock-organization':
36
+ result = {
37
+ isChoose: true,
38
+ remoteSource: {
39
+ url: `/user/orgViewNode/common/getTreeForOrgViewAndTenant`,
40
+ initialParams: { 'orgViewCode': 'stock-organizational-view' },
41
+ resKeyValue: ['code', 'name'],
42
+ },
43
+ };
44
+ break;
45
+ default:
46
+ result = {
47
+ treeCheckable: true,
48
+ isChoose: true,
49
+ remoteSource: {
50
+ url: `/user/orgViewNode/common/getTreeForOrgViewAndTenant`,
51
+ initialParams: { 'orgViewCode': 'administrative-organization-view' },
52
+ resKeyValue: ['code', 'name'],
53
+ },
54
+ };
55
+ break
56
+ }
57
+ return result;
58
+ }
59
+
60
+ export { handleDefaultProps }
@@ -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,6 +13,10 @@ 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';
@@ -21,3 +25,5 @@ export { default as SearchSelect } from './components/Functional/SearchSelect';
21
25
  export { default as BusinessSearchSelect } from './components/Business/SearchSelect';
22
26
  export { default as CommodityEntry } from './components/Business/CommodityEntry';
23
27
  export { default as CheckOneUser } from './utils/CheckOneUser';
28
+ export { default as TreeSearchSelect } from './components/Functional/TreeSearchSelect';
29
+ export { default as BusinessTreeSearchSelect } from './components/Business/TreeSearchSelect';