index.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { GraphNode } from '@vue-flow/core';
  2. import { defineStore } from 'pinia';
  3. import { getPin, Pin } from '@/views/flow/store/get';
  4. import { Component, shallowRef, toRaw } from 'vue';
  5. import { BlankPin } from '@/views/flow/pin';
  6. export interface FlowState {
  7. data: any; // 当前编辑的流程数据
  8. nodeId: string; // 当前激活的NodeId,通过useVueFlow().findNode获取实例对象
  9. pin: Pin | null; // 当前激活节点的pin component
  10. pinComponent: Component;
  11. showCard: boolean; // 是否展示Node Card面板
  12. }
  13. export const useFlowStore = defineStore({
  14. id: 'flow-store',
  15. state: (): FlowState => ({
  16. data: undefined,
  17. nodeId: '',
  18. pin: null,
  19. pinComponent: shallowRef(BlankPin),
  20. showCard: false,
  21. }),
  22. actions: {
  23. cleanNode() {
  24. this.nodeId = '';
  25. this.pin = null;
  26. this.pinComponent = BlankPin;
  27. },
  28. setShowCard() {
  29. this.showCard = !this.showCard;
  30. },
  31. initNode(node: GraphNode) {
  32. this.nodeId = node.id;
  33. this.pin = {};
  34. const pin = getPin(node.type, true);
  35. if (pin !== undefined && pin.component !== undefined) {
  36. this.pin = pin;
  37. this.pin.label = String(node.label);
  38. this.pinComponent = pin.component;
  39. }
  40. if (node.data !== undefined && node.data.des !== undefined) {
  41. this.pin.des = toRaw(node.data.des);
  42. }
  43. },
  44. initPlugin(plugin: Pin) {
  45. const pin = getPin(plugin.type, false);
  46. if (pin == undefined || pin.component == undefined) {
  47. return;
  48. }
  49. this.pin = pin;
  50. this.pinComponent = pin.component;
  51. if (plugin.des == undefined) {
  52. this.pin.des = '';
  53. }
  54. },
  55. },
  56. });