sy-form-components 0.2.3 → 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,26 +4453,79 @@ 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
+ };
4469
+ var normalizeProcessTasks = (value) => {
4470
+ if (Array.isArray(value)) return value.map(normalizeProcessTask);
4471
+ if (!value || typeof value !== "object") return [];
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);
4477
+ return [];
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
+ };
4456
4509
  async function getProcessBasic(request, formInstId) {
4457
4510
  const response = await request({
4458
4511
  url: `/workflow/instance/${formInstId}/basic`,
4459
4512
  method: "get"
4460
4513
  });
4461
- return response.data || response.result;
4514
+ return normalizeProcessBasic(response.data || response.result);
4462
4515
  }
4463
4516
  async function getProcessProgress(request, formInstId) {
4464
4517
  const response = await request({
4465
- url: `/workflow/instance/${formInstId}`,
4518
+ url: `/workflow/instance/${formInstId}/all-tasks`,
4466
4519
  method: "get"
4467
4520
  });
4468
- return response.data || response.result || [];
4521
+ return normalizeProcessTasks(response.data || response.result);
4469
4522
  }
4470
4523
  async function checkUserApproval(request, formInstId) {
4471
4524
  const response = await request({
4472
4525
  url: `/workflow/instance/${formInstId}/permission`,
4473
4526
  method: "get"
4474
4527
  });
4475
- return response.data || response.result;
4528
+ return normalizeApprovalPermission(response.data || response.result);
4476
4529
  }
4477
4530
  async function handleApproval(request, params) {
4478
4531
  const response = await request({
@@ -5257,6 +5310,22 @@ function useFormDetail(options) {
5257
5310
 
5258
5311
  // src/hooks/useProcessDetail.ts
5259
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
+ }
5260
5329
  function useProcessDetail(options) {
5261
5330
  const { formUuid, appType, formInstanceId, fieldIds } = options;
5262
5331
  const { api } = useFormContext();
@@ -5269,6 +5338,7 @@ function useProcessDetail(options) {
5269
5338
  const [instanceInfo, setInstanceInfo] = (0, import_react46.useState)(null);
5270
5339
  const [isApprover, setIsApprover] = (0, import_react46.useState)(false);
5271
5340
  const [canWithdraw, setCanWithdraw] = (0, import_react46.useState)(false);
5341
+ const [approvalTasks, setApprovalTasks] = (0, import_react46.useState)([]);
5272
5342
  const [permissions, setPermissions] = (0, import_react46.useState)(null);
5273
5343
  const [processDefinition, setProcessDefinition] = (0, import_react46.useState)(null);
5274
5344
  const mountedRef = (0, import_react46.useRef)(true);
@@ -5278,7 +5348,10 @@ function useProcessDetail(options) {
5278
5348
  mountedRef.current = false;
5279
5349
  };
5280
5350
  }, []);
5281
- const currentTask = processInfo?.currentTask ?? null;
5351
+ const currentTask = (0, import_react46.useMemo)(
5352
+ () => mergeCurrentTask(processInfo?.currentTask, approvalTasks[0]),
5353
+ [processInfo?.currentTask, approvalTasks]
5354
+ );
5282
5355
  const processStatus = processInfo?.processStatus ?? null;
5283
5356
  const isOriginatorReturn = currentTask?.nodeType === "originator_return";
5284
5357
  const isProcessCompleted = processStatus === "completed" || processStatus === "terminated";
@@ -5289,7 +5362,14 @@ function useProcessDetail(options) {
5289
5362
  isApprover,
5290
5363
  mode
5291
5364
  });
5292
- 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]);
5293
5373
  const loadData = (0, import_react46.useCallback)(async () => {
5294
5374
  if (!mountedRef.current) return;
5295
5375
  setLoading(true);
@@ -5304,6 +5384,7 @@ function useProcessDetail(options) {
5304
5384
  setProcessInfo(basicResult);
5305
5385
  setIsApprover(approvalResult?.isApprover ?? false);
5306
5386
  setCanWithdraw(approvalResult?.canUndo ?? false);
5387
+ setApprovalTasks(approvalResult?.currentTasks ?? []);
5307
5388
  setPermissions(permResult);
5308
5389
  setInstanceInfo(formResult);
5309
5390
  setFormData(extractFormValues(formResult, fieldIds));
@@ -5334,6 +5415,7 @@ function useProcessDetail(options) {
5334
5415
  setProcessInfo(null);
5335
5416
  setFormData(null);
5336
5417
  setInstanceInfo(null);
5418
+ setApprovalTasks([]);
5337
5419
  }
5338
5420
  } finally {
5339
5421
  if (mountedRef.current) {
@@ -6059,15 +6141,17 @@ var ApprovalTimeline = ({
6059
6141
  showRemarks = true,
6060
6142
  compactMode = false
6061
6143
  }) => {
6062
- if (!tasks || tasks.length === 0) {
6144
+ const taskList = Array.isArray(tasks) ? tasks : [];
6145
+ if (taskList.length === 0) {
6063
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" }) });
6064
6147
  }
6065
- return /* @__PURE__ */ (0, import_jsx_runtime77.jsx)("div", { className: `${className}`, children: tasks.map((task, index) => {
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}`;
6066
6150
  if (renderNode) {
6067
- 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);
6068
6152
  }
6069
6153
  const phase = getNodePhase(task);
6070
- const isLast = index === tasks.length - 1;
6154
+ const isLast = index === taskList.length - 1;
6071
6155
  const statusMeta = TASK_STATUS_META[task.status];
6072
6156
  return /* @__PURE__ */ (0, import_jsx_runtime77.jsxs)("div", { className: "flex gap-4", children: [
6073
6157
  /* @__PURE__ */ (0, import_jsx_runtime77.jsxs)("div", { className: "flex flex-col items-center", children: [
@@ -6121,7 +6205,7 @@ var ApprovalTimeline = ({
6121
6205
  ]
6122
6206
  }
6123
6207
  ) })
6124
- ] }, task.taskId);
6208
+ ] }, taskKey);
6125
6209
  }) });
6126
6210
  };
6127
6211
 
@@ -6966,7 +7050,7 @@ var InnerProcessContent = ({
6966
7050
  formInstanceId,
6967
7051
  formUuid,
6968
7052
  appType,
6969
- currentTaskId: currentTask?.taskId,
7053
+ currentTaskId: currentTask?.taskId ?? currentTask?.id,
6970
7054
  onActionComplete: async (action) => {
6971
7055
  onActionComplete?.(action);
6972
7056
  await refreshProgress();