openxiangda 1.0.146 → 1.0.147

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.
@@ -6316,6 +6316,21 @@ var import_react40 = require("react");
6316
6316
  var import_react37 = require("react");
6317
6317
  var import_antd16 = require("antd");
6318
6318
 
6319
+ // packages/sdk/src/components/fields/shared/departmentSearch.ts
6320
+ function canSearchAllDepartments(api, configuredTreeData) {
6321
+ return !configuredTreeData?.length && typeof api.searchDepartments === "function";
6322
+ }
6323
+ function normalizeDepartmentSearchItems(result) {
6324
+ const data = result?.data || result?.result || result;
6325
+ const source = Array.isArray(data) ? data : data?.items || data?.list || [];
6326
+ return source.map((item) => normalizeDepartmentNode(item)).filter((item) => item.id);
6327
+ }
6328
+ function getDepartmentPathText(department, separator = "/") {
6329
+ const path = Array.isArray(department?.path) ? department.path : [];
6330
+ const pathText = path.map((item) => item?.name).filter(Boolean).join(separator);
6331
+ return pathText || String(department?.fullPath || getDepartmentName(department) || "");
6332
+ }
6333
+
6319
6334
  // packages/sdk/src/components/fields/shared/DepartmentPicker.tsx
6320
6335
  var import_react36 = require("react");
6321
6336
  var import_antd15 = require("antd");
@@ -6330,7 +6345,11 @@ var getMobileComponent2 = (name) => {
6330
6345
  }
6331
6346
  };
6332
6347
  function normalizeSelection(items) {
6333
- return items.map((item) => ({ id: String(item.id || ""), name: String(item.name || item.id || "") })).filter((item) => item.id);
6348
+ return items.map((item) => ({
6349
+ id: String(item.id || ""),
6350
+ name: String(item.name || item.id || ""),
6351
+ fullPath: item.fullPath
6352
+ })).filter((item) => item.id);
6334
6353
  }
