approvalFlow.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { defineStore } from 'pinia';
  2. import { ref } from 'vue';
  3. import { useExecutionApi } from '@/api/execution';
  4. import to from 'await-to-js';
  5. const executionApi = useExecutionApi();
  6. export const useApprovalFlowStore = defineStore('approvalFlow', () => {
  7. // 审批记录列表(Execution.GetParticipantByProcInstID 返回的数据)
  8. const apprList = ref<any[]>([]);
  9. // 当前处于的节点(用于高亮)
  10. const currentNode = ref<string>('');
  11. // 加载状态
  12. const fetchLoading = ref<boolean>(false);
  13. /**
  14. * 根据流程实例ID获取审批记录
  15. * @param id 流程实例ID(procInstId)
  16. */
  17. async function fetchByProcInstId(id: number) {
  18. fetchLoading.value = true;
  19. apprList.value = [];
  20. currentNode.value = '';
  21. const [err, res] = await to(executionApi.getParticipantByProcInstID({ id })) as [any, any];
  22. fetchLoading.value = false;
  23. if (err) {
  24. console.error('获取审批记录失败:', err);
  25. return { success: false };
  26. }
  27. if (res && res.code === 200) {
  28. const arr = res.data || [];
  29. apprList.value = arr;
  30. // 简单规则:第一个审批中或尚未审批的节点作为当前节点
  31. const current = arr.find((item: any) => item.type !== 'start' && !item.approveResult);
  32. currentNode.value = current?.nodeId || '';
  33. return { success: true };
  34. }
  35. return { success: false };
  36. }
  37. return {
  38. apprList,
  39. currentNode,
  40. fetchLoading,
  41. fetchByProcInstId
  42. };
  43. });