@icos-desktop/react-components 0.1.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.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # ICOS Desktop React Components
@@ -0,0 +1,35 @@
1
+ import React, { ReactNode } from 'react';
2
+
3
+ interface Config {
4
+ getAccessToken?: () => string | Promise<string> | void;
5
+ }
6
+ declare const configFn: (config: Config) => void;
7
+
8
+ interface TestComponentProps {
9
+ heading: string;
10
+ content: ReactNode;
11
+ }
12
+
13
+ declare const TestComponent: React.FC<TestComponentProps>;
14
+
15
+ interface CheckInfo {
16
+ info: {
17
+ selectSenseObjCodes?: string[];
18
+ selectBookIds?: string[];
19
+ unSelectBookIds?: string[];
20
+ selectSenseGlobalCodes?: string[];
21
+ unSelectSenseGlobalCodes?: string[];
22
+ selectOrgIds?: string[];
23
+ };
24
+ total: number;
25
+ }
26
+ interface EntityTreeProps {
27
+ viewCodes: string[];
28
+ onTotalChange?: (total: number) => void;
29
+ onCheck?: (checkedInfo: CheckInfo) => void;
30
+ defaultCheckedAll?: boolean;
31
+ }
32
+
33
+ declare const EntityTree: React.FC<EntityTreeProps>;
34
+
35
+ export { EntityTree, TestComponent, configFn as config };
package/build/index.js ADDED
@@ -0,0 +1,1059 @@
1
+ import * as React from 'react';
2
+ import React__default, { useState, useEffect } from 'react';
3
+ import { produce } from 'immer';
4
+ import Highlighter from 'react-highlight-words';
5
+ import { message, Spin, Tree, Popover } from 'antd';
6
+ import { LoadingOutlined } from '@ant-design/icons';
7
+ import { useUpdateEffect } from 'ahooks';
8
+ import axios from 'axios';
9
+ import { cloneDeep } from 'lodash';
10
+
11
+ /******************************************************************************
12
+ Copyright (c) Microsoft Corporation.
13
+
14
+ Permission to use, copy, modify, and/or distribute this software for any
15
+ purpose with or without fee is hereby granted.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
+ PERFORMANCE OF THIS SOFTWARE.
24
+ ***************************************************************************** */
25
+ /* global Reflect, Promise, SuppressedError, Symbol */
26
+
27
+
28
+ var __assign = function() {
29
+ __assign = Object.assign || function __assign(t) {
30
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
31
+ s = arguments[i];
32
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
33
+ }
34
+ return t;
35
+ };
36
+ return __assign.apply(this, arguments);
37
+ };
38
+
39
+ function __rest(s, e) {
40
+ var t = {};
41
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
42
+ t[p] = s[p];
43
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
44
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
45
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
46
+ t[p[i]] = s[p[i]];
47
+ }
48
+ return t;
49
+ }
50
+
51
+ function __awaiter(thisArg, _arguments, P, generator) {
52
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
53
+ return new (P || (P = Promise))(function (resolve, reject) {
54
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
55
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
56
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
57
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
58
+ });
59
+ }
60
+
61
+ function __generator(thisArg, body) {
62
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
63
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
64
+ function verb(n) { return function (v) { return step([n, v]); }; }
65
+ function step(op) {
66
+ if (f) throw new TypeError("Generator is already executing.");
67
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
68
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
69
+ if (y = 0, t) op = [op[0] & 2, t.value];
70
+ switch (op[0]) {
71
+ case 0: case 1: t = op; break;
72
+ case 4: _.label++; return { value: op[1], done: false };
73
+ case 5: _.label++; y = op[1]; op = [0]; continue;
74
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
75
+ default:
76
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
77
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
78
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
79
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
80
+ if (t[2]) _.ops.pop();
81
+ _.trys.pop(); continue;
82
+ }
83
+ op = body.call(thisArg, _);
84
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
85
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
86
+ }
87
+ }
88
+
89
+ function __spreadArray(to, from, pack) {
90
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
91
+ if (ar || !(i in from)) {
92
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
93
+ ar[i] = from[i];
94
+ }
95
+ }
96
+ return to.concat(ar || Array.prototype.slice.call(from));
97
+ }
98
+
99
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
100
+ var e = new Error(message);
101
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
102
+ };
103
+
104
+ var configFn = function (config) {
105
+ window._ICOS_DESKTOP_ = __assign(__assign({}, window._ICOS_DESKTOP_), config);
106
+ };
107
+
108
+ function styleInject(css, ref) {
109
+ if ( ref === void 0 ) ref = {};
110
+ var insertAt = ref.insertAt;
111
+
112
+ if (!css || typeof document === 'undefined') { return; }
113
+
114
+ var head = document.head || document.getElementsByTagName('head')[0];
115
+ var style = document.createElement('style');
116
+ style.type = 'text/css';
117
+
118
+ if (insertAt === 'top') {
119
+ if (head.firstChild) {
120
+ head.insertBefore(style, head.firstChild);
121
+ } else {
122
+ head.appendChild(style);
123
+ }
124
+ } else {
125
+ head.appendChild(style);
126
+ }
127
+
128
+ if (style.styleSheet) {
129
+ style.styleSheet.cssText = css;
130
+ } else {
131
+ style.appendChild(document.createTextNode(css));
132
+ }
133
+ }
134
+
135
+ var css_248z$1 = ".TestComponent-module_test-component__nta6Z {\n background-color: var(--background);\n color: var(--font-color);\n border: 1px solid var(--harvey-black);\n padding: 16px;\n width: 360px;\n text-align: center;\n}\n.TestComponent-module_test-component__nta6Z .TestComponent-module_heading__TOFqv {\n font-size: var(--heading-font-size);\n}\n";
136
+ var styles$1 = {"test-component":"TestComponent-module_test-component__nta6Z","heading":"TestComponent-module_heading__TOFqv"};
137
+ styleInject(css_248z$1);
138
+
139
+ var TestComponent = function (_a) {
140
+ var heading = _a.heading, content = _a.content;
141
+ return (React__default.createElement("div", { className: styles$1['test-component'] },
142
+ React__default.createElement("h1", { className: styles$1.heading }, heading),
143
+ React__default.createElement("div", null, content)));
144
+ };
145
+
146
+ var _path$5;
147
+ function _extends$5() { return _extends$5 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$5.apply(null, arguments); }
148
+ var SvgDown = function SvgDown(props) {
149
+ return /*#__PURE__*/React.createElement("svg", _extends$5({
150
+ xmlns: "http://www.w3.org/2000/svg",
151
+ width: 16,
152
+ height: 16,
153
+ fill: "none"
154
+ }, props), _path$5 || (_path$5 = /*#__PURE__*/React.createElement("path", {
155
+ fill: "currentColor",
156
+ d: "m13.354 6.354-5 5a.5.5 0 0 1-.708 0l-5-5a.5.5 0 0 1 .708-.708L8 10.293l4.646-4.647a.5.5 0 1 1 .708.708"
157
+ })));
158
+ };
159
+
160
+ var _path$4;
161
+ function _extends$4() { return _extends$4 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$4.apply(null, arguments); }
162
+ var SvgTreePerson = function SvgTreePerson(props) {
163
+ return /*#__PURE__*/React.createElement("svg", _extends$4({
164
+ xmlns: "http://www.w3.org/2000/svg",
165
+ width: 16,
166
+ height: 16,
167
+ fill: "none"
168
+ }, props), _path$4 || (_path$4 = /*#__PURE__*/React.createElement("path", {
169
+ fill: "currentColor",
170
+ d: "M14.433 13.75A.5.5 0 0 1 14 14H2a.5.5 0 0 1-.433-.75c.952-1.646 2.42-2.826 4.131-3.385a4.5 4.5 0 1 1 4.604 0c1.712.56 3.179 1.74 4.13 3.385a.5.5 0 0 1 .001.5"
171
+ })));
172
+ };
173
+
174
+ var _path$3;
175
+ function _extends$3() { return _extends$3 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$3.apply(null, arguments); }
176
+ var SvgTreePlace = function SvgTreePlace(props) {
177
+ return /*#__PURE__*/React.createElement("svg", _extends$3({
178
+ xmlns: "http://www.w3.org/2000/svg",
179
+ width: 16,
180
+ height: 16,
181
+ fill: "none"
182
+ }, props), _path$3 || (_path$3 = /*#__PURE__*/React.createElement("path", {
183
+ fill: "currentColor",
184
+ d: "M8 1.5A6.5 6.5 0 1 0 14.5 8 6.507 6.507 0 0 0 8 1.5M3.893 11.654l.158-.103a1 1 0 0 0 .449-.83l.013-2.265L5.823 6.5l.02.014 1.23.804c.206.146.459.207.709.173l1.968-.267a1 1 0 0 0 .625-.338l1.386-1.61A1 1 0 0 0 12 4.625v-.396a5.49 5.49 0 0 1 1.236 5.459l-1.01-.923a1 1 0 0 0-1.057-.187l-1.904.79a1 1 0 0 0-.605.778l-.15 1.012a1 1 0 0 0 .736 1.113l1.342.354.147.148a5.49 5.49 0 0 1-6.842-1.119"
185
+ })));
186
+ };
187
+
188
+ var _path$2;
189
+ function _extends$2() { return _extends$2 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$2.apply(null, arguments); }
190
+ var SvgTreeEvent = function SvgTreeEvent(props) {
191
+ return /*#__PURE__*/React.createElement("svg", _extends$2({
192
+ xmlns: "http://www.w3.org/2000/svg",
193
+ width: 17,
194
+ height: 16,
195
+ fill: "none"
196
+ }, props), _path$2 || (_path$2 = /*#__PURE__*/React.createElement("path", {
197
+ fill: "currentColor",
198
+ d: "M14.3 10.6a.5.5 0 0 0-.3-.1h-.5V4a2 2 0 0 0-2-2H3a2 2 0 0 0-2 2c0 .85.628 1.346.7 1.4a.49.49 0 0 0 .59.006.5.5 0 0 0 .014-.802C2.302 4.601 2 4.36 2 4a1 1 0 0 1 2 0v8a2 2 0 0 0 2 2h7a2 2 0 0 0 2-2c0-.85-.625-1.346-.7-1.4M7 6h4a.5.5 0 0 1 0 1H7a.5.5 0 1 1 0-1m-.5 2.5A.5.5 0 0 1 7 8h4a.5.5 0 0 1 0 1H7a.5.5 0 0 1-.5-.5M13 13H7.232c.176-.304.268-.649.268-1q0-.256-.076-.5H13.8a.8.8 0 0 1 .202.5A1 1 0 0 1 13 13"
199
+ })));
200
+ };
201
+
202
+ var _path$1;
203
+ function _extends$1() { return _extends$1 = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends$1.apply(null, arguments); }
204
+ var SvgTreeObject = function SvgTreeObject(props) {
205
+ return /*#__PURE__*/React.createElement("svg", _extends$1({
206
+ xmlns: "http://www.w3.org/2000/svg",
207
+ width: 16,
208
+ height: 16,
209
+ fill: "none"
210
+ }, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
211
+ fill: "currentColor",
212
+ d: "m13.98 4.134-5.5-3.009a.99.99 0 0 0-.96 0l-5.5 3.01a1 1 0 0 0-.52.876v5.977a1 1 0 0 0 .52.875l5.5 3.01a.99.99 0 0 0 .96 0l5.5-3.01a1 1 0 0 0 .52-.875V5.011a1 1 0 0 0-.52-.877M8 2l5.022 2.75-1.861 1.018-5.022-2.75zm0 5.5L2.978 4.75l2.12-1.16 5.021 2.75zm5.5 3.49-5 2.737V8.365l2-1.094V9.5a.5.5 0 0 0 1 0V6.723l2-1.095v5.363"
213
+ })));
214
+ };
215
+
216
+ var _path;
217
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
218
+ var SvgTreeOrg = function SvgTreeOrg(props) {
219
+ return /*#__PURE__*/React.createElement("svg", _extends({
220
+ xmlns: "http://www.w3.org/2000/svg",
221
+ width: 16,
222
+ height: 16,
223
+ fill: "none"
224
+ }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
225
+ fill: "currentColor",
226
+ d: "M14.983 13H14V6a1 1 0 0 0-1-1h-2.75a.25.25 0 0 0-.25.25V13H9V2.026a1.03 1.03 0 0 0-.385-.813 1 1 0 0 0-1.17-.043l-5 3.33A1 1 0 0 0 2 5.334V13h-.983a.51.51 0 0 0-.517.467A.5.5 0 0 0 1 14h14a.499.499 0 0 0 .333-.868.5.5 0 0 0-.35-.132M4.75 11.5a.5.5 0 0 1-.533.5.51.51 0 0 1-.467-.518v-.965A.51.51 0 0 1 4.217 10a.5.5 0 0 1 .533.5zm0-3.5a.5.5 0 0 1-.533.5.51.51 0 0 1-.467-.517v-.966a.51.51 0 0 1 .467-.517.5.5 0 0 1 .533.5zm2.5 3.5a.5.5 0 0 1-.533.5.51.51 0 0 1-.467-.516v-.967A.51.51 0 0 1 6.717 10a.5.5 0 0 1 .533.5zm0-3.5a.5.5 0 0 1-.533.5.51.51 0 0 1-.467-.516v-.967a.51.51 0 0 1 .467-.516.5.5 0 0 1 .533.5z"
227
+ })));
228
+ };
229
+
230
+ // 默认配置
231
+ var defaultConfig = {
232
+ timeout: 30000,
233
+ };
234
+ var Request = /** @class */ (function () {
235
+ function Request(config) {
236
+ var getAccessToken = config.getAccessToken, onUnauthorized = config.onUnauthorized, axiosConfig = __rest(config, ["getAccessToken", "onUnauthorized"]);
237
+ this.axiosInstance = axios.create(__assign(__assign({}, defaultConfig), axiosConfig));
238
+ this.axiosInstance.interceptors.request.use(this.requestInterceptor.bind(this));
239
+ this.axiosInstance.interceptors.response.use(this.responseSuccessInterceptor.bind(this), this.responseErrorInterceptor.bind(this));
240
+ this.getAccessToken = getAccessToken;
241
+ this.onUnauthorized = onUnauthorized;
242
+ }
243
+ // 请求拦截器
244
+ Request.prototype.requestInterceptor = function (axiosConfig) {
245
+ return __awaiter(this, void 0, void 0, function () {
246
+ var accessToken;
247
+ var _a;
248
+ return __generator(this, function (_b) {
249
+ switch (_b.label) {
250
+ case 0: return [4 /*yield*/, ((_a = this.getAccessToken) === null || _a === void 0 ? void 0 : _a.call(this))];
251
+ case 1:
252
+ accessToken = _b.sent();
253
+ if (accessToken) {
254
+ axiosConfig.headers.Authorization = "Bearer ".concat(accessToken);
255
+ }
256
+ return [2 /*return*/, Promise.resolve(axiosConfig)];
257
+ }
258
+ });
259
+ });
260
+ };
261
+ // 响应成功拦截器
262
+ Request.prototype.responseSuccessInterceptor = function (response) {
263
+ return __awaiter(this, void 0, void 0, function () {
264
+ var _a, code, data, msg;
265
+ return __generator(this, function (_b) {
266
+ _a = response.data, code = _a.code, data = _a.data, msg = _a.message;
267
+ if (code === 0) {
268
+ return [2 /*return*/, Promise.resolve(data)];
269
+ }
270
+ else {
271
+ message.error(msg || '服务器内部错误');
272
+ return [2 /*return*/, Promise.reject(msg || '服务器内部错误')];
273
+ }
274
+ });
275
+ });
276
+ };
277
+ // 响应错误拦截器
278
+ Request.prototype.responseErrorInterceptor = function (error) {
279
+ return __awaiter(this, void 0, void 0, function () {
280
+ var _a, status, data;
281
+ var _b;
282
+ return __generator(this, function (_c) {
283
+ _a = (error === null || error === void 0 ? void 0 : error.response) || {}, status = _a.status, data = _a.data;
284
+ if (status === 401) {
285
+ message.error('登录已过期,请重新登录');
286
+ (_b = this.onUnauthorized) === null || _b === void 0 ? void 0 : _b.call(this);
287
+ }
288
+ else if (status === 404) {
289
+ message.error('请求的资源不存在');
290
+ }
291
+ else {
292
+ message.error((data === null || data === void 0 ? void 0 : data.message) || '服务器内部错误');
293
+ }
294
+ return [2 /*return*/, Promise.reject(error)];
295
+ });
296
+ });
297
+ };
298
+ // GET
299
+ Request.prototype.get = function (url, config) {
300
+ return this.axiosInstance.get(url, config);
301
+ };
302
+ // POST
303
+ Request.prototype.post = function (url, data, config) {
304
+ return this.axiosInstance.post(url, data, config);
305
+ };
306
+ // PUT
307
+ Request.prototype.put = function (url, data, config) {
308
+ return this.axiosInstance.put(url, data, config);
309
+ };
310
+ // DELETE
311
+ Request.prototype.delete = function (url, config) {
312
+ return this.axiosInstance.delete(url, config);
313
+ };
314
+ return Request;
315
+ }());
316
+ var request = new Request({
317
+ baseURL: '/api/icos/desktop',
318
+ getAccessToken: function () { var _a, _b; return (_b = (_a = window._ICOS_DESKTOP_) === null || _a === void 0 ? void 0 : _a.getAccessToken) === null || _b === void 0 ? void 0 : _b.call(_a); },
319
+ });
320
+
321
+ // 获取知识体系编码
322
+ var getCategoryKsCode = function () {
323
+ return request.get('/v1/entity-manager/category-ks-code-map');
324
+ };
325
+
326
+ var useKsCode = function () {
327
+ // 加载完成
328
+ var _a = useState(false), loaded = _a[0], setLoaded = _a[1];
329
+ // 知识体系编码
330
+ var _b = useState(), ksCode = _b[0], setKsCode = _b[1];
331
+ useEffect(function () {
332
+ var _a;
333
+ if ((_a = window._ICOS_DESKTOP_) === null || _a === void 0 ? void 0 : _a.ksCode) {
334
+ setKsCode(window._ICOS_DESKTOP_.ksCode);
335
+ setLoaded(true);
336
+ return;
337
+ }
338
+ getCategoryKsCode().then(function (res) {
339
+ if (window._ICOS_DESKTOP_) {
340
+ window._ICOS_DESKTOP_.ksCode = res;
341
+ }
342
+ else {
343
+ window._ICOS_DESKTOP_ = { ksCode: res };
344
+ }
345
+ setKsCode(res);
346
+ setLoaded(true);
347
+ });
348
+ }, []);
349
+ return { loaded: loaded, ksCode: ksCode };
350
+ };
351
+
352
+ var judgeArrayEmpty = function (data) {
353
+ return (data === null || data === void 0 ? void 0 : data.length) ? data : undefined;
354
+ };
355
+ // 获取树勾选参数
356
+ var getTreeChecked = function (_a) {
357
+ var _treeData = _a.treeData, checkedKeys = _a.checkedKeys, halfCheckedKeys = _a.halfCheckedKeys;
358
+ if (!(_treeData === null || _treeData === void 0 ? void 0 : _treeData.length)) {
359
+ return {
360
+ info: {},
361
+ total: 0,
362
+ };
363
+ }
364
+ var treeData = _treeData[0].type === 'all' ? _treeData[0].children : _treeData;
365
+ var total = 0;
366
+ var senseObjCodes = [];
367
+ var bookIds = [];
368
+ var excludeBookIds = [];
369
+ var senseGlobalCodes = [];
370
+ var excludeGlobalCodes = [];
371
+ var orgIds = [];
372
+ // 获取节点勾选状态
373
+ var nodeChecked = function (node) {
374
+ var checked = checkedKeys.indexOf(node.key) !== -1;
375
+ var halfChecked = halfCheckedKeys.indexOf(node.key) !== -1;
376
+ return { checked: checked || halfChecked, halfChecked: halfChecked };
377
+ };
378
+ // 处理实体记录
379
+ var judgeSense = function (data, parent) {
380
+ if (!(data === null || data === void 0 ? void 0 : data.length)) {
381
+ return;
382
+ }
383
+ // 判断实体记录加载状态
384
+ var more = data.find(function (item) { return item.type === 'more'; });
385
+ if (more) {
386
+ // 实体记录未全部加载
387
+ // 判断未加载实体记录勾选状态
388
+ var moreChecked = checkedKeys.indexOf(more.key) !== -1;
389
+ if (moreChecked) {
390
+ // 未加载实体记录勾选
391
+ // 台账添加到 bookIds
392
+ // 未勾选实体记录添加到 excludeSenseGlobalCodes
393
+ // 判断父级类型
394
+ if (parent.type === 'senseObj') {
395
+ senseObjCodes.push(parent.key);
396
+ }
397
+ else if (parent.type === 'senseBook') {
398
+ bookIds.push(parent.key);
399
+ }
400
+ var excludeTotal_1 = 0;
401
+ data.forEach(function (item) {
402
+ if (item.type !== 'more') {
403
+ if (checkedKeys.indexOf(item.key) === -1) {
404
+ excludeGlobalCodes.push(item.key);
405
+ excludeTotal_1 += 1;
406
+ }
407
+ }
408
+ });
409
+ total += parent.total - excludeTotal_1;
410
+ }
411
+ else {
412
+ // 未加载实体记录未勾选
413
+ // 勾选的实体记录添加到 senseGlobalCodes
414
+ data.forEach(function (item) {
415
+ if (item !== 'more') {
416
+ if (checkedKeys.indexOf(item.key) !== -1) {
417
+ senseGlobalCodes.push(item.key);
418
+ total += 1;
419
+ }
420
+ }
421
+ });
422
+ }
423
+ }
424
+ else {
425
+ // 实体记录已全部加载
426
+ // 实体记录添加到 senseGlobalCodes
427
+ data.forEach(function (item) {
428
+ if (checkedKeys.indexOf(item.key) !== -1) {
429
+ senseGlobalCodes.push(item.key);
430
+ total += 1;
431
+ }
432
+ });
433
+ }
434
+ };
435
+ // 处理 台账
436
+ var judgeBook = function (data, parent) {
437
+ if (!(data === null || data === void 0 ? void 0 : data.length)) {
438
+ return;
439
+ }
440
+ // 判断台账加载情况
441
+ var more = data.find(function (item) { return item.type === 'more'; });
442
+ if (more) {
443
+ // 台账未全部加载
444
+ // 判断未加载部分台账勾选状态
445
+ var moreChecked = checkedKeys.indexOf(more.key) !== -1;
446
+ if (moreChecked) {
447
+ // 未加载台账勾选
448
+ // 实体分类添加到 senseObjCodes
449
+ senseObjCodes.push(parent.key);
450
+ // 判断已加载台账勾选状态
451
+ var excludeTotal_2 = 0;
452
+ data.forEach(function (item) {
453
+ if (item !== 'more') {
454
+ var _a = nodeChecked(item), checked = _a.checked, halfChecked = _a.halfChecked;
455
+ if (checked) {
456
+ if (halfChecked) {
457
+ // 已加载台账半勾选
458
+ judgeSense(item.children, item);
459
+ }
460
+ }
461
+ else {
462
+ // 已加载台账未勾选
463
+ // 台账添加到 excludeBookIds
464
+ excludeBookIds.push(item.key);
465
+ excludeTotal_2 += 1;
466
+ }
467
+ }
468
+ });
469
+ total += parent.total - excludeTotal_2;
470
+ }
471
+ else {
472
+ // 未加载台账未勾选
473
+ // 判断已加载台账勾选状态
474
+ data.forEach(function (item) {
475
+ if (item !== 'more') {
476
+ var _a = nodeChecked(item), checked = _a.checked, halfChecked = _a.halfChecked;
477
+ if (checked) {
478
+ if (halfChecked) {
479
+ // 已加载台账半勾选
480
+ judgeSense(item.children, item);
481
+ }
482
+ else {
483
+ // 已加载台账勾选
484
+ // 台账添加到 bookIds
485
+ bookIds.push(item.key);
486
+ total += item.total;
487
+ }
488
+ }
489
+ }
490
+ });
491
+ }
492
+ }
493
+ else {
494
+ // 台账已全部加载
495
+ data.forEach(function (item) {
496
+ // 判断台账勾选状态
497
+ var _a = nodeChecked(item), checked = _a.checked, halfChecked = _a.halfChecked;
498
+ if (checked) {
499
+ if (halfChecked) {
500
+ // 台账半勾选
501
+ judgeSense(item.children, item);
502
+ }
503
+ else {
504
+ // 台账全部勾选
505
+ // 台账添加到 bookIds
506
+ bookIds.push(item.key);
507
+ total += item.total;
508
+ }
509
+ }
510
+ });
511
+ }
512
+ };
513
+ // 处理 senseObj
514
+ var judgeSenseObj = function (data) {
515
+ if (!(data === null || data === void 0 ? void 0 : data.length)) {
516
+ return;
517
+ }
518
+ data.forEach(function (item) {
519
+ var _a;
520
+ if (item.type === 'senseObj') {
521
+ // 判断实体分类勾选状态
522
+ var _b = nodeChecked(item), checked = _b.checked, halfChecked = _b.halfChecked;
523
+ if (checked) {
524
+ if (halfChecked) {
525
+ // 实体分类半勾选
526
+ // 判断下级类型
527
+ if ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) {
528
+ if (item.children[0].type === 'senseBook') {
529
+ judgeBook(item.children, item);
530
+ }
531
+ else if (item.children[0].type === 'sense') {
532
+ judgeSense(item.children, item);
533
+ }
534
+ }
535
+ }
536
+ else {
537
+ // 实体分类全勾选
538
+ // 实体分类添加到 senseObjCodes
539
+ senseObjCodes.push(item.key);
540
+ total += item.total;
541
+ }
542
+ }
543
+ }
544
+ else if (item.type === 'senseType') {
545
+ judgeSenseObj(item.children);
546
+ }
547
+ });
548
+ };
549
+ // 处理政府通讯录
550
+ var judgeOrg = function (data) {
551
+ data.forEach(function (item) {
552
+ if (item.type === 'senseOrg') {
553
+ // 判断组织(senseOrg)勾选状态
554
+ var _a = nodeChecked(item), checked = _a.checked, halfChecked = _a.halfChecked;
555
+ if (checked) {
556
+ if (halfChecked) {
557
+ // 组织半勾选
558
+ judgeOrg(item.children);
559
+ }
560
+ else {
561
+ // 组织全勾选
562
+ // 添加到 orgIds
563
+ orgIds.push(item.key);
564
+ total += item.total;
565
+ }
566
+ }
567
+ }
568
+ else {
569
+ // 判断组织人员勾选状态
570
+ var checked = checkedKeys.indexOf(item.key) !== -1;
571
+ if (checked) {
572
+ senseGlobalCodes.push(item.key);
573
+ total += 1;
574
+ }
575
+ }
576
+ });
577
+ };
578
+ if (treeData[0].type === 'senseOrg') {
579
+ judgeOrg(treeData);
580
+ }
581
+ else {
582
+ judgeSenseObj(treeData);
583
+ }
584
+ return {
585
+ info: {
586
+ selectSenseObjCodes: judgeArrayEmpty(senseObjCodes),
587
+ selectBookIds: judgeArrayEmpty(bookIds),
588
+ unSelectBookIds: judgeArrayEmpty(excludeBookIds),
589
+ selectSenseGlobalCodes: judgeArrayEmpty(senseGlobalCodes),
590
+ unSelectSenseGlobalCodes: judgeArrayEmpty(excludeGlobalCodes),
591
+ selectOrgIds: judgeArrayEmpty(orgIds),
592
+ },
593
+ total: total,
594
+ };
595
+ };
596
+
597
+ // 根据key查找树节点
598
+ var findNodeByKey = function (tree, key) {
599
+ var stack = __spreadArray([], tree, true);
600
+ while (stack.length > 0) {
601
+ var node = stack.pop();
602
+ if (node.key === key) {
603
+ return node;
604
+ }
605
+ if (node.children) {
606
+ stack.push.apply(stack, node.children);
607
+ }
608
+ }
609
+ return null;
610
+ };
611
+ // 数组转树结构
612
+ var arrayToTree = function (array, loop, fieldNames) {
613
+ var tree = [];
614
+ var map = {};
615
+ var _a = (fieldNames || {}).children, childrenName = _a === void 0 ? 'children' : _a;
616
+ var data = cloneDeep(array);
617
+ for (var i = 0; i < data.length; i++) {
618
+ var item = loop(data[i]);
619
+ data[i] = item;
620
+ map[item.key] = item;
621
+ }
622
+ data.forEach(function (item) {
623
+ var parent = map[item.parentKey];
624
+ if (parent && parent.key !== item.key) {
625
+ (parent[childrenName] || (parent[childrenName] = [])).push(item);
626
+ }
627
+ else {
628
+ tree.push(item);
629
+ }
630
+ });
631
+ return tree;
632
+ };
633
+
634
+ // 获取组织树
635
+ var getOrgTree = function (data) {
636
+ return request.post('/v1/map-window/search/org-tree', data);
637
+ };
638
+ // 获取实体分类树
639
+ var getEntityClassTree = function (data) {
640
+ return request.post('/v1/map-window/search/entity-class-tree', data);
641
+ };
642
+ // 分页获取台账列表
643
+ var getBookList = function (data) {
644
+ return request.post('/v1/map-window/search/book-list', data);
645
+ };
646
+ // 分页获取实体记录列表
647
+ var getSenseList = function (data) {
648
+ return request.post('/v2/map-window/search/sense-list', data);
649
+ };
650
+
651
+ var css_248z = ".EntityTree-module_container__F8BNC {\n width: 100%;\n height: 100%;\n overflow-x: hidden;\n overflow-y: auto;\n}\n.EntityTree-module_container__F8BNC * {\n box-sizing: border-box;\n}\n.EntityTree-module_container__F8BNC .ant-spin-nested-loading {\n width: 100%;\n height: 100%;\n}\n.EntityTree-module_container__F8BNC .ant-tree {\n background: transparent;\n color: rgba(255, 255, 255, 0.8);\n}\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-node-content-wrapper:hover,\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-checkbox + span:hover,\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-switcher:not(.ant-tree-switcher-noop):hover:before {\n background: transparent;\n}\n.EntityTree-module_container__F8BNC .ant-tree.ant-tree-block-node .ant-tree-list-holder-inner .ant-tree-node-content-wrapper {\n width: 0;\n}\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode {\n align-items: center;\n padding: 0;\n min-height: 40px;\n}\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode .ant-tree-switcher {\n line-height: 40px;\n}\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode .ant-tree-checkbox {\n align-self: center;\n margin: 0;\n}\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode[data-type=\"root\"] {\n min-height: 32px;\n margin-bottom: 4px;\n background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAvUAAABACAMAAACtBHhQAAAAdVBMVEVAm/hDsvNDvPJCqPg/jPgAAAA8hv4+nvY/u+49ivxAtfI9jfo+lfg+mfdBsfNAqfNByu8/we8+kfo+xu89ovE+pPI+p/ZBsfI+tfA+kfs/nvc+ifxCnflAwvA9h/4+h/8xnsMoc65Cp/QjcZojbpkpdLIjb5ioMoMLAAAAJnRSTlMmJiYmJgBGQDhGOkZEQjs9NDZFNUA+LisuOjQ+Ki1CJkyiKuZflsDG+oIAAAsfSURB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HUMZ8ORqErJ+ghB30LiBvT6sjxqhuu95joWdlGE63vm6gJ8eVjUfZ2sOU96FArRr1eafXXnIs2U+ofTZVwg1H4v0e9Uu+Ww7TS10f4cuvP9q7ghyGYRAmwv//vGbJYqFqh2lA4xZrivIADznGBetc3mxDz1NrvYZN/APj+0E84BK6Ptu3xMQ/+5Ytx95x5h/gr294R9cv63KQPxFgvUGZOE4T7DUYzGV+4OPeSG7FR6231K/h9VtvK/lw3kQS+BYS5i4oObO+/+ZRAsfPxImBzJ8odSLhQNsjh9NRz1mCIM6AvDFupOONWzrOrMebthSORwon1rqUA8zqHmsbstlvu1T2Xhrn30ofxHus51llnkvRT/zSoyLycB6eSdAICC4ivAtn2zyWidPyYGs9btWZdSj1wTkcK26UzsXBt1SX9WZn8hLEL7/eI3UZCGLvxgj7a3qz37heJs6u1qXKPVjftvFwDvj9Ax4scODjBEJElDd0aT4WT6M/WF+1HvBT9VEmTmf64jxzyV9cl3FkAa/ZRfxivVOdD0zjyCR/h5KaOK2hPZv/mn0BGRZn7LppW7YAAAAASUVORK5CYII=');\n background-repeat: no-repeat;\n background-size: 100% 100%;\n}\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode[data-type=\"root\"] .ant-tree-title {\n color: #FFF;\n font-family: YouSheBiaoTiHei;\n font-size: 16px;\n font-style: normal;\n font-weight: 400;\n}\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode[data-type='more'] .ant-tree-switcher,\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode[data-type='more'] .ant-tree-checkbox {\n display: none;\n}\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode[data-type='sense'],\n.EntityTree-module_container__F8BNC .ant-tree .ant-tree-treenode[data-type='more'] {\n padding-top: 8px;\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-more__Zo2wM {\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 12px;\n color: #2bf2f8;\n column-gap: 4px;\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-default__iVIc- {\n display: flex;\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-default__iVIc- .EntityTree-module_title__BJnDv {\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-default__iVIc- .EntityTree-module_total__icLCA {\n flex-shrink: 0;\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-sense__s75ax {\n display: flex;\n flex-direction: column;\n row-gap: 12px;\n padding: 8px;\n background: rgba(69, 147, 255, 0.1);\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-sense__s75ax .EntityTree-module_title__BJnDv {\n display: flex;\n align-items: center;\n gap: 4px;\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-sense__s75ax .EntityTree-module_title__BJnDv > svg {\n width: 20px;\n height: 20px;\n flex-shrink: 0;\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-sense__s75ax .EntityTree-module_title__BJnDv > span {\n flex: 1;\n width: 0;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n.EntityTree-module_container__F8BNC .EntityTree-module_node-sense__s75ax .EntityTree-module_fields__jwWMe {\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n.EntityTree-module_node-sense-content__FHgPl {\n display: flex;\n flex-direction: column;\n max-width: 440px;\n}\n.EntityTree-module_highlight__QWIYs {\n background: transparent;\n color: #0FF;\n}\n";
652
+ var styles = {"container":"EntityTree-module_container__F8BNC","node-more":"EntityTree-module_node-more__Zo2wM","node-default":"EntityTree-module_node-default__iVIc-","title":"EntityTree-module_title__BJnDv","total":"EntityTree-module_total__icLCA","node-sense":"EntityTree-module_node-sense__s75ax","fields":"EntityTree-module_fields__jwWMe","node-sense-content":"EntityTree-module_node-sense-content__FHgPl","highlight":"EntityTree-module_highlight__QWIYs"};
653
+ styleInject(css_248z);
654
+
655
+ var EntityTree = function (props) {
656
+ var _a = props.viewCodes, viewCodes = _a === void 0 ? [] : _a, onTotalChange = props.onTotalChange, onCheck = props.onCheck, defaultCheckedAll = props.defaultCheckedAll;
657
+ var searchParams = {};
658
+ var ksCode = useKsCode().ksCode;
659
+ // 加载中
660
+ var _b = useState(false), loading = _b[0], setLoading = _b[1];
661
+ // 树数据
662
+ var _c = useState([]), treeData = _c[0], setTreeData = _c[1];
663
+ // 选中复选框的树节点
664
+ var _d = useState([]), checkedKeys = _d[0], setCheckedKeys = _d[1];
665
+ // 展开指定的树节点
666
+ var _f = useState([]), expandedKeys = _f[0], setExpandedKeys = _f[1];
667
+ // 渲染高亮
668
+ var keywordHighlight = function (text) {
669
+ return (searchParams === null || searchParams === void 0 ? void 0 : searchParams.keyword) ? (React__default.createElement(Highlighter, { highlightClassName: styles.highlight, searchWords: [searchParams.keyword], textToHighlight: text || '', autoEscape: true })) : (text);
670
+ };
671
+ // 获取图标
672
+ var getIcon = function (key) {
673
+ var _a;
674
+ if (ksCode) {
675
+ var iconMap = (_a = {},
676
+ _a[ksCode.person] = React__default.createElement(SvgTreePerson, null),
677
+ _a[ksCode.place] = React__default.createElement(SvgTreePlace, null),
678
+ _a[ksCode.event] = React__default.createElement(SvgTreeEvent, null),
679
+ _a[ksCode.object] = React__default.createElement(SvgTreeObject, null),
680
+ _a[ksCode.org] = React__default.createElement(SvgTreeOrg, null),
681
+ _a);
682
+ return iconMap[key];
683
+ }
684
+ };
685
+ // 获取实体记录列表
686
+ var getSenseList$1 = function (node) { return __awaiter(void 0, void 0, void 0, function () {
687
+ var isMore, isSenseOrg, reqId, parentKey, params, res, list, pageNum, total, moreChecked;
688
+ return __generator(this, function (_a) {
689
+ switch (_a.label) {
690
+ case 0:
691
+ isMore = node.type === 'more';
692
+ isSenseOrg = node.type === 'senseOrg';
693
+ reqId = isMore ? node.reqId : node.key;
694
+ parentKey = node.type === 'senseIcosBook' || isMore ? node.parentKey : reqId;
695
+ params = __assign(__assign({}, searchParams), { viewCodes: viewCodes, page: isMore ? node.morePage : 1, pageSize: 100 });
696
+ if (isSenseOrg) {
697
+ // 组织
698
+ params.orgIds = [reqId];
699
+ }
700
+ else {
701
+ // 台账
702
+ params.bookIds = [reqId];
703
+ }
704
+ // 加载更多loading动画
705
+ if (isMore) {
706
+ setTreeData(produce(function (draftState) {
707
+ var cur = findNodeByKey(draftState, node.key);
708
+ cur.loading = true;
709
+ }));
710
+ }
711
+ return [4 /*yield*/, getSenseList(params)];
712
+ case 1:
713
+ res = _a.sent();
714
+ list = res.list, pageNum = res.pageNum, total = res.total;
715
+ setTreeData(produce(function (draftState) {
716
+ var _a;
717
+ var cur = findNodeByKey(draftState, parentKey);
718
+ if (cur) {
719
+ var data = [];
720
+ if (cur.extraChildren) {
721
+ data.push.apply(data, cur.extraChildren);
722
+ }
723
+ data.push.apply(data, (list || []).map(function (item) { return ({
724
+ key: item.senseGlobalCode,
725
+ parentKey: parentKey,
726
+ ksCode: node.ksCode,
727
+ title: item.dataList[0].fieldValue,
728
+ dataList: item.dataList,
729
+ tagCodes: item.tagCodes,
730
+ tagNames: item.tagNames,
731
+ 'data-type': 'sense',
732
+ type: 'sense',
733
+ isLeaf: true,
734
+ dataRef: item,
735
+ }); }));
736
+ if (isMore) {
737
+ // 删除加载更多节点
738
+ cur.children.pop();
739
+ (_a = cur.children).push.apply(_a, data);
740
+ }
741
+ else {
742
+ cur.children = data;
743
+ }
744
+ if (cur.children.length < total) {
745
+ // 加载更多
746
+ var page = pageNum + 1;
747
+ cur.children.push({
748
+ key: "more__".concat(reqId, "__").concat(page),
749
+ parentKey: parentKey,
750
+ reqId: reqId,
751
+ ksCode: node.ksCode,
752
+ title: '加载更多',
753
+ morePage: page,
754
+ loading: false,
755
+ moreType: 'sense',
756
+ 'data-type': 'more',
757
+ type: 'more',
758
+ isLeaf: true,
759
+ });
760
+ }
761
+ }
762
+ }));
763
+ // 加载更多时勾选状态
764
+ if (isMore) {
765
+ moreChecked = checkedKeys.indexOf(node.key) !== -1;
766
+ if (moreChecked) {
767
+ setCheckedKeys(produce(function (draftState) {
768
+ draftState.push.apply(draftState, (list || []).map(function (item) { return item.senseGlobalCode; }));
769
+ }));
770
+ }
771
+ }
772
+ return [2 /*return*/];
773
+ }
774
+ });
775
+ }); };
776
+ // 获取台账列表
777
+ var getBookList$1 = function (node) { return __awaiter(void 0, void 0, void 0, function () {
778
+ var isMore, params, res, list, next, item, moreChecked;
779
+ return __generator(this, function (_a) {
780
+ switch (_a.label) {
781
+ case 0:
782
+ isMore = node.type === 'more';
783
+ params = __assign(__assign({}, searchParams), { viewCodes: viewCodes, senseObjCodes: [node.key], isMore: isMore });
784
+ // 加载更多
785
+ if (isMore) {
786
+ setTreeData(produce(function (draftState) {
787
+ var cur = findNodeByKey(draftState, node.key);
788
+ cur.loading = true;
789
+ }));
790
+ params.excludeBookIds = (function () {
791
+ var _a;
792
+ var data = (_a = findNodeByKey(treeData, node.key)) === null || _a === void 0 ? void 0 : _a.children;
793
+ if (data) {
794
+ return data.map(function (item) { return item.key; });
795
+ }
796
+ return [];
797
+ })();
798
+ }
799
+ return [4 /*yield*/, getBookList(params)];
800
+ case 1:
801
+ res = _a.sent();
802
+ list = res.list, next = res.next;
803
+ if (!((list === null || list === void 0 ? void 0 : list.length) && list[0].type === 'senseIcosBook')) return [3 /*break*/, 3];
804
+ item = list[0];
805
+ return [4 /*yield*/, getSenseList$1({
806
+ key: item.code,
807
+ parentKey: item.parentCode,
808
+ ksCode: node.ksCode,
809
+ type: item.type,
810
+ })];
811
+ case 2:
812
+ _a.sent();
813
+ return [2 /*return*/];
814
+ case 3:
815
+ setTreeData(produce(function (draftState) {
816
+ var _a;
817
+ var cur = findNodeByKey(draftState, node.key);
818
+ if (cur) {
819
+ var data = (list || []).map(function (item) { return ({
820
+ key: item.code,
821
+ parentKey: item.parentCode,
822
+ ksCode: node.ksCode,
823
+ title: item.name,
824
+ total: item.count,
825
+ 'data-type': item.type,
826
+ type: item.type,
827
+ isLeaf: !item.count,
828
+ dataRef: item,
829
+ }); });
830
+ if (isMore) {
831
+ // 删除加载更多节点
832
+ cur.children.pop();
833
+ (_a = cur.children).push.apply(_a, data);
834
+ }
835
+ else {
836
+ cur.children = data;
837
+ }
838
+ if (next) {
839
+ // 加载更多
840
+ cur.children.push({
841
+ key: "more__".concat(node.key, "__").concat(Date.now()),
842
+ parentKey: node.key,
843
+ ksCode: node.ksCode,
844
+ title: '加载更多',
845
+ loading: false,
846
+ moreType: 'senseBook',
847
+ 'data-type': 'more',
848
+ type: 'more',
849
+ isLeaf: true,
850
+ });
851
+ }
852
+ }
853
+ }));
854
+ // 加载更多时勾选状态
855
+ if (isMore) {
856
+ moreChecked = checkedKeys.indexOf(node.key) !== -1;
857
+ if (moreChecked) {
858
+ setCheckedKeys((list || []).map(function (item) { return item.code; }));
859
+ }
860
+ }
861
+ return [2 /*return*/];
862
+ }
863
+ });
864
+ }); };
865
+ // 获取实体分类
866
+ var getEntityClassTree$1 = function () { return __awaiter(void 0, void 0, void 0, function () {
867
+ var isGovUser, params, res, ksCategoryCode, data, total, children, keys;
868
+ var _a, _b;
869
+ return __generator(this, function (_c) {
870
+ switch (_c.label) {
871
+ case 0:
872
+ setLoading(true);
873
+ isGovUser = viewCodes.includes('system-icos_gov_user');
874
+ params = __assign(__assign({}, searchParams), { viewCodes: viewCodes });
875
+ return [4 /*yield*/, getEntityClassTree(params)];
876
+ case 1:
877
+ res = _c.sent();
878
+ if (!isGovUser) return [3 /*break*/, 3];
879
+ ksCategoryCode = (_a = res[0]) === null || _a === void 0 ? void 0 : _a.ksCategoryCode;
880
+ return [4 /*yield*/, getOrgTree(params)];
881
+ case 2:
882
+ res = _c.sent();
883
+ _c.label = 3;
884
+ case 3:
885
+ data = arrayToTree(res, function (item) { return ({
886
+ key: item.code,
887
+ parentKey: item.parentCode,
888
+ ksCode: ksCategoryCode || item.ksCategoryCode,
889
+ title: item.name,
890
+ total: item.count,
891
+ 'data-type': item.parentCode === '0000000000' ? 'root' : item.type,
892
+ type: item.type,
893
+ isLeaf: !item.count,
894
+ dataRef: item,
895
+ }); }, isGovUser ? { children: 'extraChildren' } : null);
896
+ if (isGovUser) {
897
+ data.forEach(function (item) {
898
+ item['data-type'] = 'root';
899
+ });
900
+ }
901
+ total = res.reduce(function (acc, item) {
902
+ return isGovUser || item.parentCode === '0000000000' ? acc + item.count : acc;
903
+ }, 0);
904
+ // 添加全部
905
+ if (data.length > 1) {
906
+ children = __spreadArray([], data, true);
907
+ data = [
908
+ {
909
+ key: 'all',
910
+ parentKey: '',
911
+ title: '全部',
912
+ total: total,
913
+ 'data-type': 'root',
914
+ type: 'all',
915
+ children: children.map(function (item) { return (__assign(__assign({}, item), { parentKey: 'all', 'data-type': item.type })); }),
916
+ },
917
+ ];
918
+ }
919
+ setTreeData(data);
920
+ onTotalChange === null || onTotalChange === void 0 ? void 0 : onTotalChange(total);
921
+ // 选中
922
+ if (defaultCheckedAll) {
923
+ keys = data.map(function (item) { return item.key; });
924
+ setCheckedKeys(keys);
925
+ onCheck === null || onCheck === void 0 ? void 0 : onCheck({ info: {}, total: total });
926
+ }
927
+ else {
928
+ setCheckedKeys([]);
929
+ onCheck === null || onCheck === void 0 ? void 0 : onCheck({ info: {}, total: 0 });
930
+ }
931
+ // 展开
932
+ if (((_b = data === null || data === void 0 ? void 0 : data[0]) === null || _b === void 0 ? void 0 : _b.type) === 'all') {
933
+ setExpandedKeys([data[0].key]);
934
+ }
935
+ else {
936
+ setExpandedKeys([]);
937
+ }
938
+ setLoading(false);
939
+ return [2 /*return*/];
940
+ }
941
+ });
942
+ }); };
943
+ // 懒加载树节点
944
+ var loadData = function (node) { return __awaiter(void 0, void 0, void 0, function () {
945
+ return __generator(this, function (_a) {
946
+ switch (_a.label) {
947
+ case 0:
948
+ if (node.children) {
949
+ return [2 /*return*/];
950
+ }
951
+ if (!(node.type === 'senseObj')) return [3 /*break*/, 2];
952
+ return [4 /*yield*/, getBookList$1(node)];
953
+ case 1:
954
+ _a.sent();
955
+ _a.label = 2;
956
+ case 2:
957
+ if (!(node.type === 'senseBook' || node.type === 'senseOrg')) return [3 /*break*/, 4];
958
+ return [4 /*yield*/, getSenseList$1(node)];
959
+ case 3:
960
+ _a.sent();
961
+ _a.label = 4;
962
+ case 4: return [2 /*return*/];
963
+ }
964
+ });
965
+ }); };
966
+ // 其他方法触发展开树节点
967
+ var otherExpand = function (key) {
968
+ var index = expandedKeys.indexOf(key);
969
+ if (index === -1) {
970
+ setExpandedKeys(produce(function (draftState) {
971
+ draftState.push(key);
972
+ }));
973
+ }
974
+ else {
975
+ setExpandedKeys(produce(function (draftState) {
976
+ draftState.splice(index, 1);
977
+ }));
978
+ }
979
+ };
980
+ // 点击树节点
981
+ var handleSelect = function (_keys, _a) {
982
+ var node = _a.node;
983
+ if (node.type === 'more') {
984
+ if (node.moreType === 'senseBook') {
985
+ getBookList$1(node);
986
+ }
987
+ if (node.moreType === 'sense') {
988
+ getSenseList$1(node);
989
+ }
990
+ }
991
+ else if (node.type !== 'sense') {
992
+ // 展开
993
+ otherExpand(node.key);
994
+ }
995
+ };
996
+ // 收起展开树节点
997
+ var handleExpand = function (keys) {
998
+ setExpandedKeys(keys);
999
+ };
1000
+ // 选择树节点
1001
+ var handleCheck = function (keys, info) {
1002
+ setCheckedKeys(keys);
1003
+ var checkedInfo = getTreeChecked({
1004
+ treeData: treeData,
1005
+ checkedKeys: keys,
1006
+ halfCheckedKeys: info.halfCheckedKeys,
1007
+ });
1008
+ onCheck === null || onCheck === void 0 ? void 0 : onCheck(checkedInfo);
1009
+ };
1010
+ // 树节点双击
1011
+ var handleDoubleClick = function (_e, node) {
1012
+ if (node.type === 'sense') ;
1013
+ };
1014
+ // 树节点标题渲染
1015
+ var titleRender = function (node) {
1016
+ var _a;
1017
+ if (node.type === 'more') {
1018
+ // 加载更多
1019
+ return (React__default.createElement("div", { className: styles['node-more'] },
1020
+ node.title,
1021
+ node.loading ? React__default.createElement(LoadingOutlined, null) : React__default.createElement(SvgDown, null)));
1022
+ }
1023
+ if (node.type === 'sense') {
1024
+ // 实体记录
1025
+ var tagText = ((_a = node.tagNames) === null || _a === void 0 ? void 0 : _a.length) ? node.tagNames.join(', ') : '';
1026
+ var content = (React__default.createElement("div", { className: styles['node-sense-content'] },
1027
+ (node.dataList || []).map(function (item) { return (React__default.createElement("div", { key: item.fieldId }, keywordHighlight("".concat(item.fieldName, "\uFF1A").concat(item.fieldValue)))); }),
1028
+ tagText ? React__default.createElement("div", null, keywordHighlight("\u6807\u7B7E\uFF1A".concat(tagText))) : null));
1029
+ var fields = (node.dataList || [])
1030
+ .map(function (item) { return "".concat(item.fieldName, "\uFF1A").concat(item.fieldValue); })
1031
+ .join(' ');
1032
+ if (tagText) {
1033
+ fields += " \u6807\u7B7E\uFF1A".concat(tagText);
1034
+ }
1035
+ return (React__default.createElement("div", { className: styles['node-sense'] },
1036
+ React__default.createElement("div", { className: styles.title, title: node.title },
1037
+ node.ksCode ? getIcon(node.ksCode) : null,
1038
+ React__default.createElement("span", null, keywordHighlight(node.title))),
1039
+ fields ? (React__default.createElement(Popover, { content: content },
1040
+ React__default.createElement("div", { className: styles.fields, title: "" }, keywordHighlight(fields)))) : null));
1041
+ }
1042
+ return (React__default.createElement("div", { className: styles['node-default'] },
1043
+ React__default.createElement("div", { className: styles.title }, keywordHighlight(node.title)),
1044
+ React__default.createElement("div", { className: styles.total },
1045
+ "\uFF08",
1046
+ node.total,
1047
+ "\uFF09")));
1048
+ };
1049
+ useUpdateEffect(function () {
1050
+ getEntityClassTree$1();
1051
+ }, [viewCodes]);
1052
+ return (React__default.createElement("div", { className: styles.container },
1053
+ React__default.createElement(Spin, { spinning: loading, delay: 500 },
1054
+ React__default.createElement(Tree, { treeData: treeData, titleRender: titleRender, loadData: loadData, selectedKeys: [], expandedKeys: expandedKeys, checkedKeys: checkedKeys, onSelect: handleSelect, onExpand: handleExpand, onCheck: handleCheck, onDoubleClick: handleDoubleClick,
1055
+ // onRightClick={handleRightClick as any}
1056
+ checkable: true, blockNode: true }))));
1057
+ };
1058
+
1059
+ export { EntityTree, TestComponent, configFn as config };
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@icos-desktop/react-components",
3
+ "version": "0.1.0",
4
+ "description": "ICOS Desktop React Components",
5
+ "module": "build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "files": [
8
+ "build"
9
+ ],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "scripts": {
14
+ "start": "rollup -c -w",
15
+ "build": "rollup -c",
16
+ "storybook": "storybook dev -p 6006",
17
+ "build-storybook": "storybook build",
18
+ "generate": "node ./util/create-component",
19
+ "prepublishOnly": "npm run build"
20
+ },
21
+ "dependencies": {
22
+ "@ant-design/icons": "^5.4.0",
23
+ "ahooks": "^3.8.0",
24
+ "antd": "^5.11.0",
25
+ "axios": "^1.6.0",
26
+ "immer": "^10.1.1",
27
+ "lodash": "^4.17.21",
28
+ "react-highlight-words": "^0.20.0"
29
+ },
30
+ "devDependencies": {
31
+ "@babel/core": "^7.25.2",
32
+ "@chromatic-com/storybook": "^1.6.1",
33
+ "@rollup/plugin-alias": "^5.1.0",
34
+ "@rollup/plugin-commonjs": "^26.0.1",
35
+ "@rollup/plugin-image": "^3.0.3",
36
+ "@rollup/plugin-json": "^6.1.0",
37
+ "@rollup/plugin-node-resolve": "^15.2.3",
38
+ "@rollup/plugin-typescript": "^11.1.6",
39
+ "@storybook/addon-essentials": "^8.2.9",
40
+ "@storybook/addon-interactions": "^8.2.9",
41
+ "@storybook/addon-links": "^8.2.9",
42
+ "@storybook/addon-onboarding": "^8.2.9",
43
+ "@storybook/blocks": "^8.2.9",
44
+ "@storybook/react": "^8.2.9",
45
+ "@storybook/react-vite": "^8.2.9",
46
+ "@storybook/test": "^8.2.9",
47
+ "@svgr/rollup": "^8.1.0",
48
+ "@types/lodash": "^4.17.7",
49
+ "@types/react": "^18.3.3",
50
+ "@types/react-dom": "^18.3.0",
51
+ "@types/react-highlight-words": "^0.20.0",
52
+ "@typescript-eslint/eslint-plugin": "^8.1.0",
53
+ "@typescript-eslint/parser": "^8.1.0",
54
+ "@vitejs/plugin-react": "^4.3.1",
55
+ "colors": "^1.4.0",
56
+ "eslint": "^8.57.0",
57
+ "eslint-plugin-react-hooks": "^4.6.2",
58
+ "eslint-plugin-storybook": "^0.8.0",
59
+ "less": "^4.2.0",
60
+ "postcss-url": "^10.1.3",
61
+ "prettier": "^3.3.3",
62
+ "react": "^18.3.1",
63
+ "react-dom": "^18.3.1",
64
+ "rollup": "^4.20.0",
65
+ "rollup-plugin-copy": "^3.5.0",
66
+ "rollup-plugin-delete": "^2.0.0",
67
+ "rollup-plugin-dts": "^6.1.1",
68
+ "rollup-plugin-peer-deps-external": "^2.2.4",
69
+ "rollup-plugin-postcss": "^4.0.2",
70
+ "storybook": "^8.2.9",
71
+ "tslib": "^2.6.3",
72
+ "typescript": "^5.5.4",
73
+ "vite": "^5.4.1",
74
+ "vite-plugin-svgr": "^4.2.0"
75
+ },
76
+ "peerDependencies": {
77
+ "react": ">=16.8.0",
78
+ "react-dom": ">=16.8.0"
79
+ }
80
+ }