@cloudbase/weda-ui 3.1.6 → 3.2.0

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 (82) hide show
  1. package/dist/configs/components/chart/bar.json +14 -7
  2. package/dist/configs/components/chart/line.json +14 -7
  3. package/dist/configs/components/chart/pie.json +12 -6
  4. package/dist/configs/components/form/departTreeSelect.json +124 -0
  5. package/dist/configs/components/form/userTreeSelect.json +128 -0
  6. package/dist/configs/components/formdetail.json +105 -0
  7. package/dist/configs/components/listView.json +9 -1
  8. package/dist/configs/components/lottery.json +1 -1
  9. package/dist/configs/components/tabs.json +10 -9
  10. package/dist/configs/components/wxOpenApi/share.json +5 -2
  11. package/dist/configs/index.d.ts +6 -0
  12. package/dist/configs/index.js +6 -0
  13. package/dist/docs/common/format.js +24 -5
  14. package/dist/web/actions/showModal/index.css +3 -0
  15. package/dist/web/actions/showModal/index.d.ts +1 -0
  16. package/dist/web/actions/showModal/index.js +1 -0
  17. package/dist/web/components/calendar/index.js +10 -2
  18. package/dist/web/components/carousel/index.js +4 -0
  19. package/dist/web/components/chart/common/core/eChartBase.js +8 -2
  20. package/dist/web/components/form/form/index.js +10 -7
  21. package/dist/web/components/form/location/common/mapChoose.js +2 -0
  22. package/dist/web/components/form/location/common/mapView.js +2 -0
  23. package/dist/web/components/form/location/components/LocationH5/location.h5.js +3 -1
  24. package/dist/web/components/form/location/components/LocationH5/location.module.css +3 -0
  25. package/dist/web/components/form/select/h5.js +4 -0
  26. package/dist/web/components/form/select/index.js +2 -8
  27. package/dist/web/components/form/switch/index.js +3 -2
  28. package/dist/web/components/form/switch/switch.module.css +7 -0
  29. package/dist/web/components/form/uploader/uploader.h5.d.ts +1 -0
  30. package/dist/web/components/form/uploader/uploader.h5.js +41 -17
  31. package/dist/web/components/form/uploader/uploader.pc.js +31 -2
  32. package/dist/web/components/form/uploaderFile/uploadFile.h5.js +36 -14
  33. package/dist/web/components/form/uploaderFile/uploadFile.pc.js +34 -11
  34. package/dist/web/components/form/userOrgSelect/comTool.d.ts +7 -0
  35. package/dist/web/components/form/userOrgSelect/comTool.js +89 -0
  36. package/dist/web/components/form/userOrgSelect/departTreeSelect/departTreeSelect.h5.d.ts +20 -0
  37. package/dist/web/components/form/userOrgSelect/departTreeSelect/departTreeSelect.h5.js +259 -0
  38. package/dist/web/components/form/userOrgSelect/departTreeSelect/departTreeSelect.pc.d.ts +4 -0
  39. package/dist/web/components/form/userOrgSelect/departTreeSelect/departTreeSelect.pc.js +153 -0
  40. package/dist/web/components/form/userOrgSelect/departTreeSelect/index.d.ts +2 -0
  41. package/dist/web/components/form/userOrgSelect/departTreeSelect/index.js +17 -0
  42. package/dist/web/components/form/userOrgSelect/index.d.ts +2 -0
  43. package/dist/web/components/form/userOrgSelect/index.js +17 -0
  44. package/dist/web/components/form/userOrgSelect/userOrgSelect.less +643 -0
  45. package/dist/web/components/form/userOrgSelect/userTreeSelect.h5.d.ts +24 -0
  46. package/dist/web/components/form/userOrgSelect/userTreeSelect.h5.js +276 -0
  47. package/dist/web/components/form/userOrgSelect/userTreeSelect.pc.d.ts +9 -0
  48. package/dist/web/components/form/userOrgSelect/userTreeSelect.pc.js +229 -0
  49. package/dist/web/components/form/userOrgSelect/utils.d.ts +35 -0
  50. package/dist/web/components/form/userOrgSelect/utils.js +72 -0
  51. package/dist/web/components/formdetail/index.css +115 -0
  52. package/dist/web/components/formdetail/index.d.ts +28 -0
  53. package/dist/web/components/formdetail/index.js +170 -0
  54. package/dist/web/components/index.d.ts +3 -0
  55. package/dist/web/components/index.js +3 -0
  56. package/dist/web/components/listView/index.css +35 -5
  57. package/dist/web/components/listView/index.js +92 -68
  58. package/dist/web/components/listView/interface.d.ts +5 -0
  59. package/dist/web/components/lottery/index.js +2 -1
  60. package/dist/web/components/lottery/lotteryUtil.js +1 -0
  61. package/dist/web/components/navigationBar/index.css +21 -29
  62. package/dist/web/components/richText/index.css +1 -0
  63. package/dist/web/components/swiper/index.js +5 -1
  64. package/dist/web/components/wedaVideo/index.js +1 -0
  65. package/dist/web/utils/getUserService.d.ts +17 -0
  66. package/dist/web/utils/getUserService.js +148 -0
  67. package/dist/web/utils/platform.js +2 -0
  68. package/dist/web/weda-ui.css +9 -0
  69. package/package.json +14 -13
  70. package/dist/asset-manifest.json +0 -17
  71. package/dist/index.html +0 -88
  72. package/dist/static/js/bundle.js +0 -963
  73. package/dist/static/js/bundle.js.map +0 -1
  74. package/dist/static/js/main.chunk.js +0 -8841
  75. package/dist/static/js/main.chunk.js.map +0 -1
  76. package/dist/static/js/vendors~main.chunk.js +0 -247885
  77. package/dist/static/js/vendors~main.chunk.js.map +0 -1
  78. package/dist/static/media/ef6fa527e24e354765d806b826b41391.fa67580a.svg +0 -627
  79. package/dist/web/components/auth/index.d.ts +0 -10
  80. package/dist/web/components/auth/index.js +0 -37
  81. package/dist/web/utils/events.d.ts +0 -1
  82. package/dist/web/utils/events.js +0 -2
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import type { CommonFormPropsType } from '../types';
3
+ import './userOrgSelect.less';
4
+ export declare function UserTreeSelectH5({ id, className, modelClassName, style, modelStyle, events, label, labelVisible, name, placeholder, defaultValueType, defaultValue, confirmValue, disabled, layout, requiredFlag, size, decorator, multiple, //是否多选
5
+ focus: autoFocus, onChange, initOrgRequest, request, getUserByIdRequest, }: IUserTreeSelec): JSX.Element;
6
+ export interface IUserTreeSelec extends CommonFormPropsType {
7
+ defaultValue?: Readonly<string | string[]>;
8
+ confirmValue?: string;
9
+ placeholder?: string;
10
+ defaultValueType?: 'noneUser' | 'confirmUser' | 'loginUser';
11
+ maxLength?: number;
12
+ focus?: boolean;
13
+ size?: 's' | 'm' | 'l' | 'full';
14
+ modelClassName?: string;
15
+ modelStyle?: React.CSSProperties;
16
+ clearable?: boolean;
17
+ multiple?: boolean;
18
+ relation?: object;
19
+ isMuti?: boolean;
20
+ onChange?: (v: any) => void;
21
+ initOrgRequest?: (action?: string, params?: object) => any;
22
+ request?: any;
23
+ getUserByIdRequest?: (v: any) => any;
24
+ }
@@ -0,0 +1,276 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { emptyObject, emptyArray } from '../../../utils/constant';
3
+ import { renderDecorator } from '../renderDecorator';
4
+ import { IconFont } from 'tdesign-icons-react';
5
+ import classNames from '../../../utils/classnames';
6
+ import { getUserById, getUserInfo, defaultRequest, } from '../../../utils/getUserService';
7
+ import { dealOrgData, dealUserData } from './utils';
8
+ import { Modal, Button, ConfigProvider, Radio, Status } from 'tea-component';
9
+ import { isInIde, filterStrList } from '../../../utils/platform';
10
+ import './userOrgSelect.less';
11
+ import isObjectEqual from '../../../utils/isObjectEqual';
12
+ import destr from 'destr';
13
+ import { ErrorStatus } from './comTool';
14
+ export function UserTreeSelectH5({ id, className, modelClassName, style, modelStyle, events = emptyObject, label = '成员选择', labelVisible = true, name = 'formUserTreeSelect', placeholder = '请选择成员', defaultValueType = 'noneUser', defaultValue = emptyArray, confirmValue = '', disabled = false, layout = 'horizontal', requiredFlag = false, size = 'l', decorator, multiple = false, //是否多选
15
+ focus: autoFocus = false, onChange = null, initOrgRequest = null, request = defaultRequest, getUserByIdRequest = getUserById, }) {
16
+ var _a;
17
+ const cls = classNames({
18
+ 'weda-ui': true,
19
+ 'weda-select-user-dept': true,
20
+ [className]: className,
21
+ });
22
+ const modelCls = classNames({
23
+ [className]: modelClassName,
24
+ });
25
+ const subCls = classNames({
26
+ 'weui-cell': true,
27
+ 'weui-cell_active': true,
28
+ 'weui-cell_form': true,
29
+ 'weui-cell_disabled': disabled,
30
+ });
31
+ // 两次默认值不同, 需要刷新
32
+ const prevDefaultRef = React.useRef(null);
33
+ const prevConfirmRef = React.useRef(null);
34
+ const [value, setValue] = useState([]);
35
+ const [visible, setVisible] = React.useState(false);
36
+ const [isSearch, setIsSearch] = useState(false);
37
+ const [orgsTreeData, setOrgsTreeData] = useState([]);
38
+ const [originalOrgData, setOriginalOrgData] = useState([]);
39
+ const [count, setCount] = useState(1); //计数弹窗显示层级
40
+ // 用户单选
41
+ const [curSelectItem, setCurSelectItem] = useState({});
42
+ const [errorInfo, setErrorInfo] = useState({
43
+ errorStatus: false,
44
+ errorMessage: null,
45
+ });
46
+ const handleFocus = (value) => {
47
+ setIsSearch(value);
48
+ };
49
+ const cancleSearch = () => {
50
+ handleFocus(false);
51
+ setSearchValue([]);
52
+ initOrgsData();
53
+ };
54
+ const changeSearchValue = async (event) => {
55
+ var _a;
56
+ try {
57
+ const sValue = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value;
58
+ if (sValue) {
59
+ setSearchValue(multiple ? [...searchValue, sValue] : [sValue]);
60
+ const { Users = [], Roles = [] } = await request('SearchByCondition', {
61
+ KeyWords: sValue.trim(),
62
+ SearchCondition: {
63
+ SearchType: 'SearchByRole',
64
+ NeedUser: true,
65
+ },
66
+ });
67
+ setOrgsTreeData(dealUserData(Users));
68
+ }
69
+ else {
70
+ setSearchValue([]);
71
+ initOrgsData();
72
+ }
73
+ }
74
+ catch (e) {
75
+ setErrorInfo({ errorStatus: true, errorMessage: e });
76
+ }
77
+ };
78
+ const [selectItem, setSelectItem] = useState([]);
79
+ const [searchValue, setSearchValue] = useState([]);
80
+ const [loading, setLoading] = useState({ id: null, status: false });
81
+ const onFocus = function () {
82
+ setSearchValue([]);
83
+ setVisible(true);
84
+ };
85
+ const onClose = () => {
86
+ initOrgsData();
87
+ setErrorInfo({ errorStatus: false, errorMessage: null });
88
+ setVisible(false);
89
+ };
90
+ const onConfirm = (selectItem = []) => {
91
+ var _a, _b, _c, _d;
92
+ const contentList = selectItem.map((e) => e === null || e === void 0 ? void 0 : e.content);
93
+ setValue([...contentList]);
94
+ prevDefaultRef.current = (_a = selectItem[0]) === null || _a === void 0 ? void 0 : _a.userId;
95
+ onChange === null || onChange === void 0 ? void 0 : onChange((_b = selectItem[0]) === null || _b === void 0 ? void 0 : _b.userId);
96
+ (_c = events === null || events === void 0 ? void 0 : events.change) === null || _c === void 0 ? void 0 : _c.call(events, { value: (_d = selectItem[0]) === null || _d === void 0 ? void 0 : _d.userId, data: selectItem });
97
+ initOrgsData();
98
+ setVisible(false);
99
+ };
100
+ useEffect(() => {
101
+ initOrgsData();
102
+ if ((defaultValue &&
103
+ !isObjectEqual(prevDefaultRef.current !== defaultValue)) ||
104
+ (confirmValue &&
105
+ !isObjectEqual(prevConfirmRef.current !== confirmValue)) ||
106
+ defaultValueType === 'loginUser') {
107
+ getDefaultUser();
108
+ prevDefaultRef.current = defaultValue;
109
+ prevConfirmRef.current = confirmValue;
110
+ }
111
+ }, [defaultValueType, confirmValue, defaultValue]);
112
+ const getDefaultUser = async () => {
113
+ var _a;
114
+ try {
115
+ //默认显示登录用户时
116
+ if (defaultValueType === 'loginUser') {
117
+ if (isInIde()) {
118
+ setValue(['显示登录人名称']);
119
+ }
120
+ else {
121
+ const logginUserInfo = await getUserInfo();
122
+ setValue([(logginUserInfo === null || logginUserInfo === void 0 ? void 0 : logginUserInfo.name) || '-']);
123
+ prevDefaultRef.current = logginUserInfo === null || logginUserInfo === void 0 ? void 0 : logginUserInfo.userId;
124
+ onChange === null || onChange === void 0 ? void 0 : onChange(logginUserInfo === null || logginUserInfo === void 0 ? void 0 : logginUserInfo.userId);
125
+ (_a = events === null || events === void 0 ? void 0 : events.change) === null || _a === void 0 ? void 0 : _a.call(events, {
126
+ value: logginUserInfo === null || logginUserInfo === void 0 ? void 0 : logginUserInfo.userId,
127
+ data: logginUserInfo,
128
+ });
129
+ }
130
+ }
131
+ else if ((defaultValueType === 'confirmUser' && confirmValue.length !== 0) ||
132
+ defaultValue.length !== 0) {
133
+ const userIdList = filterStrList(confirmValue.length !== 0 ? confirmValue : defaultValue);
134
+ const userSelectList = [];
135
+ userIdList.forEach(async (userId) => {
136
+ const UserItem = await getUserByIdRequest({
137
+ _id: userId,
138
+ });
139
+ userSelectList.push({ value: userId, data: { content: UserItem } });
140
+ setValue(UserItem ? [UserItem] : [userId]);
141
+ });
142
+ }
143
+ }
144
+ catch (e) {
145
+ setErrorInfo({ errorStatus: true, errorMessage: e });
146
+ }
147
+ };
148
+ // 初始化数据
149
+ const initOrgsData = async () => {
150
+ try {
151
+ const resData = (await request('InitRootOrgs', {})) || [];
152
+ const data = dealOrgData(resData);
153
+ setOrgsTreeData(destr(data));
154
+ setOriginalOrgData([{ index: count, treeData: data }]);
155
+ }
156
+ catch (e) {
157
+ setErrorInfo({ errorStatus: true, errorMessage: e });
158
+ }
159
+ };
160
+ //点击部门节点,获取子部门节点
161
+ const loadDepartData = async (node, count) => {
162
+ setLoading({ id: node.orgId, status: true });
163
+ const { Orgs = [], Users = [] } = await request('LazyDescribeOrgs', {
164
+ OrgId: node.orgId,
165
+ DescribeCondition: {
166
+ NeedUser: true,
167
+ },
168
+ });
169
+ // 用来收集返回的部门和用户
170
+ //@ts-ignore jsx
171
+ const children = dealOrgData(Orgs).concat(dealUserData(Users));
172
+ setOrgsTreeData(destr(children));
173
+ originalOrgData.push({ index: count + 1, treeData: children });
174
+ setCount(count + 1);
175
+ setOriginalOrgData(originalOrgData);
176
+ setLoading({ id: null, status: false });
177
+ };
178
+ //判断当前页结构为第几层,如首次渲染则添加至orgsTreeData,二次进入刷新index数据
179
+ const retLevel = (count) => {
180
+ const storageOriTreeData = [];
181
+ const storageOrgShowData = [];
182
+ if (count !== 1) {
183
+ originalOrgData.map((item) => {
184
+ if ((item === null || item === void 0 ? void 0 : item.index) < count) {
185
+ storageOriTreeData.push(item);
186
+ if ((item === null || item === void 0 ? void 0 : item.index) === count - 1) {
187
+ setCount(count - 1);
188
+ setOrgsTreeData(destr((item === null || item === void 0 ? void 0 : item.treeData) || []));
189
+ }
190
+ }
191
+ else {
192
+ return;
193
+ }
194
+ });
195
+ setOriginalOrgData(storageOriTreeData);
196
+ }
197
+ else {
198
+ onClose();
199
+ }
200
+ };
201
+ return renderDecorator(React.createElement(ConfigProvider, { classPrefix: "wedatea2td" },
202
+ React.createElement("div", { className: subCls },
203
+ React.createElement("div", { className: "weui-cell__bd weui-flex" },
204
+ React.createElement("input", { className: "weui-input", placeholder: placeholder, value: value.join(','), disabled: disabled, name: name, autoFocus: autoFocus, readOnly: true, onClick: onFocus, role: "input" })),
205
+ React.createElement(Modal, { visible: visible, onClose: onClose, destroyOnClose: true, className: `weda-ui weda-select-user-dept__dialog` },
206
+ React.createElement(Modal.Body, { className: ((_a = selectItem[0]) === null || _a === void 0 ? void 0 : _a.userId) ? 'is-selected-value' : '' },
207
+ React.createElement("div", { className: "weda-select-user-dept__dialog-header", id: count.toString() },
208
+ React.createElement("div", { className: count == 1 ? '' : 'arrow-left', onClick: () => retLevel(count) }),
209
+ "\u9009\u62E9\u6210\u5458"),
210
+ React.createElement("div", { className: classNames({
211
+ 'weda-select-user-dept__dialog-search': true,
212
+ 'weda-select-user-dept__dialog-search-focus': isSearch,
213
+ }) },
214
+ React.createElement("div", { className: "weda-select-user-dept__dialog-search-box" },
215
+ React.createElement("input", { type: "text", onFocus: () => {
216
+ handleFocus(true);
217
+ }, onClick: (e) => {
218
+ e.stopPropagation();
219
+ }, value: searchValue.join(), onChange: changeSearchValue, className: "weda-select-user-dept__dialog-search-input" }),
220
+ React.createElement("div", { className: classNames({
221
+ 'weda-select-user-dept__dialog-label': true,
222
+ 'weda-select-user-dept__dialog-label-value': searchValue[0],
223
+ }) },
224
+ React.createElement("span", { className: "search-icon" }),
225
+ React.createElement("span", { className: "search-placeholder" }, "\u641C\u7D22")),
226
+ searchValue && searchValue.length > 0 && (React.createElement("div", { className: "weda-select-user-dept__dialog-input-clear", onClick: cancleSearch },
227
+ React.createElement("p", { className: "weda-select-user-dept__dialog-input-clear-close" })))),
228
+ React.createElement("span", { className: "weda-select-user-dept__dialog-search-cancel", onClick: cancleSearch }, "\u53D6\u6D88")),
229
+ (errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.errorStatus) ? (React.createElement(ErrorStatus, { size: "l", title: "\u63A5\u53E3\u8C03\u7528\u5931\u8D25", description: (errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.errorMessage) || null })) : orgsTreeData && orgsTreeData.length > 0 ? (React.createElement("div", { className: classNames('weda-select-user-dept__dialog-list') }, orgsTreeData.map((item, index) => {
230
+ var _a;
231
+ return (React.createElement("div", { className: "weda-select-user-dept__list-item", key: index + (item === null || item === void 0 ? void 0 : item.id), onClick: () => {
232
+ !(item === null || item === void 0 ? void 0 : item.isUser) ? loadDepartData(item, count) : null;
233
+ } },
234
+ React.createElement("div", { className: "weda-select-user-dept__list-item-wrap" },
235
+ (item === null || item === void 0 ? void 0 : item.isUser) && (React.createElement(Radio.Group, { value: (_a = selectItem.filter((e) => (e === null || e === void 0 ? void 0 : e.userId) === (item === null || item === void 0 ? void 0 : item.userId))[0]) === null || _a === void 0 ? void 0 : _a.userId, onChange: (value, context) => {
236
+ //多选情况,取消选中某元素时
237
+ if (multiple && searchValue.indexOf(value) !== -1) {
238
+ searchValue.splice(searchValue.indexOf(value), 1);
239
+ setSelectItem(selectItem.filter((e) => e.userId !== value));
240
+ }
241
+ else {
242
+ selectItem.push(item);
243
+ setSelectItem(multiple ? [...selectItem] : [item]);
244
+ }
245
+ }, layout: "column" },
246
+ React.createElement(Radio, { name: item === null || item === void 0 ? void 0 : item.userId },
247
+ React.createElement("div", { className: "wedatea2td-form-check__user" },
248
+ React.createElement("div", { className: "item-radio-name" }, item === null || item === void 0 ? void 0 : item.content))))),
249
+ !(item === null || item === void 0 ? void 0 : item.isUser) && (React.createElement("div", { className: "weda-select-user-dept__item-detail" },
250
+ React.createElement("div", { className: "item-name" }, item === null || item === void 0 ? void 0 : item.content),
251
+ (item === null || item === void 0 ? void 0 : item.expandable) && loading.id !== item.orgId && (React.createElement("div", { className: "lcap-icon lcap-icon-chevronright" })),
252
+ loading.id === item.orgId && (loading === null || loading === void 0 ? void 0 : loading.status) && (React.createElement("div", null,
253
+ React.createElement(IconFont, { name: "loading", className: `user_loading weda-grid-navigation__fonticon` }))))))));
254
+ }))) : (React.createElement(Status, { className: "dim-tree-select--blank", icon: 'blank', size: 's', title: `暂无成员数据` }))),
255
+ React.createElement(Modal.Footer, null,
256
+ React.createElement("div", null,
257
+ selectItem.length > 0 && (React.createElement("div", { className: "weda-select-user-dept__select-result" },
258
+ React.createElement("div", { className: "weda-select-user-dept__select-label" }, "\u5DF2\u9009\u62E9"),
259
+ React.createElement("div", { className: "weda-select-user-dept__result-list" }, selectItem.map((d) => (React.createElement("div", { key: d === null || d === void 0 ? void 0 : d.userId, className: "weda-select-user-dept__result-item", onClick: () => {
260
+ setSelectItem(selectItem.filter((e) => (e === null || e === void 0 ? void 0 : e.userId) !== (d === null || d === void 0 ? void 0 : d.userId)));
261
+ const valueList = searchValue.filter((e) => e !== (d === null || d === void 0 ? void 0 : d.userId));
262
+ } }, d === null || d === void 0 ? void 0 :
263
+ d.content,
264
+ React.createElement("div", { className: "close" }))))))),
265
+ React.createElement("div", { className: "weda-select-user-dept__btn-group" },
266
+ React.createElement(Button, { type: "weak", onClick: onClose }, "\u53D6\u6D88"),
267
+ React.createElement(Button, { type: "primary", onClick: () => onConfirm(selectItem) }, "\u786E\u5B9A"))))))))({
268
+ id,
269
+ className: cls,
270
+ style,
271
+ label: labelVisible ? label : null,
272
+ multiCell: false,
273
+ requiredFlag,
274
+ layout,
275
+ });
276
+ }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { IUserTreeSelec } from './userTreeSelect.h5';
3
+ import './userOrgSelect.less';
4
+ export declare function UserTreeSelectPC({ id, className, modelClassName, modelStyle, //弹窗样式控制
5
+ style, events, label, labelVisible, //标题显隐
6
+ name, defaultValue, //默认值,支持数组
7
+ confirmValue, placeholder, defaultValueType, disabled, layout, requiredFlag, size, multiple, //多选
8
+ onChange, request, //接口请求
9
+ getUserByIdRequest, decorator, relation, }: IUserTreeSelec): JSX.Element;
@@ -0,0 +1,229 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { renderDecorator } from '../renderDecorator';
3
+ import { isInIde, filterStrList } from '../../../utils/platform';
4
+ import classNames from 'classnames';
5
+ import { Dropdown, ConfigProvider, Text } from 'tea-component';
6
+ import { getNode, getRelationData, dealOrgData } from './utils';
7
+ import { getUserById, getUserInfo, defaultRequest, } from '../../../utils/getUserService';
8
+ import './userOrgSelect.less';
9
+ import { DimTreeContent } from './comTool';
10
+ import isObjectEqual from '../../../utils/isObjectEqual';
11
+ import { emptyArray, emptyObject } from '../../../utils/constant';
12
+ export function UserTreeSelectPC({ id, className, modelClassName, modelStyle, //弹窗样式控制
13
+ style, events = emptyObject,
14
+ // 组件属性
15
+ label = '人员选择', labelVisible = true, //标题显隐
16
+ name = 'formUserTreeSelect', defaultValue = emptyArray, //默认值,支持数组
17
+ confirmValue = '', placeholder = '请选择人员', defaultValueType = 'noneUser', disabled = false, layout = 'horizontal', requiredFlag = false, size = 'l', multiple = false, //多选
18
+ onChange = null, request = defaultRequest, //接口请求
19
+ getUserByIdRequest = getUserById, decorator, relation, }) {
20
+ // 两次默认值不同, 需要刷新
21
+ const prevDefaultRef = React.useRef(null);
22
+ const prevConfirmRef = React.useRef(null);
23
+ const [selectIds, setSelectIds] = useState([]);
24
+ const [selectUserIds, setSelectUserIds] = useState([]);
25
+ // 用户单选
26
+ const [curSelectData, setCurSelectData] = useState([]);
27
+ // 用户多选
28
+ const [userTreeData, setUserTreeData] = useState([]);
29
+ //const { callWedaApi, showToast, showError } = useGlobalContext();
30
+ const [orgsTreeData, setOrgsTreeData] = useState([]);
31
+ // 节点高亮
32
+ const [activeIds, setActiveIds] = useState([]);
33
+ const [userActiveIds, setUserActiveIds] = useState([]);
34
+ const [open, setOpen] = useState(false);
35
+ //鼠标移入移除输入框
36
+ const [moveIn, setMoveIn] = useState(false);
37
+ const [originalOrgData, setOriginalOrgData] = useState([]);
38
+ const [originalUsersData, setOriginalUsersData] = useState([]);
39
+ const [errorInfo, setErrorInfo] = useState({
40
+ errorStatus: false,
41
+ errorMessage: null,
42
+ });
43
+ useEffect(() => {
44
+ initOrgsData();
45
+ }, [defaultValueType]);
46
+ useEffect(() => {
47
+ if ((defaultValue &&
48
+ !isObjectEqual(prevDefaultRef.current !== defaultValue)) ||
49
+ (confirmValue &&
50
+ !isObjectEqual(prevConfirmRef.current !== confirmValue)) ||
51
+ defaultValueType === 'loginUser') {
52
+ getdefaultUser();
53
+ prevDefaultRef.current = defaultValue;
54
+ prevConfirmRef.current = confirmValue;
55
+ }
56
+ }, [defaultValueType, confirmValue, defaultValue]);
57
+ useEffect(() => {
58
+ var _a;
59
+ if (open) {
60
+ setErrorInfo({ errorStatus: false, errorMessage: null });
61
+ const userId = (_a = curSelectData[0]) === null || _a === void 0 ? void 0 : _a.userId;
62
+ const isOrgs = getNode(orgsTreeData, userId, 'userId');
63
+ if (!userId) {
64
+ setUserActiveIds([]);
65
+ setSelectUserIds([]);
66
+ setUserActiveIds([]);
67
+ setSelectUserIds([]);
68
+ }
69
+ if (isOrgs) {
70
+ setActiveIds([isOrgs.id]);
71
+ setSelectIds([isOrgs.id]);
72
+ setUserActiveIds([]);
73
+ setSelectUserIds([]);
74
+ }
75
+ }
76
+ }, [open]);
77
+ // 初始化数据
78
+ const initOrgsData = async () => {
79
+ try {
80
+ setErrorInfo({ errorStatus: false, errorMessage: null });
81
+ const resData = (await request('InitRootOrgs', {})) || [];
82
+ const data = dealOrgData(resData);
83
+ setOrgsTreeData(data);
84
+ setOriginalOrgData([...data]);
85
+ }
86
+ catch (e) {
87
+ setErrorInfo({ errorStatus: true, errorMessage: e });
88
+ }
89
+ };
90
+ const getdefaultUser = async () => {
91
+ var _a;
92
+ try {
93
+ setErrorInfo({ errorStatus: false, errorMessage: null });
94
+ //默认显示登录用户时
95
+ if (defaultValueType === 'loginUser') {
96
+ if (isInIde()) {
97
+ setCurSelectData([
98
+ { data: { content: '显示登录人名称' }, value: 'loginmock' },
99
+ ]);
100
+ }
101
+ else {
102
+ const logginUserInfo = await getUserInfo();
103
+ setCurSelectData([
104
+ {
105
+ value: logginUserInfo === null || logginUserInfo === void 0 ? void 0 : logginUserInfo.userId,
106
+ data: { content: logginUserInfo === null || logginUserInfo === void 0 ? void 0 : logginUserInfo.name },
107
+ },
108
+ ]);
109
+ (_a = events === null || events === void 0 ? void 0 : events.change) === null || _a === void 0 ? void 0 : _a.call(events, {
110
+ value: logginUserInfo === null || logginUserInfo === void 0 ? void 0 : logginUserInfo.userId,
111
+ data: logginUserInfo,
112
+ });
113
+ }
114
+ }
115
+ else if ((defaultValueType === 'confirmUser' && confirmValue.length !== 0) ||
116
+ defaultValue.length !== 0) {
117
+ const userIdList = filterStrList(confirmValue.length !== 0 ? confirmValue : defaultValue);
118
+ const userSelectList = [];
119
+ userIdList.forEach(async (userId) => {
120
+ const UserItem = await getUserByIdRequest({
121
+ _id: userId,
122
+ });
123
+ userSelectList.push({ value: userId, data: { content: UserItem } });
124
+ setCurSelectData([...userSelectList]);
125
+ });
126
+ }
127
+ }
128
+ catch (e) {
129
+ setErrorInfo({ errorStatus: true, errorMessage: e });
130
+ }
131
+ };
132
+ const reset = (close) => {
133
+ setSelectIds([]);
134
+ setCurSelectData([]);
135
+ setActiveIds([]);
136
+ setErrorInfo({ errorStatus: false, errorMessage: null });
137
+ onChange === null || onChange === void 0 ? void 0 : onChange(null);
138
+ close && setOpen(false);
139
+ };
140
+ // 外层组件类
141
+ const cls = classNames({
142
+ 'weda-ui': true,
143
+ 'weda-user-tree-select': true,
144
+ [className]: className,
145
+ });
146
+ const modelCls = classNames({
147
+ 'dim-tree-select': true,
148
+ 'dim-tree-select--user': true,
149
+ [className]: modelClassName,
150
+ });
151
+ return renderDecorator(React.createElement(ConfigProvider, { classPrefix: "wedatea2td" },
152
+ React.createElement("div", { onMouseEnter: () => {
153
+ setMoveIn(true);
154
+ }, onMouseLeave: () => {
155
+ setMoveIn(false);
156
+ } },
157
+ React.createElement(Dropdown, { "data-testid": "userSelectDropdown", className: classNames('role-tree-select', `role-tree-select--depart`, `size-${size}`), destroyOnClose: false, open: open, onOpenChange: (open) => {
158
+ setOpen(open);
159
+ setErrorInfo({ errorStatus: false, errorMessage: null });
160
+ }, button: curSelectData.length === 0 ? (React.createElement(Text, { className: "placeholder" }, placeholder)) : (React.createElement(SelectViewContainer, { curSelectData: curSelectData, multiple: multiple, placeholder: placeholder, onChange: () => reset(true), moveIn: moveIn })), style: { width: '100%' }, appearance: 'button', clickClose: false, disabled: disabled }, (close) => (React.createElement("div", { className: modelCls, style: modelStyle },
161
+ React.createElement(DimTreeContent, { data: orgsTreeData, setTreeData: setOrgsTreeData, selectedIds: selectIds, activeIds: activeIds, needUser: true, request: request, onActive: (ids, context) => {
162
+ const selectedId = ids[0];
163
+ const node = getNode(orgsTreeData, selectedId, 'id');
164
+ if (node === null || node === void 0 ? void 0 : node.isUser) {
165
+ //多选情况,取消选中某元素时
166
+ if (multiple && activeIds.indexOf(selectedId) !== -1) {
167
+ activeIds.splice(activeIds.indexOf(selectedId), 1);
168
+ setActiveIds([...activeIds]);
169
+ setSelectIds([...activeIds]);
170
+ }
171
+ else {
172
+ setActiveIds(multiple ? [...activeIds, ...ids] : [...ids]);
173
+ setSelectIds(multiple ? [...activeIds, ...ids] : [...ids]);
174
+ }
175
+ }
176
+ }, onReset: () => setOrgsTreeData(originalOrgData), onCancel: () => {
177
+ setOpen(false);
178
+ setErrorInfo({ errorStatus: false, errorMessage: null });
179
+ }, onClear: () => reset(false), onConfirm: () => {
180
+ var _a, _b;
181
+ const nodeList = [];
182
+ const idList = [];
183
+ const selectItem = [];
184
+ selectIds.forEach((selectId) => {
185
+ if (selectId) {
186
+ const node = getNode(orgsTreeData, selectId, 'id');
187
+ nodeList.push(node);
188
+ idList.push(node.userId);
189
+ selectItem.push({ value: node === null || node === void 0 ? void 0 : node.userId, data: node });
190
+ }
191
+ });
192
+ setCurSelectData(selectItem);
193
+ onChange === null || onChange === void 0 ? void 0 : onChange((_a = selectItem[0]) === null || _a === void 0 ? void 0 : _a.value);
194
+ setOpen(false);
195
+ (_b = events === null || events === void 0 ? void 0 : events.change) === null || _b === void 0 ? void 0 : _b.call(events, multiple ? { value: idList, data: nodeList } : selectItem[0]);
196
+ } })))))))({
197
+ id,
198
+ className: cls,
199
+ style,
200
+ label: labelVisible ? label : null,
201
+ layout,
202
+ multiCell: false,
203
+ requiredFlag,
204
+ size,
205
+ decorator,
206
+ });
207
+ }
208
+ const SelectViewContainer = (props) => {
209
+ var _a;
210
+ const { curSelectData, placeholder, onChange, moveIn } = props;
211
+ if (!((_a = curSelectData[0]) === null || _a === void 0 ? void 0 : _a.value))
212
+ return React.createElement(Text, { className: "placeholder1" }, placeholder);
213
+ return (React.createElement(React.Fragment, null,
214
+ React.createElement(ViewCell, { data: curSelectData, showType: "tree", relation: undefined }),
215
+ moveIn && (React.createElement(React.Fragment, null,
216
+ React.createElement("div", { className: "weda-select-user-dept__dialog-input-clear", onClick: (e) => {
217
+ e.stopPropagation();
218
+ onChange === null || onChange === void 0 ? void 0 : onChange();
219
+ } },
220
+ React.createElement("p", { className: "weda-select-user-dept__dialog-input-clear-close" }))))));
221
+ };
222
+ const ViewCell = ({ data, showType, relation }) => {
223
+ const contentList = data.map((e) => { var _a; return (_a = e.data) === null || _a === void 0 ? void 0 : _a.content; });
224
+ if (showType === 'tree') {
225
+ return (React.createElement(Text, { verticalAlign: "middle", "data-testid": "defaultValueText" }, contentList.join(',') || '-'));
226
+ }
227
+ const defaultValue = getRelationData(relation);
228
+ return (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.value) ? (React.createElement(Text, { verticalAlign: "middle" }, defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.content)) : (React.createElement(Text, null, "-"));
229
+ };
@@ -0,0 +1,35 @@
1
+ export function guidMod(bit: any): string;
2
+ export function parentIcon({ expanded }: {
3
+ expanded: any;
4
+ }): JSX.Element;
5
+ export function roleIcon(): JSX.Element;
6
+ export function departIcon(): JSX.Element;
7
+ export function dealOrgData(data?: any[]): {
8
+ id: string;
9
+ content: any;
10
+ children: any;
11
+ selectable: boolean;
12
+ expandable: boolean;
13
+ isUser: boolean;
14
+ icon: ({ expanded }: {
15
+ expanded: any;
16
+ }) => JSX.Element;
17
+ orgId: any;
18
+ userId: any;
19
+ }[];
20
+ export function dealUserData(data: any[], isRole: any): {
21
+ id: string;
22
+ expandable: boolean;
23
+ selectable: boolean;
24
+ content: any;
25
+ userId: any;
26
+ isUser: boolean;
27
+ orgId: any;
28
+ children: any;
29
+ icon: () => JSX.Element;
30
+ }[];
31
+ export function getNode(nodes: any, id: any, key: any): any;
32
+ export function getRelationData(relation: any): {
33
+ content: any;
34
+ id: any;
35
+ };
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+ import { Icon } from 'tea-component';
3
+ import destr from 'destr';
4
+ export const parentIcon = ({ expanded }) => (React.createElement(Icon, { type: expanded ? 'folderopen' : 'folderclose' }));
5
+ export const roleIcon = () => React.createElement(Icon, { type: 'role' });
6
+ export const departIcon = () => React.createElement(Icon, { type: 'depart' });
7
+ // 处理部门数据格式
8
+ export const dealOrgData = (data = []) => data.map((i) => ({
9
+ id: `${guidMod(7)}-${i.OrgId}`,
10
+ content: i[i.PrimaryColumn] || i.OrgId,
11
+ children: undefined,
12
+ selectable: true,
13
+ expandable: true,
14
+ isUser: false,
15
+ icon: parentIcon,
16
+ orgId: i.OrgId,
17
+ userId: (i === null || i === void 0 ? void 0 : i.UserId) || null,
18
+ }));
19
+ // 处理用户数据格式
20
+ export const dealUserData = (data = [], isRole) => data.map((user) => {
21
+ var _a;
22
+ return ({
23
+ id: `${guidMod(7)}-${user.UserId}`,
24
+ expandable: false,
25
+ selectable: true,
26
+ content: (user === null || user === void 0 ? void 0 : user[user === null || user === void 0 ? void 0 : user.PrimaryColumn]) ||
27
+ ((user === null || user === void 0 ? void 0 : user.UserExtend)
28
+ ? ((_a = destr(user.UserExtend)) === null || _a === void 0 ? void 0 : _a[user === null || user === void 0 ? void 0 : user.PrimaryColumn]) || user.UserId
29
+ : user.UserId),
30
+ userId: user.UserId,
31
+ isUser: true,
32
+ orgId: (user === null || user === void 0 ? void 0 : user.OrgId) || null,
33
+ children: undefined,
34
+ icon: isRole ? roleIcon : departIcon,
35
+ });
36
+ });
37
+ export function guidMod(bit) {
38
+ const str = 'qwertyuiopasdfghjklmnbvcxz1234567890';
39
+ let cont = '';
40
+ for (let i = 0; i < bit; i++) {
41
+ cont += str[Math.floor(Math.random() * str.length)];
42
+ }
43
+ return cont;
44
+ }
45
+ export const getNode = (nodes, id, key) => {
46
+ if (!id)
47
+ return null;
48
+ for (const node of nodes) {
49
+ if (node[key] === id) {
50
+ return node;
51
+ }
52
+ if (node.children) {
53
+ const result = getNode(node.children, id, key);
54
+ if (result) {
55
+ return result;
56
+ }
57
+ }
58
+ }
59
+ return null;
60
+ };
61
+ export const getRelationData = (relation) => {
62
+ var _a, _b;
63
+ const record = (_a = relation === null || relation === void 0 ? void 0 : relation.v1) === null || _a === void 0 ? void 0 : _a.record;
64
+ const primaryColumn = (_b = relation === null || relation === void 0 ? void 0 : relation.v1) === null || _b === void 0 ? void 0 : _b.primaryColumn;
65
+ const data = {
66
+ content: record === null || record === void 0 ? void 0 : record[primaryColumn],
67
+ // eslint-disable-next-line no-underscore-dangle
68
+ id: record === null || record === void 0 ? void 0 : record._id,
69
+ };
70
+ // eslint-disable-next-line no-underscore-dangle
71
+ return data;
72
+ };