sy-form-components 0.2.9 → 0.2.11

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/dist/index.mjs CHANGED
@@ -6999,6 +6999,16 @@ async function exportDataManagementRows(request, params) {
6999
6999
  }
7000
7000
  });
7001
7001
  }
7002
+ async function downloadDataManagementImportTemplate(request, params) {
7003
+ return request({
7004
+ url: `/${params.appType}/v1/form/advancedExportTemplate.xlsx`,
7005
+ method: "get",
7006
+ responseType: "blob",
7007
+ params: {
7008
+ formUuid: params.formUuid
7009
+ }
7010
+ });
7011
+ }
7002
7012
  async function importPreviewDataManagementRows(request, params) {
7003
7013
  const response = await request({
7004
7014
  url: `/${params.appType}/v1/form/importPreview.xlsx`,
@@ -7717,12 +7727,17 @@ function useFormDetail(options) {
7717
7727
  const [instanceInfo, setInstanceInfo] = useState24(null);
7718
7728
  const [permissions, setPermissions] = useState24(null);
7719
7729
  const mountedRef = useRef9(true);
7730
+ const onPermissionDeniedRef = useRef9(onPermissionDenied);
7731
+ const fieldIdsKey = fieldIds?.join("") ?? "";
7720
7732
  useEffect29(() => {
7721
7733
  mountedRef.current = true;
7722
7734
  return () => {
7723
7735
  mountedRef.current = false;
7724
7736
  };
7725
7737
  }, []);
7738
+ useEffect29(() => {
7739
+ onPermissionDeniedRef.current = onPermissionDenied;
7740
+ }, [onPermissionDenied]);
7726
7741
  const loadData = useCallback11(async () => {
7727
7742
  if (!mountedRef.current) return;
7728
7743
  setLoading(true);
@@ -7733,7 +7748,7 @@ function useFormDetail(options) {
7733
7748
  ]);
7734
7749
  if (!mountedRef.current) return;
7735
7750
  if (!permResult || !hasViewOperation(permResult.operations, "view")) {
7736
- onPermissionDenied?.();
7751
+ onPermissionDeniedRef.current?.();
7737
7752
  }
7738
7753
  const normalizedInfo = normalizeFormInstanceInfo(formResult, {
7739
7754
  formUuid,
@@ -7742,7 +7757,9 @@ function useFormDetail(options) {
7742
7757
  });
7743
7758
  setPermissions(permResult);
7744
7759
  setInstanceInfo(normalizedInfo);
7745
- setFormData(extractFormValues(formResult, fieldIds));
7760
+ setFormData(
7761
+ extractFormValues(formResult, fieldIdsKey ? fieldIdsKey.split("") : void 0)
7762
+ );
7746
7763
  } catch (error) {
7747
7764
  console.error("[useFormDetail] Failed to load data:", error);
7748
7765
  if (mountedRef.current) {
@@ -7755,7 +7772,7 @@ function useFormDetail(options) {
7755
7772
  setLoading(false);
7756
7773
  }
7757
7774
  }
7758
- }, [request, formUuid, appType, formInstanceId, fieldIds, onPermissionDenied]);
7775
+ }, [request, formUuid, appType, formInstanceId, fieldIdsKey]);
7759
7776
  useEffect29(() => {
7760
7777
  loadData();
7761
7778
  }, [loadData]);
@@ -7851,6 +7868,7 @@ function useProcessDetail(options) {
7851
7868
  const [permissions, setPermissions] = useState25(null);
7852
7869
  const [processDefinition, setProcessDefinition] = useState25(null);
7853
7870
  const mountedRef = useRef10(true);
7871
+ const fieldIdsKey = fieldIds?.join("") ?? "";
7854
7872
  useEffect30(() => {
7855
7873
  mountedRef.current = true;
7856
7874
  return () => {
@@ -7896,7 +7914,9 @@ function useProcessDetail(options) {
7896
7914
  setApprovalTasks(approvalResult?.currentTasks ?? []);
7897
7915
  setPermissions(permResult);
7898
7916
  setInstanceInfo(formResult);
7899
- setFormData(extractFormValues(formResult, fieldIds));
7917
+ setFormData(
7918
+ extractFormValues(formResult, fieldIdsKey ? fieldIdsKey.split("") : void 0)
7919
+ );
7900
7920
  if (permResult?.operations?.includes("VIEW_PROCESS") || permResult?.operations?.length > 0) {
7901
7921
  try {
7902
7922
  const progress = await getProcessProgress(request, formInstanceId);
@@ -7931,7 +7951,7 @@ function useProcessDetail(options) {
7931
7951
  setLoading(false);
7932
7952
  }
7933
7953
  }
7934
- }, [request, formUuid, appType, formInstanceId, fieldIds]);
7954
+ }, [request, formUuid, appType, formInstanceId, fieldIdsKey]);
7935
7955
  useEffect30(() => {
7936
7956
  loadData();
7937
7957
  }, [loadData]);
@@ -9871,7 +9891,6 @@ import {
9871
9891
  Dropdown as Dropdown3,
9872
9892
  Empty as Empty5,
9873
9893
  Input as Input12,
9874
- InputNumber as InputNumber2,
9875
9894
  Modal as Modal8,
9876
9895
  Segmented,
9877
9896
  Select as Select6,
@@ -10019,6 +10038,74 @@ var fileToBase64 = (file) => new Promise((resolve, reject) => {
10019
10038
  reader.onerror = reject;
10020
10039
  reader.readAsDataURL(file);
10021
10040
  });
10041
+ var normalizeBasePath2 = (basePath) => {
10042
+ const normalized = String(basePath || "").replace(/^\/+|\/+$/g, "");
10043
+ return normalized ? `/${normalized}` : "";
10044
+ };
10045
+ var inferBasePath2 = (appType) => {
10046
+ if (typeof window === "undefined") return "";
10047
+ const pathname = window.location?.pathname || "";
10048
+ const marker = `/${appType}/`;
10049
+ const markerIndex = pathname.indexOf(marker);
10050
+ if (markerIndex <= 0) return "";
10051
+ return pathname.slice(0, markerIndex);
10052
+ };
10053
+ var buildDefaultDetailUrl = ({
10054
+ appType,
10055
+ formUuid,
10056
+ formType,
10057
+ formInstanceId,
10058
+ basePath
10059
+ }) => {
10060
+ const prefix = normalizeBasePath2(basePath ?? inferBasePath2(appType));
10061
+ const detailType = formType === "process" ? "processDetail" : "formDetail";
10062
+ return `${prefix}/${appType}/${detailType}/${formUuid}?formInstId=${encodeURIComponent(formInstanceId)}`;
10063
+ };
10064
+ var getHeaderValue = (headers, key) => {
10065
+ if (!headers) return "";
10066
+ if (typeof headers.get === "function")
10067
+ return headers.get(key) || headers.get(key.toLowerCase()) || "";
10068
+ return headers[key] || headers[key.toLowerCase()] || "";
10069
+ };
10070
+ var resolveDownloadFilename = (headers, fallbackName) => {
10071
+ const disposition = getHeaderValue(headers, "content-disposition");
10072
+ if (typeof disposition !== "string") return fallbackName;
10073
+ const matchStar = disposition.match(/filename\*=UTF-8''([^;]+)/i);
10074
+ if (matchStar?.[1]) return decodeURIComponent(matchStar[1]);
10075
+ const match = disposition.match(/filename="?([^";]+)"?/i);
10076
+ if (match?.[1]) return decodeURIComponent(match[1]);
10077
+ return fallbackName;
10078
+ };
10079
+ var downloadBlobResponse = async (response, fallbackName) => {
10080
+ if (typeof window === "undefined" || typeof document === "undefined") return;
10081
+ const headers = response?.headers;
10082
+ const payload = response?.data ?? response;
10083
+ const contentType = getHeaderValue(headers, "content-type") || payload?.type || "";
10084
+ const hasBlob = typeof Blob !== "undefined";
10085
+ if (hasBlob && payload instanceof Blob && String(contentType).includes("application/json")) {
10086
+ const text = await payload.text();
10087
+ try {
10088
+ const json = JSON.parse(text);
10089
+ throw new Error(json?.message || "\u4E0B\u8F7D\u5931\u8D25");
10090
+ } catch (error) {
10091
+ if (error instanceof SyntaxError) throw new Error("\u4E0B\u8F7D\u5931\u8D25");
10092
+ if (error instanceof Error) throw error;
10093
+ throw new Error("\u4E0B\u8F7D\u5931\u8D25");
10094
+ }
10095
+ }
10096
+ const blob = hasBlob && payload instanceof Blob ? payload : hasBlob && payload instanceof ArrayBuffer ? new Blob([payload], { type: contentType || "application/octet-stream" }) : new Blob([typeof payload === "string" ? payload : JSON.stringify(payload ?? "")], {
10097
+ type: contentType || "application/octet-stream"
10098
+ });
10099
+ const filename = resolveDownloadFilename(headers, fallbackName);
10100
+ const url = window.URL.createObjectURL(blob);
10101
+ const anchor = document.createElement("a");
10102
+ anchor.href = url;
10103
+ anchor.download = filename;
10104
+ document.body.appendChild(anchor);
10105
+ anchor.click();
10106
+ anchor.remove();
10107
+ window.URL.revokeObjectURL(url);
10108
+ };
10022
10109
  function FilterGroupEditor({
10023
10110
  group,
10024
10111
  fields,
@@ -10178,12 +10265,16 @@ function ResizableColumnTitle({
10178
10265
  "span",
10179
10266
  {
10180
10267
  "aria-hidden": true,
10181
- className: "absolute -right-2 top-1/2 h-5 w-2 -translate-y-1/2 cursor-col-resize rounded hover:bg-ant-color-primary",
10182
- onClick: (event) => {
10268
+ className: "absolute -right-3 top-0 h-full w-4 cursor-col-resize after:absolute after:right-1 after:top-1/2 after:h-5 after:w-0.5 after:-translate-y-1/2 after:rounded after:bg-transparent hover:after:bg-ant-color-primary",
10269
+ onClickCapture: (event) => {
10183
10270
  event.preventDefault();
10184
10271
  event.stopPropagation();
10185
10272
  },
10186
- onMouseDown: handleMouseDown,
10273
+ onDoubleClickCapture: (event) => {
10274
+ event.preventDefault();
10275
+ event.stopPropagation();
10276
+ },
10277
+ onMouseDownCapture: handleMouseDown,
10187
10278
  title: "\u62D6\u62FD\u8C03\u6574\u5217\u5BBD"
10188
10279
  }
10189
10280
  )
@@ -10192,6 +10283,7 @@ function ResizableColumnTitle({
10192
10283
  var DataManagementList = ({
10193
10284
  appType,
10194
10285
  formUuid,
10286
+ detailBasePath,
10195
10287
  menuFormUuid,
10196
10288
  readonly = false,
10197
10289
  fullHeight = true,
@@ -10238,6 +10330,7 @@ var DataManagementList = ({
10238
10330
  const [importOpen, setImportOpen] = useState35(false);
10239
10331
  const [importPreview, setImportPreview] = useState35([]);
10240
10332
  const [importBase64, setImportBase64] = useState35("");
10333
+ const [templateDownloading, setTemplateDownloading] = useState35(false);
10241
10334
  const [recordsOpen, setRecordsOpen] = useState35(false);
10242
10335
  const [recordTab, setRecordTab] = useState35("export");
10243
10336
  const [transferRecords, setTransferRecords] = useState35([]);
@@ -10333,7 +10426,6 @@ var DataManagementList = ({
10333
10426
  }).catch(() => void 0);
10334
10427
  if (!mounted) return;
10335
10428
  const resolved = normalizeColumnConfig(saved, allFields);
10336
- const resolvedDetailOpenMode = detailPageUrlBuilder ? resolved.detailOpenMode : "drawer";
10337
10429
  const nextSearchKeyWord = saved?.filter?.searchKeyWord || "";
10338
10430
  const nextFilterGroup = hydrateFilterGroup(saved?.filter?.group);
10339
10431
  setFields(allFields);
@@ -10344,7 +10436,7 @@ var DataManagementList = ({
10344
10436
  setLockFieldIds(resolved.lockFieldIds);
10345
10437
  setSort(resolved.sort);
10346
10438
  setDensity(resolved.density);
10347
- setDetailOpenMode(resolvedDetailOpenMode);
10439
+ setDetailOpenMode(resolved.detailOpenMode);
10348
10440
  setPageSize(resolved.pageSize);
10349
10441
  setSearchKeyWord(nextSearchKeyWord);
10350
10442
  setFilterGroup(nextFilterGroup);
@@ -10366,7 +10458,7 @@ var DataManagementList = ({
10366
10458
  return () => {
10367
10459
  mounted = false;
10368
10460
  };
10369
- }, [appType, configScope, detailPageUrlBuilder, formUuid, loadData, menuFormUuid, request]);
10461
+ }, [appType, configScope, formUuid, loadData, menuFormUuid, request]);
10370
10462
  const persistConfig = useCallback17(
10371
10463
  async (patch) => {
10372
10464
  const nextConfig = { ...config, ...patch };
@@ -10432,20 +10524,23 @@ var DataManagementList = ({
10432
10524
  message.warning("\u5F53\u524D\u8BB0\u5F55\u7F3A\u5C11\u5B9E\u4F8B ID\uFF0C\u65E0\u6CD5\u6253\u5F00\u8BE6\u60C5");
10433
10525
  return;
10434
10526
  }
10435
- if (detailOpenMode === "newPage" && detailPageUrlBuilder && typeof window !== "undefined") {
10436
- const detailUrl = detailPageUrlBuilder({ record, formInstanceId: String(formInstanceId) });
10527
+ if (detailOpenMode === "newPage" && typeof window !== "undefined") {
10528
+ const detailUrl = detailPageUrlBuilder?.({ record, formInstanceId: String(formInstanceId) }) || buildDefaultDetailUrl({
10529
+ appType,
10530
+ formUuid,
10531
+ formType,
10532
+ formInstanceId: String(formInstanceId),
10533
+ basePath: detailBasePath
10534
+ });
10437
10535
  if (detailUrl) {
10438
10536
  window.open(detailUrl, "_blank");
10439
10537
  return;
10440
10538
  }
10441
10539
  }
10442
- if (detailOpenMode === "newPage" && !detailPageUrlBuilder) {
10443
- setDetailOpenMode("drawer");
10444
- }
10445
10540
  setActiveRecord(record);
10446
10541
  setDetailOpen(true);
10447
10542
  },
10448
- [detailOpenMode, detailPageUrlBuilder]
10543
+ [appType, detailBasePath, detailOpenMode, detailPageUrlBuilder, formType, formUuid]
10449
10544
  );
10450
10545
  const handleDelete = useCallback17(
10451
10546
  async (ids) => {
@@ -10527,6 +10622,19 @@ var DataManagementList = ({
10527
10622
  setExporting(false);
10528
10623
  }
10529
10624
  };
10625
+ const handleDownloadTemplate = async () => {
10626
+ setTemplateDownloading(true);
10627
+ try {
10628
+ const response = await downloadDataManagementImportTemplate(request, { appType, formUuid });
10629
+ await downloadBlobResponse(response, `\u5BFC\u5165\u6A21\u677F-${formUuid}.xlsx`);
10630
+ message.success("\u6A21\u677F\u4E0B\u8F7D\u5DF2\u5F00\u59CB");
10631
+ } catch (error) {
10632
+ console.error("[DataManagementList] download template failed:", error);
10633
+ message.error(error instanceof Error ? error.message : "\u4E0B\u8F7D\u5BFC\u5165\u6A21\u677F\u5931\u8D25");
10634
+ } finally {
10635
+ setTemplateDownloading(false);
10636
+ }
10637
+ };
10530
10638
  const loadTransferRecords = async (type) => {
10531
10639
  setRecordTab(type);
10532
10640
  setRecordsOpen(true);
@@ -10578,7 +10686,6 @@ var DataManagementList = ({
10578
10686
  width: columnWidth,
10579
10687
  fixed: lockFieldIds.includes(field.fieldId) ? "left" : void 0,
10580
10688
  ellipsis: true,
10581
- sorter: true,
10582
10689
  render: (value) => renderCellValue(value, field)
10583
10690
  };
10584
10691
  }) || [];
@@ -10815,18 +10922,11 @@ var DataManagementList = ({
10815
10922
  showSizeChanger: true,
10816
10923
  showTotal: (count) => `\u5171 ${count} \u6761`
10817
10924
  },
10818
- onChange: (pagination, _filters, sorter) => {
10819
- const sorters = Array.isArray(sorter) ? sorter : [sorter];
10820
- const nextSort = sorters.filter((item) => item?.field && item?.order).map((item) => ({
10821
- id: String(item.field),
10822
- isAsc: item.order === "ascend" ? "y" : "n"
10823
- }));
10824
- setSort(nextSort);
10825
- persistConfig({ sort: nextSort });
10925
+ onChange: (pagination) => {
10826
10926
  loadData({
10827
10927
  current: pagination.current || 1,
10828
10928
  pageSize: pagination.pageSize || pageSize,
10829
- sort: nextSort
10929
+ sort
10830
10930
  });
10831
10931
  }
10832
10932
  }
@@ -10871,27 +10971,6 @@ var DataManagementList = ({
10871
10971
  }
10872
10972
  )
10873
10973
  ] }),
10874
- /* @__PURE__ */ jsxs41("div", { children: [
10875
- /* @__PURE__ */ jsx89("div", { className: "mb-2 text-sm font-medium text-ant-color-text", children: "\u5217\u5BBD" }),
10876
- /* @__PURE__ */ jsx89("div", { className: "grid max-h-56 gap-2 overflow-auto rounded-lg border border-ant-border-secondary p-3 md:grid-cols-2", children: showFields.map((fieldId) => {
10877
- const field = fields.find((item) => item.fieldId === fieldId);
10878
- const width = widths[fieldId] || field?.width || 160;
10879
- return /* @__PURE__ */ jsxs41("div", { className: "flex items-center justify-between gap-3", children: [
10880
- /* @__PURE__ */ jsx89("span", { className: "min-w-0 truncate text-sm text-ant-color-text-secondary", children: field?.label || fieldId }),
10881
- /* @__PURE__ */ jsx89(
10882
- InputNumber2,
10883
- {
10884
- min: 96,
10885
- max: 520,
10886
- value: width,
10887
- addonAfter: "px",
10888
- onChange: (value) => updateColumnWidth(fieldId, Number(value || 160)),
10889
- onBlur: () => commitColumnWidth(fieldId, widthsRef.current[fieldId] || width)
10890
- }
10891
- )
10892
- ] }, fieldId);
10893
- }) })
10894
- ] }),
10895
10974
  /* @__PURE__ */ jsxs41("div", { children: [
10896
10975
  /* @__PURE__ */ jsx89("div", { className: "mb-2 text-sm font-medium text-ant-color-text", children: "\u51BB\u7ED3\u5217" }),
10897
10976
  /* @__PURE__ */ jsx89(
@@ -10973,10 +11052,10 @@ var DataManagementList = ({
10973
11052
  {
10974
11053
  block: true,
10975
11054
  value: detailOpenMode,
10976
- options: detailPageUrlBuilder ? [
11055
+ options: [
10977
11056
  { label: "\u62BD\u5C49", value: "drawer" },
10978
11057
  { label: "\u65B0\u9875", value: "newPage" }
10979
- ] : [{ label: "\u62BD\u5C49", value: "drawer" }],
11058
+ ],
10980
11059
  onChange: (value) => setDetailOpenMode(value)
10981
11060
  }
10982
11061
  )
@@ -11082,6 +11161,21 @@ var DataManagementList = ({
11082
11161
  okButtonProps: { disabled: !importBase64 },
11083
11162
  okText: "\u786E\u8BA4\u5BFC\u5165",
11084
11163
  children: [
11164
+ /* @__PURE__ */ jsxs41("div", { className: "mb-3 flex flex-col gap-3 rounded-lg border border-ant-border-secondary bg-ant-bg-container px-4 py-3 md:flex-row md:items-center md:justify-between", children: [
11165
+ /* @__PURE__ */ jsxs41("div", { children: [
11166
+ /* @__PURE__ */ jsx89("div", { className: "text-sm font-medium text-ant-color-text", children: "\u5BFC\u5165\u6A21\u677F" }),
11167
+ /* @__PURE__ */ jsx89("div", { className: "mt-1 text-xs text-ant-color-text-secondary", children: "\u5148\u4E0B\u8F7D\u6A21\u677F\u586B\u5199\u6570\u636E\uFF0C\u518D\u4E0A\u4F20 Excel \u6587\u4EF6\u5BFC\u5165" })
11168
+ ] }),
11169
+ /* @__PURE__ */ jsx89(
11170
+ Button15,
11171
+ {
11172
+ icon: /* @__PURE__ */ jsx89(DownloadOutlined, {}),
11173
+ loading: templateDownloading,
11174
+ onClick: handleDownloadTemplate,
11175
+ children: "\u4E0B\u8F7D\u5BFC\u5165\u6A21\u677F"
11176
+ }
11177
+ )
11178
+ ] }),
11085
11179
  /* @__PURE__ */ jsx89(
11086
11180
  Upload3.Dragger,
11087
11181
  {
@@ -12113,6 +12207,7 @@ export {
12113
12207
  defineFormSchema,
12114
12208
  deleteDataManagementRows,
12115
12209
  deleteFormData,
12210
+ downloadDataManagementImportTemplate,
12116
12211
  evaluateEffects,
12117
12212
  exportDataManagementRows,
12118
12213
  extractFormValues,