sy-form-components 0.2.9 → 0.2.10

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`,
@@ -9871,7 +9881,6 @@ import {
9871
9881
  Dropdown as Dropdown3,
9872
9882
  Empty as Empty5,
9873
9883
  Input as Input12,
9874
- InputNumber as InputNumber2,
9875
9884
  Modal as Modal8,
9876
9885
  Segmented,
9877
9886
  Select as Select6,
@@ -10019,6 +10028,74 @@ var fileToBase64 = (file) => new Promise((resolve, reject) => {
10019
10028
  reader.onerror = reject;
10020
10029
  reader.readAsDataURL(file);
10021
10030
  });
10031
+ var normalizeBasePath2 = (basePath) => {
10032
+ const normalized = String(basePath || "").replace(/^\/+|\/+$/g, "");
10033
+ return normalized ? `/${normalized}` : "";
10034
+ };
10035
+ var inferBasePath2 = (appType) => {
10036
+ if (typeof window === "undefined") return "";
10037
+ const pathname = window.location?.pathname || "";
10038
+ const marker = `/${appType}/`;
10039
+ const markerIndex = pathname.indexOf(marker);
10040
+ if (markerIndex <= 0) return "";
10041
+ return pathname.slice(0, markerIndex);
10042
+ };
10043
+ var buildDefaultDetailUrl = ({
10044
+ appType,
10045
+ formUuid,
10046
+ formType,
10047
+ formInstanceId,
10048
+ basePath
10049
+ }) => {
10050
+ const prefix = normalizeBasePath2(basePath ?? inferBasePath2(appType));
10051
+ const detailType = formType === "process" ? "processDetail" : "formDetail";
10052
+ return `${prefix}/${appType}/${detailType}/${formUuid}?formInstId=${encodeURIComponent(formInstanceId)}`;
10053
+ };
10054
+ var getHeaderValue = (headers, key) => {
10055
+ if (!headers) return "";
10056
+ if (typeof headers.get === "function")
10057
+ return headers.get(key) || headers.get(key.toLowerCase()) || "";
10058
+ return headers[key] || headers[key.toLowerCase()] || "";
10059
+ };
10060
+ var resolveDownloadFilename = (headers, fallbackName) => {
10061
+ const disposition = getHeaderValue(headers, "content-disposition");
10062
+ if (typeof disposition !== "string") return fallbackName;
10063
+ const matchStar = disposition.match(/filename\*=UTF-8''([^;]+)/i);
10064
+ if (matchStar?.[1]) return decodeURIComponent(matchStar[1]);
10065
+ const match = disposition.match(/filename="?([^";]+)"?/i);
10066
+ if (match?.[1]) return decodeURIComponent(match[1]);
10067
+ return fallbackName;
10068
+ };
10069
+ var downloadBlobResponse = async (response, fallbackName) => {
10070
+ if (typeof window === "undefined" || typeof document === "undefined") return;
10071
+ const headers = response?.headers;
10072
+ const payload = response?.data ?? response;
10073
+ const contentType = getHeaderValue(headers, "content-type") || payload?.type || "";
10074
+ const hasBlob = typeof Blob !== "undefined";
10075
+ if (hasBlob && payload instanceof Blob && String(contentType).includes("application/json")) {
10076
+ const text = await payload.text();
10077
+ try {
10078
+ const json = JSON.parse(text);
10079
+ throw new Error(json?.message || "\u4E0B\u8F7D\u5931\u8D25");
10080
+ } catch (error) {
10081
+ if (error instanceof SyntaxError) throw new Error("\u4E0B\u8F7D\u5931\u8D25");
10082
+ if (error instanceof Error) throw error;
10083
+ throw new Error("\u4E0B\u8F7D\u5931\u8D25");
10084
+ }
10085
+ }
10086
+ 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 ?? "")], {
10087
+ type: contentType || "application/octet-stream"
10088
+ });
10089
+ const filename = resolveDownloadFilename(headers, fallbackName);
10090
+ const url = window.URL.createObjectURL(blob);
10091
+ const anchor = document.createElement("a");
10092
+ anchor.href = url;
10093
+ anchor.download = filename;
10094
+ document.body.appendChild(anchor);
10095
+ anchor.click();
10096
+ anchor.remove();
10097
+ window.URL.revokeObjectURL(url);
10098
+ };
10022
10099
  function FilterGroupEditor({
10023
10100
  group,
10024
10101
  fields,
@@ -10178,12 +10255,16 @@ function ResizableColumnTitle({
10178
10255
  "span",
10179
10256
  {
10180
10257
  "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) => {
10258
+ 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",
10259
+ onClickCapture: (event) => {
10183
10260
  event.preventDefault();
10184
10261
  event.stopPropagation();
10185
10262
  },
10186
- onMouseDown: handleMouseDown,
10263
+ onDoubleClickCapture: (event) => {
10264
+ event.preventDefault();
10265
+ event.stopPropagation();
10266
+ },
10267
+ onMouseDownCapture: handleMouseDown,
10187
10268
  title: "\u62D6\u62FD\u8C03\u6574\u5217\u5BBD"
10188
10269
  }
10189
10270
  )
@@ -10192,6 +10273,7 @@ function ResizableColumnTitle({
10192
10273
  var DataManagementList = ({
10193
10274
  appType,
10194
10275
  formUuid,
10276
+ detailBasePath,
10195
10277
  menuFormUuid,
10196
10278
  readonly = false,
10197
10279
  fullHeight = true,
@@ -10238,6 +10320,7 @@ var DataManagementList = ({
10238
10320
  const [importOpen, setImportOpen] = useState35(false);
10239
10321
  const [importPreview, setImportPreview] = useState35([]);
10240
10322
  const [importBase64, setImportBase64] = useState35("");
10323
+ const [templateDownloading, setTemplateDownloading] = useState35(false);
10241
10324
  const [recordsOpen, setRecordsOpen] = useState35(false);
10242
10325
  const [recordTab, setRecordTab] = useState35("export");
10243
10326
  const [transferRecords, setTransferRecords] = useState35([]);
@@ -10333,7 +10416,6 @@ var DataManagementList = ({
10333
10416
  }).catch(() => void 0);
10334
10417
  if (!mounted) return;
10335
10418
  const resolved = normalizeColumnConfig(saved, allFields);
10336
- const resolvedDetailOpenMode = detailPageUrlBuilder ? resolved.detailOpenMode : "drawer";
10337
10419
  const nextSearchKeyWord = saved?.filter?.searchKeyWord || "";
10338
10420
  const nextFilterGroup = hydrateFilterGroup(saved?.filter?.group);
10339
10421
  setFields(allFields);
@@ -10344,7 +10426,7 @@ var DataManagementList = ({
10344
10426
  setLockFieldIds(resolved.lockFieldIds);
10345
10427
  setSort(resolved.sort);
10346
10428
  setDensity(resolved.density);
10347
- setDetailOpenMode(resolvedDetailOpenMode);
10429
+ setDetailOpenMode(resolved.detailOpenMode);
10348
10430
  setPageSize(resolved.pageSize);
10349
10431
  setSearchKeyWord(nextSearchKeyWord);
10350
10432
  setFilterGroup(nextFilterGroup);
@@ -10366,7 +10448,7 @@ var DataManagementList = ({
10366
10448
  return () => {
10367
10449
  mounted = false;
10368
10450
  };
10369
- }, [appType, configScope, detailPageUrlBuilder, formUuid, loadData, menuFormUuid, request]);
10451
+ }, [appType, configScope, formUuid, loadData, menuFormUuid, request]);
10370
10452
  const persistConfig = useCallback17(
10371
10453
  async (patch) => {
10372
10454
  const nextConfig = { ...config, ...patch };
@@ -10432,20 +10514,23 @@ var DataManagementList = ({
10432
10514
  message.warning("\u5F53\u524D\u8BB0\u5F55\u7F3A\u5C11\u5B9E\u4F8B ID\uFF0C\u65E0\u6CD5\u6253\u5F00\u8BE6\u60C5");
10433
10515
  return;
10434
10516
  }
10435
- if (detailOpenMode === "newPage" && detailPageUrlBuilder && typeof window !== "undefined") {
10436
- const detailUrl = detailPageUrlBuilder({ record, formInstanceId: String(formInstanceId) });
10517
+ if (detailOpenMode === "newPage" && typeof window !== "undefined") {
10518
+ const detailUrl = detailPageUrlBuilder?.({ record, formInstanceId: String(formInstanceId) }) || buildDefaultDetailUrl({
10519
+ appType,
10520
+ formUuid,
10521
+ formType,
10522
+ formInstanceId: String(formInstanceId),
10523
+ basePath: detailBasePath
10524
+ });
10437
10525
  if (detailUrl) {
10438
10526
  window.open(detailUrl, "_blank");
10439
10527
  return;
10440
10528
  }
10441
10529
  }
10442
- if (detailOpenMode === "newPage" && !detailPageUrlBuilder) {
10443
- setDetailOpenMode("drawer");
10444
- }
10445
10530
  setActiveRecord(record);
10446
10531
  setDetailOpen(true);
10447
10532
  },
10448
- [detailOpenMode, detailPageUrlBuilder]
10533
+ [appType, detailBasePath, detailOpenMode, detailPageUrlBuilder, formType, formUuid]
10449
10534
  );
10450
10535
  const handleDelete = useCallback17(
10451
10536
  async (ids) => {
@@ -10527,6 +10612,19 @@ var DataManagementList = ({
10527
10612
  setExporting(false);
10528
10613
  }
10529
10614
  };
10615
+ const handleDownloadTemplate = async () => {
10616
+ setTemplateDownloading(true);
10617
+ try {
10618
+ const response = await downloadDataManagementImportTemplate(request, { appType, formUuid });
10619
+ await downloadBlobResponse(response, `\u5BFC\u5165\u6A21\u677F-${formUuid}.xlsx`);
10620
+ message.success("\u6A21\u677F\u4E0B\u8F7D\u5DF2\u5F00\u59CB");
10621
+ } catch (error) {
10622
+ console.error("[DataManagementList] download template failed:", error);
10623
+ message.error(error instanceof Error ? error.message : "\u4E0B\u8F7D\u5BFC\u5165\u6A21\u677F\u5931\u8D25");
10624
+ } finally {
10625
+ setTemplateDownloading(false);
10626
+ }
10627
+ };
10530
10628
  const loadTransferRecords = async (type) => {
10531
10629
  setRecordTab(type);
10532
10630
  setRecordsOpen(true);
@@ -10578,7 +10676,6 @@ var DataManagementList = ({
10578
10676
  width: columnWidth,
10579
10677
  fixed: lockFieldIds.includes(field.fieldId) ? "left" : void 0,
10580
10678
  ellipsis: true,
10581
- sorter: true,
10582
10679
  render: (value) => renderCellValue(value, field)
10583
10680
  };
10584
10681
  }) || [];
@@ -10815,18 +10912,11 @@ var DataManagementList = ({
10815
10912
  showSizeChanger: true,
10816
10913
  showTotal: (count) => `\u5171 ${count} \u6761`
10817
10914
  },
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 });
10915
+ onChange: (pagination) => {
10826
10916
  loadData({
10827
10917
  current: pagination.current || 1,
10828
10918
  pageSize: pagination.pageSize || pageSize,
10829
- sort: nextSort
10919
+ sort
10830
10920
  });
10831
10921
  }
10832
10922
  }
@@ -10871,27 +10961,6 @@ var DataManagementList = ({
10871
10961
  }
10872
10962
  )
10873
10963
  ] }),
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
10964
  /* @__PURE__ */ jsxs41("div", { children: [
10896
10965
  /* @__PURE__ */ jsx89("div", { className: "mb-2 text-sm font-medium text-ant-color-text", children: "\u51BB\u7ED3\u5217" }),
10897
10966
  /* @__PURE__ */ jsx89(
@@ -10973,10 +11042,10 @@ var DataManagementList = ({
10973
11042
  {
10974
11043
  block: true,
10975
11044
  value: detailOpenMode,
10976
- options: detailPageUrlBuilder ? [
11045
+ options: [
10977
11046
  { label: "\u62BD\u5C49", value: "drawer" },
10978
11047
  { label: "\u65B0\u9875", value: "newPage" }
10979
- ] : [{ label: "\u62BD\u5C49", value: "drawer" }],
11048
+ ],
10980
11049
  onChange: (value) => setDetailOpenMode(value)
10981
11050
  }
10982
11051
  )
@@ -11082,6 +11151,21 @@ var DataManagementList = ({
11082
11151
  okButtonProps: { disabled: !importBase64 },
11083
11152
  okText: "\u786E\u8BA4\u5BFC\u5165",
11084
11153
  children: [
11154
+ /* @__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: [
11155
+ /* @__PURE__ */ jsxs41("div", { children: [
11156
+ /* @__PURE__ */ jsx89("div", { className: "text-sm font-medium text-ant-color-text", children: "\u5BFC\u5165\u6A21\u677F" }),
11157
+ /* @__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" })
11158
+ ] }),
11159
+ /* @__PURE__ */ jsx89(
11160
+ Button15,
11161
+ {
11162
+ icon: /* @__PURE__ */ jsx89(DownloadOutlined, {}),
11163
+ loading: templateDownloading,
11164
+ onClick: handleDownloadTemplate,
11165
+ children: "\u4E0B\u8F7D\u5BFC\u5165\u6A21\u677F"
11166
+ }
11167
+ )
11168
+ ] }),
11085
11169
  /* @__PURE__ */ jsx89(
11086
11170
  Upload3.Dragger,
11087
11171
  {
@@ -12113,6 +12197,7 @@ export {
12113
12197
  defineFormSchema,
12114
12198
  deleteDataManagementRows,
12115
12199
  deleteFormData,
12200
+ downloadDataManagementImportTemplate,
12116
12201
  evaluateEffects,
12117
12202
  exportDataManagementRows,
12118
12203
  extractFormValues,