sy-form-components 0.2.4 → 0.2.5

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
@@ -418,13 +418,17 @@ interface ProcessAction {
418
418
  }
419
419
  /** 流程任务 */
420
420
  interface ProcessTask {
421
+ id?: string;
421
422
  taskId: string;
422
423
  nodeId: string;
423
424
  nodeVisitId?: string;
424
425
  nodeType: ProcessNodeType;
425
426
  nodeName: string;
427
+ title?: string;
426
428
  status: TaskStatus;
429
+ canApprove?: boolean;
427
430
  assigneeId?: string;
431
+ assignee?: string;
428
432
  assigneeName?: string;
429
433
  departmentName?: string;
430
434
  comments?: string;
@@ -450,6 +454,9 @@ interface ApprovalPermission {
450
454
  hasPermission: boolean;
451
455
  canUndo: boolean;
452
456
  isApprover: boolean;
457
+ currentTasks?: ProcessTask[];
458
+ futureTasksCount?: number;
459
+ details?: string;
453
460
  }
454
461
  /** 可退回节点 */
455
462
  interface ReturnableNode {
package/dist/index.d.ts CHANGED
@@ -418,13 +418,17 @@ interface ProcessAction {
418
418
  }
419
419
  /** 流程任务 */
420
420
  interface ProcessTask {
421
+ id?: string;
421
422
  taskId: string;
422
423
  nodeId: string;
423
424
  nodeVisitId?: string;
424
425
  nodeType: ProcessNodeType;
425
426
  nodeName: string;
427
+ title?: string;
426
428
  status: TaskStatus;
429
+ canApprove?: boolean;
427
430
  assigneeId?: string;
431
+ assignee?: string;
428
432
  assigneeName?: string;
429
433
  departmentName?: string;
430
434
  comments?: string;
@@ -450,6 +454,9 @@ interface ApprovalPermission {
450
454
  hasPermission: boolean;
451
455
  canUndo: boolean;
452
456
  isApprover: boolean;
457
+ currentTasks?: ProcessTask[];
458
+ futureTasksCount?: number;
459
+ details?: string;
453
460
  }
454
461
  /** 可退回节点 */
455
462
  interface ReturnableNode {
package/dist/index.js CHANGED
@@ -4453,21 +4453,65 @@ var TASK_STATUS_META = {
4453
4453
  };
4454
4454
 
4455
4455
  // src/core/processApi.ts
4456
+ var normalizeProcessTask = (value) => {
4457
+ const taskId = value?.taskId ?? value?.id ?? value?.task_id ?? "";
4458
+ return {
4459
+ ...value,
4460
+ id: value?.id ?? taskId,
4461
+ taskId,
4462
+ nodeId: value?.nodeId ?? value?.node_id ?? "",
4463
+ nodeType: value?.nodeType ?? value?.node_type ?? "approval",
4464
+ nodeName: value?.nodeName ?? value?.title ?? value?.name ?? value?.nodeId ?? "\u5BA1\u6279\u8282\u70B9",
4465
+ status: value?.status ?? "pending",
4466
+ assigneeId: value?.assigneeId ?? value?.assignee
4467
+ };
4468
+ };
4456
4469
  var normalizeProcessTasks = (value) => {
4457
- if (Array.isArray(value)) return value;
4470
+ if (Array.isArray(value)) return value.map(normalizeProcessTask);
4458
4471
  if (!value || typeof value !== "object") return [];
4459
- if (Array.isArray(value.tasks)) return value.tasks;
4460
- if (Array.isArray(value.list)) return value.list;
4461
- if (Array.isArray(value.items)) return value.items;
4462
- if (Array.isArray(value.records)) return value.records;
4472
+ if (Array.isArray(value.tasks)) return value.tasks.map(normalizeProcessTask);
4473
+ if (Array.isArray(value.currentTasks)) return value.currentTasks.map(normalizeProcessTask);
4474
+ if (Array.isArray(value.list)) return value.list.map(normalizeProcessTask);
4475
+ if (Array.isArray(value.items)) return value.items.map(normalizeProcessTask);
4476
+ if (Array.isArray(value.records)) return value.records.map(normalizeProcessTask);
4463
4477
  return [];
4464
4478
  };
4479
+ var normalizeProcessBasic = (value) => {
4480
+ const raw = value ?? {};
4481
+ const instance = raw.instance ?? raw;
4482
+ const currentTask = raw.currentTask ? normalizeProcessTask(raw.currentTask) : void 0;
4483
+ return {
4484
+ ...raw,
4485
+ instanceId: raw.instanceId ?? raw.id ?? instance.formInstanceId ?? instance.id,
4486
+ processStatus: raw.processStatus ?? raw.status ?? instance.processStatus ?? instance.status,
4487
+ formUuid: raw.formUuid ?? instance.formUuid ?? instance.definition?.formUuid,
4488
+ appType: raw.appType ?? instance.appType ?? instance.definition?.appType,
4489
+ title: raw.title ?? instance.title,
4490
+ originatorId: raw.originatorId ?? instance.originatorId ?? instance.startedBy,
4491
+ originatorName: raw.originatorName ?? instance.originatorName ?? instance.startedByName,
4492
+ originatorDepartment: raw.originatorDepartment ?? instance.originatorDepartment ?? instance.startedDepartmentName,
4493
+ createdAt: raw.createdAt ?? instance.createdAt ?? instance.startedAt,
4494
+ currentTask
4495
+ };
4496
+ };
4497
+ var normalizeApprovalPermission = (value) => {
4498
+ const raw = value ?? {};
4499
+ const currentTasks = normalizeProcessTasks(raw.currentTasks);
4500
+ const hasPermission = Boolean(raw.hasPermission ?? raw.isApprover ?? currentTasks.length > 0);
4501
+ return {
4502
+ ...raw,
4503
+ hasPermission,
4504
+ isApprover: Boolean(raw.isApprover ?? hasPermission),
4505
+ canUndo: Boolean(raw.canUndo ?? raw.canWithdraw),
4506
+ currentTasks
4507
+ };
4508
+ };
4465
4509
  async function getProcessBasic(request, formInstId) {
4466
4510
  const response = await request({
4467
4511
  url: `/workflow/instance/${formInstId}/basic`,
4468
4512
  method: "get"
4469
4513
  });
4470
- return response.data || response.result;
4514
+ return normalizeProcessBasic(response.data || response.result);
4471
4515
  }
4472
4516
  async function getProcessProgress(request, formInstId) {
4473
4517
  const response = await request({
@@ -4481,7 +4525,7 @@ async function checkUserApproval(request, formInstId) {
4481
4525
  url: `/workflow/instance/${formInstId}/permission`,
4482
4526
  method: "get"
4483
4527
  });
4484
- return response.data || response.result;
4528
+ return normalizeApprovalPermission(response.data || response.result);
4485
4529
  }
4486
4530
  async function handleApproval(request, params) {
4487
4531
  const response = await request({
@@ -5266,6 +5310,22 @@ function useFormDetail(options) {
5266
5310
 
5267
5311
  // src/hooks/useProcessDetail.ts
5268
5312
  var import_react46 = require("react");
5313
+ var DEFAULT_APPROVAL_ACTIONS = [
5314
+ { action: "agree", name: { zh_CN: "\u540C\u610F" } },
5315
+ { action: "rejected", name: { zh_CN: "\u62D2\u7EDD" } }
5316
+ ];
5317
+ var WITHDRAW_ACTION = { action: "withdraw", name: { zh_CN: "\u64A4\u9500" } };
5318
+ function mergeCurrentTask(processTask, approvalTask) {
5319
+ if (!approvalTask) return processTask ?? null;
5320
+ if (!processTask) return approvalTask;
5321
+ return {
5322
+ ...processTask,
5323
+ ...approvalTask,
5324
+ nodeName: processTask.nodeName || approvalTask.nodeName,
5325
+ title: processTask.title || approvalTask.title,
5326
+ actions: processTask.actions ?? approvalTask.actions
5327
+ };
5328
+ }
5269
5329
  function useProcessDetail(options) {
5270
5330
  const { formUuid, appType, formInstanceId, fieldIds } = options;
5271
5331
  const { api } = useFormContext();
@@ -5278,6 +5338,7 @@ function useProcessDetail(options) {
5278
5338
  const [instanceInfo, setInstanceInfo] = (0, import_react46.useState)(null);
5279
5339
  const [isApprover, setIsApprover] = (0, import_react46.useState)(false);
5280
5340
  const [canWithdraw, setCanWithdraw] = (0, import_react46.useState)(false);
5341
+ const [approvalTasks, setApprovalTasks] = (0, import_react46.useState)([]);
5281
5342
  const [permissions, setPermissions] = (0, import_react46.useState)(null);
5282
5343
  const [processDefinition, setProcessDefinition] = (0, import_react46.useState)(null);
5283
5344
  const mountedRef = (0, import_react46.useRef)(true);
@@ -5287,7 +5348,10 @@ function useProcessDetail(options) {
5287
5348
  mountedRef.current = false;
5288
5349
  };
5289
5350
  }, []);
5290
- const currentTask = processInfo?.currentTask ?? null;
5351
+ const currentTask = (0, import_react46.useMemo)(
5352
+ () => mergeCurrentTask(processInfo?.currentTask, approvalTasks[0]),
5353
+ [processInfo?.currentTask, approvalTasks]
5354
+ );
5291
5355
  const processStatus = processInfo?.processStatus ?? null;
5292
5356
  const isOriginatorReturn = currentTask?.nodeType === "originator_return";
5293
5357
  const isProcessCompleted = processStatus === "completed" || processStatus === "terminated";
@@ -5298,7 +5362,14 @@ function useProcessDetail(options) {
5298
5362
  isApprover,
5299
5363
  mode
5300
5364
  });
5301
- const activeActions = isApprover && currentTask?.actions ? currentTask.actions : [];
5365
+ const activeActions = (0, import_react46.useMemo)(() => {
5366
+ if (!isApprover) return [];
5367
+ const actions = currentTask?.actions && currentTask.actions.length > 0 ? [...currentTask.actions] : [...DEFAULT_APPROVAL_ACTIONS];
5368
+ if (canWithdraw && !actions.some((action) => action.action === "withdraw")) {
5369
+ actions.push(WITHDRAW_ACTION);
5370
+ }
5371
+ return actions;
5372
+ }, [isApprover, currentTask?.actions, canWithdraw]);
5302
5373
  const loadData = (0, import_react46.useCallback)(async () => {
5303
5374
  if (!mountedRef.current) return;
5304
5375
  setLoading(true);
@@ -5313,6 +5384,7 @@ function useProcessDetail(options) {
5313
5384
  setProcessInfo(basicResult);
5314
5385
  setIsApprover(approvalResult?.isApprover ?? false);
5315
5386
  setCanWithdraw(approvalResult?.canUndo ?? false);
5387
+ setApprovalTasks(approvalResult?.currentTasks ?? []);
5316
5388
  setPermissions(permResult);
5317
5389
  setInstanceInfo(formResult);
5318
5390
  setFormData(extractFormValues(formResult, fieldIds));
@@ -5343,6 +5415,7 @@ function useProcessDetail(options) {
5343
5415
  setProcessInfo(null);
5344
5416
  setFormData(null);
5345
5417
  setInstanceInfo(null);
5418
+ setApprovalTasks([]);
5346
5419
  }
5347
5420
  } finally {
5348
5421
  if (mountedRef.current) {
@@ -6073,8 +6146,9 @@ var ApprovalTimeline = ({
6073
6146
  return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: `bg-white rounded-xl shadow-sm border border-gray-100 p-6 ${className}`, children: /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("p", { className: "text-sm text-gray-400 text-center", children: "\u6682\u65E0\u5BA1\u6279\u8BB0\u5F55" }) });
6074
6147
  }
6075
6148
  return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: `${className}`, children: taskList.map((task, index) => {
6149
+ const taskKey = task.taskId || task.id || `${task.nodeId}-${index}`;
6076
6150
  if (renderNode) {
6077
- return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { children: renderNode(task, index) }, task.taskId);
6151
+ return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { children: renderNode(task, index) }, taskKey);
6078
6152
  }
6079
6153
  const phase = getNodePhase(task);
6080
6154
  const isLast = index === taskList.length - 1;
@@ -6131,7 +6205,7 @@ var ApprovalTimeline = ({
6131
6205
  ]
6132
6206
  }
6133
6207
  ) })
6134
- ] }, task.taskId);
6208
+ ] }, taskKey);
6135
6209
  }) });
6136
6210
  };
6137
6211
 
@@ -6976,7 +7050,7 @@ var InnerProcessContent = ({
6976
7050
  formInstanceId,
6977
7051
  formUuid,
6978
7052
  appType,
6979
- currentTaskId: currentTask?.taskId,
7053
+ currentTaskId: currentTask?.taskId ?? currentTask?.id,
6980
7054
  onActionComplete: async (action) => {
6981
7055
  onActionComplete?.(action);
6982
7056
  await refreshProgress();