6335
6354
  function matchSearch(nodes, keyword) {
6336
6355
  if (!keyword) return nodes;
@@ -6351,7 +6370,12 @@ function DepartmentPickerPanel({
6351
6370
  treeData,
6352
6371
  onConfirm,
6353
6372
  onCancel,
6354
- mobile = false
6373
+ mobile = false,
6374
+ showSearch = true,
6375
+ searchScope = "loaded",
6376
+ showFullPath = false,
6377
+ searchMinLength = 1,
6378
+ searchDebounceMs = 300
6355
6379
  }) {
6356
6380
  const {
6357
6381
  treeData: loadedTreeData,
@@ -6365,11 +6389,53 @@ function DepartmentPickerPanel({
6365
6389
  const [selected, setSelected] = (0, import_react36.useState)(() => normalizeSelection(value));
6366
6390
  const [expandedKeys, setExpandedKeys] = (0, import_react36.useState)([]);
6367
6391
  const [currentDeptId, setCurrentDeptId] = (0, import_react36.useState)(null);
6392
+ const [remoteSearchResults, setRemoteSearchResults] = (0, import_react36.useState)([]);
6393
+ const [remoteSearchLoading, setRemoteSearchLoading] = (0, import_react36.useState)(false);
6394
+ const [remoteSearchError, setRemoteSearchError] = (0, import_react36.useState)("");
6395
+ const searchSeqRef = (0, import_react36.useRef)(0);
6368
6396
  const selectedIds = selected.map((item) => item.id);
6369
6397
  const MobileSearchBar = getMobileComponent2("SearchBar");
6398
+ const trimmedKeyword = keyword.trim();
6399
+ const canRemoteSearch = showSearch && searchScope === "all" && trimmedKeyword.length >= searchMinLength && canSearchAllDepartments(api, treeData);
6400
+ const spinning = treeLoading || remoteSearchLoading;
6401
+ (0, import_react36.useEffect)(() => {
6402
+ if (!canRemoteSearch) {
6403
+ searchSeqRef.current += 1;
6404
+ setRemoteSearchResults([]);
6405
+ setRemoteSearchLoading(false);
6406
+ setRemoteSearchError("");
6407
+ return;
6408
+ }
6409
+ const seq = searchSeqRef.current + 1;
6410
+ searchSeqRef.current = seq;
6411
+ setRemoteSearchLoading(true);
6412
+ setRemoteSearchError("");
6413
+ const timer = window.setTimeout(() => {
6414
+ api.searchDepartments?.({
6415
+ keyword: trimmedKeyword,
6416
+ page: 1,
6417
+ pageSize: 50,
6418
+ includePath: true
6419
+ }).then((result) => {
6420
+ if (searchSeqRef.current !== seq) return;
6421
+ setRemoteSearchResults(normalizeDepartmentSearchItems(result));
6422
+ }).catch((error) => {
6423
+ if (searchSeqRef.current !== seq) return;
6424
+ setRemoteSearchResults([]);
6425
+ setRemoteSearchError(error?.message || "\u641C\u7D22\u5931\u8D25");
6426
+ }).finally(() => {
6427
+ if (searchSeqRef.current === seq) {
6428
+ setRemoteSearchLoading(false);
6429
+ }
6430
+ });
6431
+ }, searchDebounceMs);
6432
+ return () => {
6433
+ window.clearTimeout(timer);
6434
+ };
6435
+ }, [api, canRemoteSearch, searchDebounceMs, trimmedKeyword]);
6370
6436
  const filteredTreeData = (0, import_react36.useMemo)(
6371
- () => matchSearch(loadedTreeData, keyword.trim()),
6372
- [keyword, loadedTreeData]
6437
+ () => showSearch ? matchSearch(loadedTreeData, trimmedKeyword) : loadedTreeData,
6438
+ [loadedTreeData, showSearch, trimmedKeyword]
6373
6439
  );
6374
6440
  const currentPath = (0, import_react36.useMemo)(() => {
6375
6441
  if (!currentDeptId) return [];
@@ -6384,13 +6450,36 @@ function DepartmentPickerPanel({
6384
6450
  return path;
6385
6451
  }, [currentDeptId, nodeMap, parentMap]);
6386
6452
  const mobileList = (0, import_react36.useMemo)(() => {
6387
- if (keyword.trim()) {
6388
- const lower = keyword.trim().toLowerCase();
6453
+ if (canRemoteSearch) {
6454
+ return remoteSearchResults;
6455
+ }
6456
+ if (showSearch && trimmedKeyword) {
6457
+ const lower = trimmedKeyword.toLowerCase();
6389
6458
  return flatNodes.filter((item) => item.name.toLowerCase().includes(lower)).map((item) => item.node);
6390
6459
  }
6391
6460
  if (!currentDeptId) return loadedTreeData;
6392
6461
  return nodeMap.get(currentDeptId)?.children || [];
6393
- }, [currentDeptId, flatNodes, keyword, loadedTreeData, nodeMap]);
6462
+ }, [
6463
+ canRemoteSearch,
6464
+ currentDeptId,
6465
+ flatNodes,
6466
+ loadedTreeData,
6467
+ nodeMap,
6468
+ remoteSearchResults,
6469
+ showSearch,
6470
+ trimmedKeyword
6471
+ ]);
6472
+ const getNodeValue = (node) => {
6473
+ const id = getDepartmentId(node);
6474
+ const name = getDepartmentName(node);
6475
+ const fullPath = getDepartmentPathText(node);
6476
+ return {
6477
+ id,
6478
+ name,
6479
+ ...fullPath && fullPath !== name ? { fullPath } : {}
6480
+ };
6481
+ };
6482
+ const getSelectedLabel = (item) => showFullPath ? item.fullPath || item.name : item.name;
6394
6483
  const upsertSelected = (department, checked) => {
6395
6484
  if (multiple) {
6396
6485
  setSelected((prev) => {
@@ -6407,14 +6496,14 @@ function DepartmentPickerPanel({
6407
6496
  const checkedKeys = Array.isArray(keys) ? keys : keys.checked;
6408
6497
  const next = checkedKeys.map((key) => {
6409
6498
  const node = nodeMap.get(String(key));
6410
- return node ? { id: getDepartmentId(node), name: getDepartmentName(node) } : void 0;
6499
+ return node ? getNodeValue(node) : void 0;
6411
6500
  }).filter(Boolean);
6412
6501
  setSelected(next);
6413
6502
  };
6414
6503
  const handleTreeSelect = (keys) => {
6415
6504
  const id = String(keys[0] || "");
6416
6505
  const node = id ? nodeMap.get(id) : void 0;
6417
- setSelected(node ? [{ id, name: getDepartmentName(node) }] : []);
6506
+ setSelected(node ? [getNodeValue(node)] : []);
6418
6507
  };
6419
6508
  const renderSelected = () => /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("div", { className: "sy-org-picker-selected", children: [
6420
6509
  /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("div", { className: "sy-org-picker-selected-head", children: [
@@ -6424,8 +6513,51 @@ function DepartmentPickerPanel({
6424
6513
  ] }),
6425
6514
  /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("button", { type: "button", onClick: () => setSelected([]), disabled: !selected.length, children: "\u6E05\u7A7A" })
6426
6515
  ] }),
6427
- selected.length ? /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("div", { className: "sy-org-picker-tags", children: selected.map((item) => /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.Tag, { closable: true, onClose: () => upsertSelected(item, false), children: item.name }, item.id)) }) : /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.Empty, { image: import_antd15.Empty.PRESENTED_IMAGE_SIMPLE, description: "\u6682\u65E0\u9009\u62E9" })
6516
+ selected.length ? /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("div", { className: "sy-org-picker-tags", children: selected.map((item) => /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.Tag, { closable: true, onClose: () => upsertSelected(item, false), children: getSelectedLabel(item) }, item.id)) }) : /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.Empty, { image: import_antd15.Empty.PRESENTED_IMAGE_SIMPLE, description: "\u6682\u65E0\u9009\u62E9" })
6428
6517
  ] });
6518
+ const renderRemoteSearchResults = () => /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6519
+ import_antd15.List,
6520
+ {
6521
+ dataSource: remoteSearchResults,
6522
+ locale: { emptyText: remoteSearchError || "\u6682\u65E0\u90E8\u95E8" },
6523
+ renderItem: (node) => {
6524
+ const id = getDepartmentId(node);
6525
+ const name = getDepartmentName(node);
6526
+ const selectedNow = selectedIds.includes(id);
6527
+ const pathText = getDepartmentPathText(node);
6528
+ return /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6529
+ import_antd15.List.Item,
6530
+ {
6531
+ onClick: () => upsertSelected(getNodeValue(node), true),
6532
+ actions: [
6533
+ /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6534
+ import_antd15.Checkbox,
6535
+ {
6536
+ checked: selectedNow,
6537
+ onChange: (event) => upsertSelected(getNodeValue(node), event.target.checked)
6538
+ },
6539
+ "select"
6540
+ )
6541
+ ],
6542
+ children: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6543
+ import_antd15.List.Item.Meta,
6544
+ {
6545
+ avatar: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_icons4.ApartmentOutlined, {}),
6546
+ title: /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("span", { children: [
6547
+ /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("span", { children: name }),
6548
+ showFullPath && pathText && pathText !== name ? /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("span", { className: "sy-org-picker-path", children: [
6549
+ " ",
6550
+ pathText
6551
+ ] }) : null
6552
+ ] })
6553
+ }
6554
+ )
6555
+ },
6556
+ id
6557
+ );
6558
+ }
6559
+ }
6560
+ );
6429
6561
  if (mobile) {
6430
6562
  return /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("div", { className: "sy-org-picker sy-org-picker-mobile", children: [
6431
6563
  /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("div", { className: "sy-org-picker-mobile-head", children: [
@@ -6433,7 +6565,7 @@ function DepartmentPickerPanel({
6433
6565
  /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("strong", { children: "\u9009\u62E9\u90E8\u95E8" }),
6434
6566
  /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("button", { type: "button", onClick: () => onConfirm(selected), children: "\u786E\u5B9A" })
6435
6567
  ] }),
6436
- MobileSearchBar ? /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(MobileSearchBar, { placeholder: "\u641C\u7D22\u90E8\u95E8", value: keyword, onChange: setKeyword }) : /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("input", { value: keyword, onChange: (event) => setKeyword(event.target.value) }),
6568
+ showSearch ? MobileSearchBar ? /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(MobileSearchBar, { placeholder: "\u641C\u7D22\u90E8\u95E8", value: keyword, onChange: setKeyword }) : /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("input", { value: keyword, onChange: (event) => setKeyword(event.target.value) }) : null,
6437
6569
  /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("div", { className: "sy-org-picker-breadcrumb", children: [
6438
6570
  /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("button", { type: "button", onClick: () => setCurrentDeptId(null), children: "\u90E8\u95E8" }),
6439
6571
  currentPath.map((item) => /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("button", { type: "button", onClick: () => setCurrentDeptId(item.id), children: [
@@ -6441,16 +6573,17 @@ function DepartmentPickerPanel({
6441
6573
  item.name
6442
6574
  ] }, item.id))
6443
6575
  ] }),
6444
- /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.Spin, { spinning: treeLoading, children: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6576
+ /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.Spin, { spinning, children: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6445
6577
  import_antd15.List,
6446
6578
  {
6447
6579
  dataSource: mobileList,
6448
- locale: { emptyText: "\u6682\u65E0\u90E8\u95E8" },
6580
+ locale: { emptyText: remoteSearchError || "\u6682\u65E0\u90E8\u95E8" },
6449
6581
  renderItem: (node) => {
6450
6582
  const id = getDepartmentId(node);
6451
6583
  const name = getDepartmentName(node);
6452
6584
  const selectedNow = selectedIds.includes(id);
6453
- const hasChildren = Boolean(node.hasChildren && !node.isLeaf);
6585
+ const hasChildren = !canRemoteSearch && Boolean(node.hasChildren && !node.isLeaf);
6586
+ const pathText = getDepartmentPathText(node);
6454
6587
  return /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6455
6588
  import_antd15.List.Item,
6456
6589
  {
@@ -6459,7 +6592,7 @@ function DepartmentPickerPanel({
6459
6592
  import_antd15.Checkbox,
6460
6593
  {
6461
6594
  checked: selectedNow,
6462
- onChange: (event) => upsertSelected({ id, name }, event.target.checked)
6595
+ onChange: (event) => upsertSelected(getNodeValue(node), event.target.checked)
6463
6596
  },
6464
6597
  "select"
6465
6598
  ),
@@ -6477,7 +6610,19 @@ function DepartmentPickerPanel({
6477
6610
  "children"
6478
6611
  ) : null
6479
6612
  ],
6480
- children: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.List.Item.Meta, { avatar: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_icons4.ApartmentOutlined, {}), title: name })
6613
+ children: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6614
+ import_antd15.List.Item.Meta,
6615
+ {
6616
+ avatar: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_icons4.ApartmentOutlined, {}),
6617
+ title: /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("span", { children: [
6618
+ /* @__PURE__ */ (0, import_jsx_runtime61.jsx)("span", { children: name }),
6619
+ showFullPath && pathText && pathText !== name ? /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("span", { className: "sy-org-picker-path", children: [
6620
+ " ",
6621
+ pathText
6622
+ ] }) : null
6623
+ ] })
6624
+ }
6625
+ )
6481
6626
  },
6482
6627
  id
6483
6628
  );
@@ -6490,7 +6635,7 @@ function DepartmentPickerPanel({
6490
6635
  return /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("div", { className: "sy-org-picker", children: [
6491
6636
  /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("div", { className: "sy-org-picker-main", children: [
6492
6637
  /* @__PURE__ */ (0, import_jsx_runtime61.jsxs)("div", { className: "sy-org-picker-tree", children: [
6493
- /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6638
+ showSearch ? /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6494
6639
  import_antd15.Input,
6495
6640
  {
6496
6641
  allowClear: true,
@@ -6499,8 +6644,8 @@ function DepartmentPickerPanel({
6499
6644
  value: keyword,
6500
6645
  onChange: (event) => setKeyword(event.target.value)
6501
6646
  }
6502
- ),
6503
- /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.Spin, { spinning: treeLoading, children: /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6647
+ ) : null,
6648
+ /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(import_antd15.Spin, { spinning, children: canRemoteSearch ? renderRemoteSearchResults() : /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
6504
6649
  import_antd15.Tree,
6505
6650
  {
6506
6651
  checkable: multiple,
@@ -6590,6 +6735,17 @@ function convertTreeData(nodes) {
6590
6735
  children: node.children ? convertTreeData(node.children) : void 0
6591
6736
  }));
6592
6737
  }
6738
+ function convertSearchTreeData(nodes, showFullPath) {
6739
+ return nodes.map((node) => {
6740
+ const name = getDepartmentName(node);
6741
+ const pathText = getDepartmentPathText(node);
6742
+ return {
6743
+ value: getDepartmentId(node),
6744
+ title: showFullPath && pathText ? pathText : name,
6745
+ isLeaf: true
6746
+ };
6747
+ });
6748
+ }
6593
6749
  function DepartmentSelectFieldPC({
6594
6750
  fieldId,
6595
6751
  behavior,
@@ -6599,6 +6755,11 @@ function DepartmentSelectFieldPC({
6599
6755
  treeData,
6600
6756
  allowClear = true,
6601
6757
  maxCount,
6758
+ notFoundContent,
6759
+ showSearch = true,
6760
+ searchScope = "loaded",
6761
+ searchMinLength = 1,
6762
+ searchDebounceMs = 300,
6602
6763
  showFullPath,
6603
6764
  scopeType,
6604
6765
  specifiedDepts,
@@ -6612,6 +6773,11 @@ function DepartmentSelectFieldPC({
6612
6773
  const remoteLoadedRef = (0, import_react37.useRef)(false);
6613
6774
  const [loadedTreeData, setLoadedTreeData] = (0, import_react37.useState)(configuredTreeData);
6614
6775
  const [pickerOpen, setPickerOpen] = (0, import_react37.useState)(false);
6776
+ const [searchKeyword, setSearchKeyword] = (0, import_react37.useState)("");
6777
+ const [remoteSearchResults, setRemoteSearchResults] = (0, import_react37.useState)([]);
6778
+ const [remoteSearchLoading, setRemoteSearchLoading] = (0, import_react37.useState)(false);
6779
+ const [selectedPathMap, setSelectedPathMap] = (0, import_react37.useState)({});
6780
+ const searchSeqRef = (0, import_react37.useRef)(0);
6615
6781
  (0, import_react37.useEffect)(() => {
6616
6782
  if (configuredTreeData.length) {
6617
6783
  setLoadedTreeData(configuredTreeData.map(normalizeDepartmentNode));
@@ -6623,22 +6789,87 @@ function DepartmentSelectFieldPC({
6623
6789
  (nodes) => setLoadedTreeData(nodes.map(normalizeDepartmentNode))
6624
6790
  );
6625
6791
  }, [api, configuredTreeData]);
6792
+ const trimmedSearchKeyword = searchKeyword.trim();
6793
+ const canRemoteSearch = showSearch && searchScope === "all" && trimmedSearchKeyword.length >= searchMinLength && canSearchAllDepartments(api, configuredTreeData);
6794
+ (0, import_react37.useEffect)(() => {
6795
+ if (!canRemoteSearch) {
6796
+ searchSeqRef.current += 1;
6797
+ setRemoteSearchResults([]);
6798
+ setRemoteSearchLoading(false);
6799
+ return;
6800
+ }
6801
+ const seq = searchSeqRef.current + 1;
6802
+ searchSeqRef.current = seq;
6803
+ setRemoteSearchLoading(true);
6804
+ const timer = window.setTimeout(() => {
6805
+ api.searchDepartments?.({
6806
+ keyword: trimmedSearchKeyword,
6807
+ page: 1,
6808
+ pageSize: 50,
6809
+ includePath: true
6810
+ }).then((result) => {
6811
+ if (searchSeqRef.current !== seq) return;
6812
+ setRemoteSearchResults(normalizeDepartmentSearchItems(result));
6813
+ }).catch(() => {
6814
+ if (searchSeqRef.current !== seq) return;
6815
+ setRemoteSearchResults([]);
6816
+ }).finally(() => {
6817
+ if (searchSeqRef.current === seq) {
6818
+ setRemoteSearchLoading(false);
6819
+ }
6820
+ });
6821
+ }, searchDebounceMs);
6822
+ return () => {
6823
+ window.clearTimeout(timer);
6824
+ };
6825
+ }, [api, canRemoteSearch, searchDebounceMs, trimmedSearchKeyword]);
6626
6826
  const scopedTreeData = filterTreeByScope(loadedTreeData, scopeType, specifiedDepts);
6627
6827
  const allDepts = flattenDepartments(scopedTreeData);
6828
+ const scopedRemoteSearchResults = (0, import_react37.useMemo)(() => {
6829
+ if (scopeType !== "specified" || !specifiedDepts?.length) {
6830
+ return remoteSearchResults;
6831
+ }
6832
+ const specifiedSet = new Set(specifiedDepts);
6833
+ return remoteSearchResults.filter((node) => {
6834
+ const id = getDepartmentId(node);
6835
+ if (specifiedSet.has(id)) return true;
6836
+ return node.path?.some((item) => specifiedSet.has(item.id));
6837
+ });
6838
+ }, [remoteSearchResults, scopeType, specifiedDepts]);
6839
+ const remoteDeptMap = (0, import_react37.useMemo)(() => {
6840
+ const map = /* @__PURE__ */ new Map();
6841
+ scopedRemoteSearchResults.forEach((node) => map.set(getDepartmentId(node), node));
6842
+ return map;
6843
+ }, [scopedRemoteSearchResults]);
6628
6844
  const handleChange = (selectedValue) => {
6629
6845
  const selectedValues = Array.isArray(selectedValue) ? selectedValue : selectedValue ? [selectedValue] : [];
6846
+ const nextPathMap = { ...selectedPathMap };
6630
6847
  const selected = selectedValues.map((item) => {
6631
6848
  const id = String(item?.value ?? item);
6632
6849
  const label = item?.label;
6633
- const matched = allDepts.find((dept) => dept.id === id) ?? value.find((dept) => getDepartmentId(dept) === id);
6850
+ const remoteDept = remoteDeptMap.get(id);
6851
+ const matched = remoteDept ?? allDepts.find((dept) => dept.id === id)?.node ?? value.find((dept) => getDepartmentId(dept) === id);
6852
+ if (remoteDept) {
6853
+ nextPathMap[id] = getDepartmentPathText(remoteDept);
6854
+ }
6634
6855
  const labelText = typeof label === "string" || typeof label === "number" ? String(label) : void 0;
6635
- return { id, name: labelText || matched?.name || id };
6856
+ return { id, name: getDepartmentName(matched) || labelText || id };
6636
6857
  }).filter((item) => item.id);
6637
6858
  const result = (multiple ? selected.slice(0, maxCount ?? selected.length) : selected.slice(0, 1)).map(toDepartmentValue);
6859
+ setSelectedPathMap(nextPathMap);
6638
6860
  setFieldValue(fieldId, result);
6639
6861
  onChange?.(result);
6640
6862
  };
6641
6863
  const handlePickerConfirm = (items) => {
6864
+ setSelectedPathMap((current) => {
6865
+ const next = { ...current };
6866
+ items.forEach((item) => {
6867
+ if (item.fullPath) {
6868
+ next[item.id] = String(item.fullPath);
6869
+ }
6870
+ });
6871
+ return next;
6872
+ });
6642
6873
  const result = (multiple ? items.slice(0, maxCount ?? items.length) : items.slice(0, 1)).map(
6643
6874
  toDepartmentValue
6644
6875
  );
@@ -6646,12 +6877,19 @@ function DepartmentSelectFieldPC({
6646
6877
  onChange?.(result);
6647
6878
  };
6648
6879
  const treeDataConverted = convertTreeData(scopedTreeData);
6880
+ const searchTreeDataConverted = convertSearchTreeData(scopedRemoteSearchResults, showFullPath);
6881
+ const renderedTreeData = canRemoteSearch ? searchTreeDataConverted : treeDataConverted;
6882
+ const getDisplayLabel2 = (dept) => {
6883
+ const id = getDepartmentId(dept);
6884
+ if (!showFullPath) return getDepartmentName(dept);
6885
+ return getDepartmentFullPath(id, scopedTreeData) || selectedPathMap[id] || (remoteDeptMap.has(id) ? getDepartmentPathText(remoteDeptMap.get(id)) : "") || getDepartmentName(dept);
6886
+ };
6649
6887
  const selectValue = multiple ? value.map((d) => ({
6650
6888
  value: getDepartmentId(d),
6651
- label: showFullPath ? getDepartmentFullPath(getDepartmentId(d), scopedTreeData) || getDepartmentName(d) : getDepartmentName(d)
6889
+ label: getDisplayLabel2(d)
6652
6890
  })) : value[0] ? {
6653
6891
  value: getDepartmentId(value[0]),
6654
- label: showFullPath ? getDepartmentFullPath(getDepartmentId(value[0]), scopedTreeData) || getDepartmentName(value[0]) : getDepartmentName(value[0])
6892
+ label: getDisplayLabel2(value[0])
6655
6893
  } : void 0;
6656
6894
  return /* @__PURE__ */ (0, import_jsx_runtime62.jsxs)("div", { className: "sy-select-with-picker", children: [
6657
6895
  /* @__PURE__ */ (0, import_jsx_runtime62.jsx)(
@@ -6663,9 +6901,14 @@ function DepartmentSelectFieldPC({
6663
6901
  maxCount,
6664
6902
  allowClear,
6665
6903
  labelInValue: true,
6666
- treeData: treeDataConverted,
6904
+ showSearch,
6905
+ searchValue: searchKeyword,
6906
+ onSearch: setSearchKeyword,
6907
+ filterTreeNode: canRemoteSearch ? false : void 0,
6908
+ treeData: renderedTreeData,
6667
6909
  value: selectValue,
6668
6910
  placeholder,
6911
+ notFoundContent: remoteSearchLoading ? "\u641C\u7D22\u4E2D..." : notFoundContent || "\u6682\u65E0\u90E8\u95E8",
6669
6912
  disabled,
6670
6913
  onChange: handleChange,
6671
6914
  loadData: async (node) => {
@@ -6709,6 +6952,11 @@ function DepartmentSelectFieldPC({
6709
6952
  multiple,
6710
6953
  value,
6711
6954
  treeData,
6955
+ showSearch,
6956
+ searchScope,
6957
+ showFullPath,
6958
+ searchMinLength,
6959
+ searchDebounceMs,
6712
6960
  onConfirm: handlePickerConfirm,
6713
6961
  onCancel: () => void 0
6714
6962
  }
@@ -6741,6 +6989,10 @@ function DepartmentSelectFieldMobile({
6741
6989
  treeData,
6742
6990
  allowClear = true,
6743
6991
  maxCount,
6992
+ showSearch = true,
6993
+ searchScope = "loaded",
6994
+ searchMinLength = 1,
6995
+ searchDebounceMs = 300,
6744
6996
  showFullPath,
6745
6997
  scopeType,
6746
6998
  specifiedDepts,
@@ -6828,6 +7080,11 @@ function DepartmentSelectFieldMobile({
6828
7080
  multiple,
6829
7081
  value,
6830
7082
  treeData,
7083
+ showSearch,
7084
+ searchScope,
7085
+ showFullPath,
7086
+ searchMinLength,
7087
+ searchDebounceMs,
6831
7088
  onConfirm: handleConfirm,
6832
7089
  onCancel: () => setShowPicker(false)
6833
7090
  }
@@ -10598,6 +10855,30 @@ function createFormRuntimeApi(config) {
10598
10855
  });
10599
10856
  return response.data || response.result || [];
10600
10857
  },
10858
+ searchDepartments: async (params) => {
10859
+ const page = params?.page ?? 1;
10860
+ const pageSize = params?.pageSize ?? 50;
10861
+ const response = await request({
10862
+ url: "/department/search",
10863
+ method: "get",
10864
+ params: {
10865
+ keyword: params?.keyword,
10866
+ page,
10867
+ pageSize,
10868
+ includePath: params?.includePath ?? true
10869
+ }
10870
+ });
10871
+ const data = response.data || response.result;
10872
+ if (Array.isArray(data)) {
10873
+ return { items: data, total: data.length, page, pageSize };
10874
+ }
10875
+ return {
10876
+ items: data?.items || data?.list || [],
10877
+ total: Number(data?.total ?? data?.count ?? data?.items?.length ?? 0),
10878
+ page: Number(data?.page ?? page),
10879
+ pageSize: Number(data?.pageSize ?? pageSize)
10880
+ };
10881
+ },
10601
10882
  getDepartmentParentDepartments: async (id) => {
10602
10883
  const response = await request({
10603
10884
  url: `/department/${id}/parentDepartments`,