吉安感知网项目-前端
罗广辉
2026-03-05 aef9afcbfceec4c9220992dcd651c86e6fbdefd0
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
<template>
    <el-dialog
        class=" nf-dialog"
        v-model="visible"
        title="流程配置"
        append-to-body
        destroy-on-close
        :close-on-press-escape="false"
        :fullscreen="true"
        :before-close="handleNutflowClose"
        @closed="visible = false"
    >
        <nf-design-base
            v-if="nutflowOption.step === 1"
            class="animated fadeIn"
            style="height: calc(100vh - 108px)"
            ref="nfDesignRef"
            :options="nutflowOption.step1"
        ></nf-design-base>
        <nf-design-base
            v-if="nutflowOption.step === 2"
            class="animated fadeIn"
            style="height: calc(100vh - 108px)"
            ref="nfDesignViewRef"
            :options="nutflowOption.step2"
        ></nf-design-base>
        <template #footer>
            <span class="avue-dialog__footer">
                <el-button @click="handleNutflowClose(() => {}, true)">取 消</el-button>
                <el-button color="#4C34FF" v-if="nutflowOption.step === 1" type="success" @click="handleStep(1)">下 一 步</el-button>
                <el-button color="#4C34FF" v-if="nutflowOption.step === 2" type="success" @click="handleStep(-1)">上 一 步</el-button>
                <el-button v-if="nutflowOption.step === 2" type="primary" @click="handleSubmitModel">确 定</el-button>
            </span>
        </template>
    </el-dialog>
</template>
 
<script>
import { submitModel, detail } from '@/api/flow/flow'
import { ElMessageBox, ElMessage } from 'element-plus'
 
export default {
    data() {
        return {
            visible: false,
            nutflowOption: {
                process: {},
                step: 1,
                step1: {
                    toolbar: ['open', 'create', 'fit', 'zoom-in', 'zoom-out', 'undo', 'redo', 'import', 'preview'],
                },
                step2: {
                    mode: 'view',
                    simulation: true,
                    minimap: true,
                },
            },
        }
    },
    methods: {
        // 打开弹框
        open(row) {
            this.visible = true
            if (row) {
                detail({ id: row.id }).then(res => {
                    const data = res.data.data
                    const { modelEditorXml } = data
                    this.nutflowOption.step1.xml = modelEditorXml
                    this.nutflowOption.process = data
                })
            }
        },
        // 提交流程模型
        handleSubmitModel() {
            const registry = this.$refs['nfDesignViewRef'].getElementRegistry().getAll()
            const { businessObject } = registry[0]
            const { id, name, documentation } = businessObject
            const description = documentation && documentation.length > 0 ? documentation[0].text : null
            const params = {
                ...this.nutflowOption.process,
                modelKey: id,
                name,
                description,
                modelEditorXml: this.nutflowOption.process.xml,
            }
            submitModel(params).then(() => {
                ElMessage.success('操作成功')
                this.handleNutflowClose()
                this.$emit('success')
            })
        },
        // 步骤切换
        handleStep(step) {
            if (step === 1) {
                // 下一步
                this.$refs['nfDesignRef'].getData('xml').then(data => {
                    this.nutflowOption.step1.xml = data
                    this.nutflowOption.step2.xml = data
                    this.nutflowOption.process.xml = data
                    this.nutflowOption.step = 2
                })
            } else {
                this.nutflowOption.step = 1
            }
        },
        // 关闭弹框处理
        handleNutflowClose(done, flag) {
            const initOption = {
                process: {},
                step: 1,
                step1: {
                    toolbar: ['open', 'create', 'fit', 'zoom-in', 'zoom-out', 'undo', 'redo', 'import', 'preview'],
                },
                step2: {
                    mode: 'view',
                    simulation: true,
                    minimap: true,
                },
            }
            if (done || flag) {
                ElMessageBox.confirm('确定要关闭吗?关闭未保存的修改都会丢失。', '警告', {
                    type: 'warning',
                })
                    .then(() => {
                        this.nutflowOption = initOption
                        if (typeof done === 'function') done()
                        this.visible = false
                    })
                    .catch(() => {})
            } else {
                this.nutflowOption = initOption
                this.visible = false
            }
        },
    },
}
</script>
 
<style scoped lang="scss">
:deep() {
    /* 隐藏右下角的 BPMN.io 标识 */
    .bjs-powered-by,
    .bjs-powered-by *,
    .bjs-powered-by-overlay,
    [data-id="logo-bpmn-io"],
    .bpmn-io-logo,
    [data-overlay-id="powered-by"],
    .overlay-sidebar-powered-by,
    a[href="https://bpmn.io"] {
        display: none !important;
    }
}
</style>