移动系统liao
4 天以前 df64ac247493594de867fa0fd89f518446eff118
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<template>
    <div class="flow-container">
        <el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" fullscreen>
            <template #header>
                <div style="color: #fff">
                    <span>{{ props.title }}</span>
                </div>
            </template>
            <div class="f-content">
                <div class="f-container">
                    <div class="f-switch">
                        <el-switch v-model="state.value2" @change="change" class="mb-2" active-text="打开框选" inactive-text="关闭框选" />
                    </div>
                    <PanelControl v-if="lf" :lf="lf" @catData="getData"></PanelControl>
                    <div class="f-container-c" ref="container" id="container"></div>
                    <PanelNode v-if="lf" :lf="lf"></PanelNode>
                    <el-drawer title="属性" v-model="drawer" :direction="direction" size="500px" :before-close="handleClose">
                        <PropertyDialog v-if="drawer" :nodeData="state.nodeData" :lf="lf" @setPropertiesFinish="handleClose"></PropertyDialog>
                    </el-drawer>
                    <el-dialog title="数据" v-model="dataVisible" width="50%">
                        <PanelDataDialog :graphData="state.graphData"></PanelDataDialog>
                    </el-dialog>
                </div>
            </div>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="cancel">取 消</el-button>
                    <el-button type="primary" @click="submit">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
 
<script setup lang="ts">
import { reactive, ref, nextTick } from 'vue';
import { ElMessageBox } from 'element-plus';
 
import LogicFlow from '@logicflow/core';
import { BpmnElement, InsertNodeInPolyline, Menu, MiniMap, SelectionSelect, Snapshot } from '@logicflow/extension';
import '@logicflow/core/dist/index.css';
import '@logicflow/extension/lib/style/index.css';
 
import RegisterEdge from './LogicFlow/Register/RegisterEdge';
import RegisterNode from './LogicFlow/Register/RegisterNode';
import PanelNode from './LogicFlow/Panel/PanelNode.vue';
import PanelControl from './LogicFlow/Panel/PanelControl.vue';
import PanelDataDialog from './LogicFlow/Panel/PanelDataDialog.vue';
import PropertyDialog from './LogicFlow/Property/PropertyDialog.vue';
 
import { getAPI } from '/@/utils/axios-utils';
import { ApprovalFlowApi } from '/@/api-plugins/approvalFlow/api';
import { ApprovalFlowOutput, UpdateApprovalFlowInput } from '/@/api-plugins/approvalFlow/models';
 
var props = defineProps({
    title: {
        type: String,
        default: '',
    },
});
 
const emit = defineEmits(['reloadTable', 'updateFlow']);
const flowData = ref({});
const lf = ref<InstanceType<typeof LogicFlow>>();
 
const drawer = ref(false);
const direction = ref('rtl');
const dataVisible = ref(false);
 
const state = reactive({
    loading: false,
    isShowDialog: false,
    ruleSource: {} as UpdateApprovalFlowInput,
    nodeData: {},
    graphData: {},
});
 
const openDialog = (row: ApprovalFlowOutput) => {
    state.ruleSource = row as UpdateApprovalFlowInput;
    // 初始化数据
    if (state.ruleSource.flowJson) {
        flowData.value = JSON.parse(state.ruleSource.flowJson);
    } else {
        flowData.value = {
            nodes: [],
            edges: [],
        };
    }
    state.isShowDialog = true;
    nextTick(() => {
        // 初始化画布
        initGraph();
    });
    console.log('open');
};
 
const closeDialog = () => {
    emit('reloadTable');
    state.isShowDialog = false;
    console.log('close');
};
 
const cancel = () => {
    state.isShowDialog = false;
    console.log('cancel');
};
 
// 保存流程设计
const submit = async () => {
    flowData.value = lf.value?.getGraphData();
    state.ruleSource.flowJson = JSON.stringify(flowData.value);
    await getAPI(ApprovalFlowApi).apiApprovalFlowUpdatePost(state.ruleSource);
    emit('updateFlow', flowData.value);
    closeDialog();
};
 
const initGraph = () => {
    // 初始化画布
    const container: HTMLElement = document.querySelector('#container')!;
    // 配置项
    const config = {
        stopScrollGraph: true, // 禁止鼠标滚动移动画布
        stopZoomGraph: true, // 禁止缩放
        metaKeyMultipleSelected: true,
        // 背景网格大小
        grid: {
            size: 10,
            type: 'dot',
        },
        // 快捷键
        keyboard: {
            enabled: true,
        },
        // 辅助线
        snapline: true,
    };
    lf.value = new LogicFlow({
        ...config,
        plugins: [
            BpmnElement,
            // 作栋节点自动插入边
            InsertNodeInPolyline,
            // 右键菜单
            Menu,
            // 迷你图
            MiniMap,
            // 框选
            SelectionSelect,
            // 快照
            Snapshot,
        ],
        container: container,
        width: container.clientWidth,
        height: container.clientHeight,
    });
    // 设置主题
    lf.value.setTheme({
        snapline: {
            stroke: '#1E90FF', // 对齐线颜色
            strokeWidth: 1, // 对齐线宽度
        },
    });
    // 注册自定义节点
    RegisterNode.Register(lf.value);
    // 注册自定义边
    RegisterEdge.Register(lf.value);
    // 监听节点点击事件
    lf.value.on('node:click', ({ data }) => {
        state.nodeData = data;
        drawer.value = true;
    });
    // 监听边点击事件
    lf.value.on('edge:click', ({ data }) => {
        state.nodeData = data;
        drawer.value = true;
    });
    // 渲染数据
    lf.value.render(flowData.value);
    // 画布居中
    lf.value.focusOn({ coordinate: { x: 300, y: 300 } });
};
 
// 框选
const change = (val: boolean) => {
    if (val) {
        lf.value?.extension.selectionSelect.openSelectionSelect();
    } else {
        lf.value?.extension.selectionSelect.closeSelectionSelect();
    }
};
 
// 获取数据
const getData = () => {
    var data = lf.value?.getGraphData();
    state.graphData = data;
    dataVisible.value = true;
};
 
// 关闭属性界面提醒
const handleClose = (done: () => void) => {
    ElMessageBox.confirm('确认要关闭当前属性编辑?')
        .then(() => {
            done();
        })
        .catch(() => {
            // catch error
        });
};
 
defineExpose({ openDialog });
</script>
 
<style scoped lang="scss">
:deep(.el-tabs__nav-scroll) {
    width: 70%;
    margin: 0 auto;
}
.flow-container {
    :deep(.el-dialog) {
        .el-dialog__header {
            display: none !important;
        }
        .el-dialog__body {
            max-height: calc(100vh - 45px) !important;
        }
    }
}
.f-content {
    display: flex;
    flex-grow: 1;
    z-index: 1;
    margin: -2px -19px -20px -19px;
    height: calc(100vh - 100px) !important;
 
    .f-container {
        flex-grow: 1;
        position: relative;
 
        .f-switch {
            position: absolute;
            z-index: 2;
            top: -22px;
            left: 5px;
 
            .el-switch {
                margin-right: 10px;
            }
        }
 
        .el-drawer {
            height: 80%;
            overflow: auto;
            margin-top: -30px;
            z-index: !important;
        }
 
        .f-container-c {
            position: absolute;
            width: 100%;
            height: 100%;
        }
    }
}
</style>