@leadal/flowstream-ui-plus 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -670,7 +670,7 @@ const firstHandleNodes: FlowNode[] = result.data || []
670
670
  import flowstream from '@leadal/flowstream-ui-plus'
671
671
 
672
672
  async function submitBusiness() {
673
- await flowstream.getRuntimeService().start({
673
+ const result = await flowstream.getRuntimeService().start({
674
674
  processDefinitionId,
675
675
  draftUserId: currentUser.id,
676
676
  draftUserName: currentUser.name,
@@ -679,6 +679,17 @@ async function submitBusiness() {
679
679
  name: borrowTitle,
680
680
  },
681
681
  variables,
682
+ async onBeforeStart(startArgs) {
683
+ // 可执行同步校验,也可以 await 业务项目自己的表单弹窗。
684
+ const formData = await openBusinessForm()
685
+ if (!formData) return false
686
+ startArgs.variables = { ...startArgs.variables, ...formData }
687
+ return true
688
+ },
689
+ async onBeforeSend(context) {
690
+ // false:实例已经创建,但不打开审批人选择弹窗。
691
+ return validateBeforeSend(context)
692
+ },
682
693
  onStarted(result) {
683
694
  saveFlowRelation(result.processInstanceId)
684
695
  },
@@ -687,15 +698,52 @@ async function submitBusiness() {
687
698
  refreshBusinessList()
688
699
  },
689
700
  onClose() {
690
- // 关闭发送弹窗不会撤销已经启动的流程。
701
+ // 未发送就关闭弹窗时,运行时服务会撤销刚创建的流程实例。
691
702
  },
692
703
  onError(error) {
693
704
  console.error(error.phase, error.message)
694
705
  },
695
706
  })
707
+ if (result === false) return
696
708
  }
697
709
  ```
698
710
 
699
- `start()` 返回 `processInstanceId`、`processDefinitionId` 和起草人当前 `workId`。当前流程的发送弹窗关闭后,可调用 `flowstream.getRuntimeService().open()` 重新打开;调用 `close()` 只关闭弹窗,不撤销流程实例。`singleAssignee` 默认为 `true`,也可在启动参数中传入 `dialogTitle`、`dialogWidth`、`defaultOpinion` 和 `bpmnXml`。
711
+ `onBeforeStart` 在首办节点查询和 `quickStart` 之前执行;返回 `false` 时 `start()` 返回 `false`,不会创建流程实例。`onBeforeSend` 在实例创建成功后、发送弹窗打开前执行;返回 `false` `start()` 仍返回流程实例结果,但不会弹窗,并保留当前会话。之后调用 `await flowstream.getRuntimeService().open()` 会重新执行 `onBeforeSend`,通过后才打开弹窗;若决定放弃,调用 `close()` 会撤销该实例并释放会话。
712
+
713
+ 两个前置钩子都支持 `boolean | Promise<boolean>`。因此业务项目需要“弹表单、校验通过后再启动”时,应让业务弹窗封装成 Promise,而不是由流程组件识别业务字段:
714
+
715
+ ```ts
716
+ let finishBeforeStart: ((allowed: boolean) => void) | undefined
717
+
718
+ function waitForBusinessForm() {
719
+ businessDialogVisible.value = true
720
+ return new Promise<boolean>(resolve => {
721
+ finishBeforeStart = resolve
722
+ })
723
+ }
724
+
725
+ async function confirmBusinessForm() {
726
+ const valid = await businessFormRef.value?.validate().catch(() => false)
727
+ if (!valid) return
728
+ businessDialogVisible.value = false
729
+ finishBeforeStart?.(true)
730
+ finishBeforeStart = undefined
731
+ }
732
+
733
+ function cancelBusinessForm() {
734
+ businessDialogVisible.value = false
735
+ finishBeforeStart?.(false)
736
+ finishBeforeStart = undefined
737
+ }
738
+
739
+ await flowstream.getRuntimeService().start({
740
+ processDefinitionId,
741
+ draftUserId: currentUser.id,
742
+ draftUserName: currentUser.name,
743
+ onBeforeStart: waitForBusinessForm,
744
+ })
745
+ ```
746
+
747
+ 业务弹窗通过右上角关闭、路由离开或组件卸载时也必须 `resolve(false)`,避免 `start()` 一直处于等待状态。`singleAssignee` 默认为 `true`,也可在启动参数中传入 `dialogTitle`、`dialogWidth`、`defaultOpinion` 和 `bpmnXml`。
700
748
 
701
749
  `quickStart()`、`getFirstHandleNodes()`、`nextSendNode()`、`nodeAssistant()` 和 `sendTask()` 仍作为底层 API 导出,供组件内部及高级扩展使用;普通业务项目应优先调用 `flowstream.getRuntimeService().start()`,不要自行复制流程编排。