flow.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { defineStore } from 'pinia';
  2. import { ref } from 'vue';
  3. import { useFlowApi } from '@/api/flow/index';
  4. import to from 'await-to-js';
  5. const flowApi = useFlowApi();
  6. export const useFlowStore = defineStore('flow', () => {
  7. // 审批实例节点列表
  8. const apprList = ref<any[]>([]);
  9. // 当前处于的节点
  10. const currentNode = ref<string>('');
  11. // 加载状态
  12. const fetchFlowLoading = ref<boolean>(false);
  13. /**
  14. * 获取审批实例详情列表
  15. * @param id 表单ID
  16. * @param businessCode 单据编码
  17. * @param defCode 流程编码
  18. * @param memberList 额外的成员匹配列表(比如为了取templateContent)
  19. */
  20. async function fetchFlowInstance(id: number, businessCode: string, defCode: string, memberList: any[] = []) {
  21. fetchFlowLoading.value = true;
  22. apprList.value = [];
  23. currentNode.value = '';
  24. const params = { id, businessCode, defCode };
  25. const [err, res] = await to(flowApi.getFlowInstance(params)) as [any, any];
  26. fetchFlowLoading.value = false;
  27. if (err) {
  28. console.error('获取审批流实例失败:', err);
  29. return { success: false };
  30. }
  31. if (res && res.code === 200) {
  32. const arr = res.data?.nodes || [];
  33. // 匹配附加数据
  34. apprList.value = arr.map((item: any) => {
  35. const obj = memberList.find((i: any) => i.memberId === item.userId);
  36. return {
  37. ...item,
  38. templateContent: obj?.templateContent || null
  39. };
  40. });
  41. currentNode.value = res.data?.nodeId || '';
  42. return { success: true };
  43. }
  44. return { success: false };
  45. }
  46. return {
  47. apprList,
  48. currentNode,
  49. fetchFlowLoading,
  50. fetchFlowInstance
  51. };
  52. });