|
1 | 1 | <template> |
2 | 2 | <div class="h-full" :class="prefixCls"> |
3 | | - <FlowChartToolbar :prefixCls="prefixCls" v-if="toolbar" /> |
| 3 | + <FlowChartToolbar :prefixCls="prefixCls" v-if="toolbar" @view-data="handlePreview" /> |
4 | 4 | <div ref="lfElRef" class="h-full"></div> |
| 5 | + <BasicModal @register="register" title="流程数据" width="50%"> |
| 6 | + <JsonPreview :data="graphData" /> |
| 7 | + </BasicModal> |
5 | 8 | </div> |
6 | 9 | </template> |
7 | 10 | <script lang="ts"> |
|
14 | 17 | import { Snapshot, BpmnElement, Menu, DndPanel } from '@logicflow/extension'; |
15 | 18 |
|
16 | 19 | import { useDesign } from '/@/hooks/web/useDesign'; |
| 20 | + import { useAppStore } from '/@/store/modules/app'; |
17 | 21 | import { createFlowChartContext } from './useFlowContext'; |
18 | 22 |
|
19 | 23 | import { toLogicFlowData } from './adpterForTurbo'; |
| 24 | + import { useModal, BasicModal } from '/@/components/Modal'; |
| 25 | + import { JsonPreview } from '/@/components/CodeEditor'; |
20 | 26 |
|
21 | 27 | import '@logicflow/core/dist/style/index.css'; |
22 | | - import './index.css'; |
| 28 | + import '@logicflow/extension/lib/style/index.css'; |
23 | 29 | export default defineComponent({ |
24 | 30 | name: 'FlowChart', |
25 | | - components: { FlowChartToolbar }, |
| 31 | + components: { BasicModal, FlowChartToolbar, JsonPreview }, |
26 | 32 | props: { |
27 | 33 | flowOptions: { |
28 | 34 | type: Object as PropType<Definition>, |
|
41 | 47 | }, |
42 | 48 | setup(props) { |
43 | 49 | const lfElRef = ref<ElRef>(null); |
| 50 | + const graphData = ref<Recordable>({}); |
44 | 51 |
|
45 | 52 | const lfInstance = ref<Nullable<LogicFlow>>(null); |
46 | 53 |
|
47 | 54 | const { prefixCls } = useDesign('flow-chart'); |
| 55 | + const appStore = useAppStore(); |
| 56 | + const [register, { openModal }] = useModal(); |
48 | 57 | createFlowChartContext({ |
49 | 58 | logicFlow: (lfInstance as unknown) as LogicFlow, |
50 | 59 | }); |
|
55 | 64 | const defaultOptions: Partial<Definition> = { |
56 | 65 | grid: true, |
57 | 66 | background: { |
58 | | - color: '#f7f9ff', |
| 67 | + color: appStore.getDarkMode === 'light' ? '#f7f9ff' : '#151515', |
59 | 68 | }, |
60 | 69 | keyboard: { |
61 | 70 | enabled: true, |
|
73 | 82 | ); |
74 | 83 |
|
75 | 84 | watch( |
76 | | - () => props.flowOptions, |
| 85 | + () => appStore.getDarkMode, |
| 86 | + () => { |
| 87 | + init(); |
| 88 | + } |
| 89 | + ); |
| 90 | +
|
| 91 | + watch( |
| 92 | + () => unref(getFlowOptions), |
77 | 93 | (options) => { |
78 | 94 | unref(lfInstance)?.updateEditConfig(options); |
79 | 95 | } |
80 | 96 | ); |
81 | 97 |
|
| 98 | + let isInit = false; |
82 | 99 | // init logicFlow |
83 | 100 | async function init() { |
84 | 101 | await nextTick(); |
|
87 | 104 | if (!lfEl) { |
88 | 105 | return; |
89 | 106 | } |
| 107 | + if (!isInit) { |
| 108 | + // Canvas configuration |
| 109 | + LogicFlow.use(Snapshot); |
| 110 | + // Use the bpmn plug-in to introduce bpmn elements, which can be used after conversion in turbo |
| 111 | + LogicFlow.use(BpmnElement); |
| 112 | + // Start the right-click menu |
| 113 | + LogicFlow.use(Menu); |
| 114 | + LogicFlow.use(DndPanel); |
| 115 | + isInit = true; |
| 116 | + } |
90 | 117 |
|
91 | | - // Canvas configuration |
92 | | - LogicFlow.use(Snapshot); |
93 | | - // Use the bpmn plug-in to introduce bpmn elements, which can be used after conversion in turbo |
94 | | - LogicFlow.use(BpmnElement); |
95 | | - // Start the right-click menu |
96 | | - LogicFlow.use(Menu); |
97 | | - LogicFlow.use(DndPanel); |
98 | 118 | lfInstance.value = new LogicFlow({ |
99 | 119 | ...unref(getFlowOptions), |
100 | 120 | container: lfEl, |
|
113 | 133 | lf.render(lFData); |
114 | 134 | } |
115 | 135 |
|
| 136 | + function handlePreview() { |
| 137 | + const lf = unref(lfInstance); |
| 138 | + if (!lf) { |
| 139 | + return; |
| 140 | + } |
| 141 | + graphData.value = unref(lf).getGraphData(); |
| 142 | +
|
| 143 | + openModal(); |
| 144 | + } |
| 145 | +
|
116 | 146 | onMounted(init); |
117 | 147 |
|
118 | 148 | return { |
| 149 | + register, |
119 | 150 | prefixCls, |
120 | 151 | lfElRef, |
| 152 | + handlePreview, |
| 153 | + graphData, |
121 | 154 | }; |
122 | 155 | }, |
123 | 156 | }); |
|
0 commit comments