sy-form-components 0.2.1 → 0.2.2

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.d.mts CHANGED
@@ -93,6 +93,9 @@ interface FormEngineConfig {
93
93
  redirectUrl?: string;
94
94
  };
95
95
  api?: FormRuntimeApiConfig;
96
+ navigation?: {
97
+ basePath?: string;
98
+ };
96
99
  effects?: FormEffect[];
97
100
  }
98
101
  /** 字段联动效果 */
@@ -996,6 +999,7 @@ interface UseFormNavigationOptions {
996
999
  formType?: 'form' | 'process';
997
1000
  mode?: 'redirect' | 'stay' | 'callback';
998
1001
  redirectDelay?: number;
1002
+ basePath?: string;
999
1003
  onStay?: (formInstId: string) => void;
1000
1004
  }
1001
1005
  interface UseFormNavigationReturn {
@@ -1006,9 +1010,6 @@ interface UseFormNavigationReturn {
1006
1010
  countdown: number;
1007
1011
  cancelRedirect: () => void;
1008
1012
  }
1009
- /**
1010
- * 页面导航 hook
1011
- */
1012
1013
  declare function useFormNavigation(options: UseFormNavigationOptions): UseFormNavigationReturn;
1013
1014
 
1014
1015
  interface UseDraftStorageOptions {
package/dist/index.d.ts CHANGED
@@ -93,6 +93,9 @@ interface FormEngineConfig {
93
93
  redirectUrl?: string;
94
94
  };
95
95
  api?: FormRuntimeApiConfig;
96
+ navigation?: {
97
+ basePath?: string;
98
+ };
96
99
  effects?: FormEffect[];
97
100
  }
98
101
  /** 字段联动效果 */
@@ -996,6 +999,7 @@ interface UseFormNavigationOptions {
996
999
  formType?: 'form' | 'process';
997
1000
  mode?: 'redirect' | 'stay' | 'callback';
998
1001
  redirectDelay?: number;
1002
+ basePath?: string;
999
1003
  onStay?: (formInstId: string) => void;
1000
1004
  }
1001
1005
  interface UseFormNavigationReturn {
@@ -1006,9 +1010,6 @@ interface UseFormNavigationReturn {
1006
1010
  countdown: number;
1007
1011
  cancelRedirect: () => void;
1008
1012
  }
1009
- /**
1010
- * 页面导航 hook
1011
- */
1012
1013
  declare function useFormNavigation(options: UseFormNavigationOptions): UseFormNavigationReturn;
1013
1014
 
1014
1015
  interface UseDraftStorageOptions {
package/dist/index.js CHANGED
@@ -3793,7 +3793,12 @@ var CHUNK_UPLOAD_THRESHOLD = 10 * 1024 * 1024;
3793
3793
  var trimTrailingSlash = (value) => String(value || "").replace(/\/$/, "");
3794
3794
  var getDefaultBaseUrl = () => {
3795
3795
  const globalEnv = globalThis.process?.env;
3796
- return trimTrailingSlash(globalEnv?.FORM_API_BASE_URL || globalEnv?.BASE_API_URL || "");
3796
+ const envBaseUrl = globalEnv?.FORM_API_BASE_URL || globalEnv?.BASE_API_URL;
3797
+ if (envBaseUrl) return trimTrailingSlash(envBaseUrl);
3798
+ const browserGlobal = typeof window !== "undefined" ? window : void 0;
3799
+ const windowBaseUrl = browserGlobal?.FORM_API_BASE_URL || browserGlobal?.BASE_API_URL || browserGlobal?.__FORM_API_BASE_URL__ || browserGlobal?.__LOWCODE_API_BASE_URL__;
3800
+ if (windowBaseUrl) return trimTrailingSlash(windowBaseUrl);
3801
+ return typeof window !== "undefined" ? "/service" : "";
3797
3802
  };
3798
3803
  var appendQuery = (url, params) => {
3799
3804
  if (!params) return url;
@@ -5602,6 +5607,22 @@ function useChangeRecords(options) {
5602
5607
 
5603
5608
  // src/hooks/useFormNavigation.ts
5604
5609
  var import_react49 = require("react");
5610
+ var normalizeBasePath = (basePath) => {
5611
+ const normalized = String(basePath || "").replace(/^\/+|\/+$/g, "");
5612
+ return normalized ? `/${normalized}` : "";
5613
+ };
5614
+ var inferBasePath = (appType) => {
5615
+ if (typeof window === "undefined") return "";
5616
+ const pathname = window.location?.pathname || "";
5617
+ const marker = `/${appType}/`;
5618
+ const markerIndex = pathname.indexOf(marker);
5619
+ if (markerIndex <= 0) return "";
5620
+ return pathname.slice(0, markerIndex);
5621
+ };
5622
+ var buildDetailUrl = (appType, formUuid, formInstId, detailType, basePath) => {
5623
+ const prefix = normalizeBasePath(basePath ?? inferBasePath(appType));
5624
+ return `${prefix}/${appType}/${detailType}/${formUuid}?formInstId=${encodeURIComponent(formInstId)}`;
5625
+ };
5605
5626
  function useFormNavigation(options) {
5606
5627
  const {
5607
5628
  appType,
@@ -5609,6 +5630,7 @@ function useFormNavigation(options) {
5609
5630
  formType = "form",
5610
5631
  mode = "redirect",
5611
5632
  redirectDelay = 3e3,
5633
+ basePath,
5612
5634
  onStay
5613
5635
  } = options;
5614
5636
  const [isRedirecting, setIsRedirecting] = (0, import_react49.useState)(false);
@@ -5628,15 +5650,21 @@ function useFormNavigation(options) {
5628
5650
  }, []);
5629
5651
  const navigateToDetail = (0, import_react49.useCallback)(
5630
5652
  (formInstId) => {
5631
- window.location.href = `/${appType}/formDetail/${formUuid}?formInstId=${formInstId}`;
5653
+ window.location.href = buildDetailUrl(appType, formUuid, formInstId, "formDetail", basePath);
5632
5654
  },
5633
- [appType, formUuid]
5655
+ [appType, basePath, formUuid]
5634
5656
  );
5635
5657
  const navigateToProcessDetail = (0, import_react49.useCallback)(
5636
5658
  (formInstId) => {
5637
- window.location.href = `/${appType}/processDetail/${formUuid}?formInstId=${formInstId}`;
5659
+ window.location.href = buildDetailUrl(
5660
+ appType,
5661
+ formUuid,
5662
+ formInstId,
5663
+ "processDetail",
5664
+ basePath
5665
+ );
5638
5666
  },
5639
- [appType, formUuid]
5667
+ [appType, basePath, formUuid]
5640
5668
  );
5641
5669
  const startRedirectCountdown = (0, import_react49.useCallback)(
5642
5670
  (targetUrl) => {
@@ -5690,10 +5718,16 @@ function useFormNavigation(options) {
5690
5718
  onStay?.(formInstId);
5691
5719
  return;
5692
5720
  }
5693
- const targetUrl = formType === "process" ? `/${appType}/processDetail/${formUuid}?formInstId=${formInstId}` : `/${appType}/formDetail/${formUuid}?formInstId=${formInstId}`;
5721
+ const targetUrl = buildDetailUrl(
5722
+ appType,
5723
+ formUuid,
5724
+ formInstId,
5725
+ formType === "process" ? "processDetail" : "formDetail",
5726
+ basePath
5727
+ );
5694
5728
  startRedirectCountdown(targetUrl);
5695
5729
  },
5696
- [mode, formType, appType, formUuid, onStay, startRedirectCountdown]
5730
+ [mode, formType, appType, formUuid, basePath, onStay, startRedirectCountdown]
5697
5731
  );
5698
5732
  return {
5699
5733
  navigateToDetail,
@@ -6371,6 +6405,12 @@ var import_react54 = require("react");
6371
6405
  var import_antd27 = require("antd");
6372
6406
  var import_icons5 = require("@ant-design/icons");
6373
6407
  var import_jsx_runtime82 = require("react/jsx-runtime");
6408
+ var pickFormInstanceId = (value) => {
6409
+ if (!value) return void 0;
6410
+ if (typeof value === "string") return value;
6411
+ if (typeof value !== "object") return void 0;
6412
+ return value.formInstanceId || value.formInstId || value.instanceId || value.id || pickFormInstanceId(value.result) || pickFormInstanceId(value.data);
6413
+ };
6374
6414
  var SubmitSuccessCard = ({
6375
6415
  info,
6376
6416
  mode,
@@ -6420,7 +6460,7 @@ var InnerFormContent = ({
6420
6460
  renderSuccess,
6421
6461
  onSubmitSuccess
6422
6462
  }) => {
6423
- const { validateAll, getFormData: getFormData2, resetForm } = useFormContext();
6463
+ const { validateAll, getFormData: getFormData2, resetForm, api } = useFormContext();
6424
6464
  const [submitted, setSubmitted] = (0, import_react54.useState)(false);
6425
6465
  const [successInfo, setSuccessInfo] = (0, import_react54.useState)(null);
6426
6466
  const [submitting, setSubmitting] = (0, import_react54.useState)(false);
@@ -6432,7 +6472,8 @@ var InnerFormContent = ({
6432
6472
  appType: config.appType,
6433
6473
  formUuid: config.formUuid,
6434
6474
  formType,
6435
- mode: submitSuccessMode === "continue" ? "stay" : submitSuccessMode
6475
+ mode: submitSuccessMode === "continue" ? "stay" : submitSuccessMode,
6476
+ basePath: config.navigation?.basePath
6436
6477
  });
6437
6478
  const handleSubmit = (0, import_react54.useCallback)(async () => {
6438
6479
  const valid = await validateAll();
@@ -6447,9 +6488,24 @@ var InnerFormContent = ({
6447
6488
  return;
6448
6489
  }
6449
6490
  }
6450
- const formInstId = `inst_${Date.now()}`;
6491
+ const submitResponse = config.mode === "edit" && config.formInstanceId ? await api.updateFormData({
6492
+ appType: config.appType,
6493
+ formUuid: config.formUuid,
6494
+ formInstId: config.formInstanceId,
6495
+ formInstanceId: config.formInstanceId,
6496
+ updateFormDataJson: JSON.stringify(formData)
6497
+ }) : await api.submitFormData({
6498
+ appType: config.appType,
6499
+ formUuid: config.formUuid,
6500
+ data: formData
6501
+ });
6502
+ const formInstId = pickFormInstanceId(submitResponse) || config.formInstanceId || `inst_${Date.now()}`;
6451
6503
  if (config.submit?.afterSubmit) {
6452
- await config.submit.afterSubmit({ formInstanceId: formInstId, data: formData });
6504
+ await config.submit.afterSubmit({
6505
+ formInstanceId: formInstId,
6506
+ data: formData,
6507
+ response: submitResponse
6508
+ });
6453
6509
  }
6454
6510
  if (enableDraft) {
6455
6511
  clearDraft();
@@ -6471,6 +6527,7 @@ var InnerFormContent = ({
6471
6527
  validateAll,
6472
6528
  getFormData2,
6473
6529
  config,
6530
+ api,
6474
6531
  enableDraft,
6475
6532
  clearDraft,
6476
6533
  onSubmitSuccess,