workflow.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {defineStore} from "pinia";
  2. export const useWorkflowStore = defineStore('workflow', {
  3. state: () => ({
  4. graph: <any>null,
  5. panel: {
  6. node: <any>null,
  7. show: false
  8. },
  9. systemVars: [
  10. {label: '查询内容', key: 'sys.query', type: 'String'},
  11. {label: '用户ID', key: 'sys.user_id', type: 'String'},
  12. ]
  13. }),
  14. getters: {
  15. },
  16. actions: {
  17. init(graph) {
  18. this.graph = graph
  19. },
  20. nodePanel(node) {
  21. this.panel.node = node
  22. this.panel.show = true
  23. },
  24. nodePanelClose() {
  25. this.panel.node = null
  26. this.panel.show = false
  27. },
  28. layoutPort(nodeId: string, portId: string) {
  29. const dom = document.getElementById(portId)
  30. const node = this.graph.getCellById(nodeId)
  31. if (dom && node) {
  32. node.portProp(portId, ['args', 'dy'], dom.offsetTop + 17)
  33. }
  34. },
  35. getInVars(node) {
  36. const pathNodes = this.graph.getPredecessors(node).reverse()
  37. const options: any = []
  38. pathNodes.forEach(n => {
  39. const wd = n.data.workflowData
  40. const group = {
  41. label: wd.subTitle || wd.title,
  42. key: wd.id,
  43. options: [
  44. ...(wd.outVars?.map(v => {
  45. v.nodeId = wd.id
  46. return v
  47. }) || []),
  48. ...(wd.sysVars?.map(v => {
  49. v.nodeId = wd.id
  50. return v
  51. }) || []),
  52. ]
  53. }
  54. if (group.options.length > 0) {
  55. options.push(group)
  56. }
  57. })
  58. return options
  59. }
  60. },
  61. })