【代码评审】Bpm:新的编辑界面

feature/bpm
YunaiV 2024-12-27 21:28:12 +08:00
parent 6791de9d7c
commit 6f724d9d52
3 changed files with 35 additions and 81 deletions

View File

@ -309,18 +309,26 @@ const props = defineProps({
}) })
// value, // value,
watch(() => props.value, (newValue) => { watch(
() => props.value,
(newValue) => {
if (newValue && bpmnModeler) { if (newValue && bpmnModeler) {
createNewDiagram(newValue) createNewDiagram(newValue)
} }
}, { immediate: true }) },
{ immediate: true }
)
// processIdprocessName // processIdprocessName
watch([() => props.processId, () => props.processName], ([newId, newName]) => { watch(
[() => props.processId, () => props.processName],
([newId, newName]) => {
if (newId && newName && !props.value) { if (newId && newName && !props.value) {
createNewDiagram(null) createNewDiagram(null)
} }
}, { immediate: true }) },
{ immediate: true }
)
provide('configGlobal', props) provide('configGlobal', props)
let bpmnModeler: any = null let bpmnModeler: any = null
@ -599,16 +607,6 @@ const processZoomOut = (zoomStep = 0.1) => {
defaultZoom.value = newZoom defaultZoom.value = newZoom
bpmnModeler.get('canvas').zoom(defaultZoom.value) bpmnModeler.get('canvas').zoom(defaultZoom.value)
} }
// const processZoomTo = (newZoom = 1) => {
// if (newZoom < 0.2) {
// throw new Error('[Process Designer Warn ]: The zoom ratio cannot be less than 0.2')
// }
// if (newZoom > 4) {
// throw new Error('[Process Designer Warn ]: The zoom ratio cannot be greater than 4')
// }
// defaultZoom = newZoom
// bpmnModeler.get('canvas').zoom(newZoom)
// }
const processReZoom = () => { const processReZoom = () => {
defaultZoom.value = 1 defaultZoom.value = 1
bpmnModeler.get('canvas').zoom('fit-viewport', 'auto') bpmnModeler.get('canvas').zoom('fit-viewport', 'auto')
@ -647,62 +645,19 @@ const previewProcessXML = () => {
} }
const previewProcessJson = () => { const previewProcessJson = () => {
bpmnModeler.saveXML({ format: true }).then(({ xml }) => { bpmnModeler.saveXML({ format: true }).then(({ xml }) => {
// console.log(xml, 'xml')
// const rootNode = parseXmlString(xml)
// console.log(rootNode, 'rootNoderootNode')
const rootNodes = new XmlNode(XmlNodeType.Root, parseXmlString(xml)) const rootNodes = new XmlNode(XmlNodeType.Root, parseXmlString(xml))
// console.log(rootNodes, 'rootNodesrootNodesrootNodes')
// console.log(rootNodes.parent.toJsObject(), 'rootNodes.toJSON()')
// console.log(JSON.stringify(rootNodes.parent.toJsObject()), 'rootNodes.toJSON()')
// console.log(JSON.stringify(rootNodes.parent.toJSON()), 'rootNodes.toJSON()')
// const parser = new xml2js.XMLParser()
// let jObj = parser.parse(xml)
// console.log(jObj, 'jObjjObjjObjjObjjObj')
// const builder = new xml2js.XMLBuilder(xml)
// const xmlContent = builder
// console.log(xmlContent, 'xmlContent')
// console.log(xml2js, 'convertconvertconvert')
previewResult.value = rootNodes.parent?.toJSON() as unknown as string previewResult.value = rootNodes.parent?.toJSON() as unknown as string
// previewResult.value = jObj
// previewResult.value = convert.xml2json(xml, {explicitArray : false},{ spaces: 2 })
previewType.value = 'json' previewType.value = 'json'
previewModelVisible.value = true previewModelVisible.value = true
}) })
} }
/* ------------------------------------------------ 芋道源码 methods ------------------------------------------------------ */ /* ------------------------------------------------ 芋道源码 methods ------------------------------------------------------ */
const processSave = async () => {
try {
const { err, xml } = await bpmnModeler.saveXML()
if (err) {
ElMessage.error('保存流程设计失败,请重试!')
return
}
emit('save', xml)
} catch (error) {
console.error(error)
ElMessage.error('保存流程设计失败,请重试!')
}
}
/** 高亮显示 */
// const highlightedCode = (previewType, previewResult) => {
// console.log(previewType, 'previewType, previewResult')
// console.log(previewResult, 'previewType, previewResult')
// console.log(hljs.highlight, 'hljs.highlight')
// const result = hljs.highlight(previewType, previewResult.value || '', true)
// return result.value || '&nbsp;'
// }
onBeforeMount(() => {
console.log(props, 'propspropspropsprops')
})
onMounted(() => { onMounted(() => {
initBpmnModeler() initBpmnModeler()
createNewDiagram(props.value) createNewDiagram(props.value)
}) })
onBeforeUnmount(() => { onBeforeUnmount(() => {
// this.$once('hook:beforeDestroy', () => {
// })
if (bpmnModeler) bpmnModeler.destroy() if (bpmnModeler) bpmnModeler.destroy()
emit('destroy', bpmnModeler) emit('destroy', bpmnModeler)
bpmnModeler = null bpmnModeler = null

View File

@ -251,7 +251,7 @@ defineExpose({
<style lang="scss"> <style lang="scss">
.process-panel__container { .process-panel__container {
position: absolute; position: absolute;
top: 180px; top: 172px;
right: 60px; right: 70px;
} }
</style> </style>

View File

@ -79,14 +79,14 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useRouter, useRoute } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
import { useMessage } from '@/hooks/web/useMessage' import { useMessage } from '@/hooks/web/useMessage'
import * as ModelApi from '@/api/bpm/model' import * as ModelApi from '@/api/bpm/model'
import * as FormApi from '@/api/bpm/form' import * as FormApi from '@/api/bpm/form'
import { CategoryApi } from '@/api/bpm/category' import { CategoryApi } from '@/api/bpm/category'
import * as UserApi from '@/api/system/user' import * as UserApi from '@/api/system/user'
import { useUserStoreWithOut } from '@/store/modules/user' import { useUserStoreWithOut } from '@/store/modules/user'
import { BpmModelType, BpmModelFormType } from '@/utils/constants' import { BpmModelFormType, BpmModelType } from '@/utils/constants'
import BasicInfo from './BasicInfo.vue' import BasicInfo from './BasicInfo.vue'
import FormDesign from './FormDesign.vue' import FormDesign from './FormDesign.vue'
import ProcessDesign from './ProcessDesign.vue' import ProcessDesign from './ProcessDesign.vue'
@ -108,16 +108,17 @@ const validateBasic = async () => {
await basicInfoRef.value?.validate() await basicInfoRef.value?.validate()
} }
/** 表单设计校验 */
const validateForm = async () => { const validateForm = async () => {
await formDesignRef.value?.validate() await formDesignRef.value?.validate()
} }
/** 流程设计校验 */
const validateProcess = async () => { const validateProcess = async () => {
await processDesignRef.value?.validate() await processDesignRef.value?.validate()
} }
// const currentStep = ref(0) //
const currentStep = ref(0)
const steps = [ const steps = [
{ title: '基本信息', validator: validateBasic }, { title: '基本信息', validator: validateBasic },
{ title: '表单设计', validator: validateForm }, { title: '表单设计', validator: validateForm },
@ -233,7 +234,6 @@ const handleSave = async () => {
if (formData.value.id) { if (formData.value.id) {
// //
await ModelApi.updateModel(modelData) await ModelApi.updateModel(modelData)
message.success('修改成功')
// //
try { try {
await message.confirm('修改流程成功,是否发布流程?') await message.confirm('修改流程成功,是否发布流程?')
@ -244,8 +244,7 @@ const handleSave = async () => {
} }
} else { } else {
// //
const result = await ModelApi.createModel(modelData) formData.value.id = await ModelApi.createModel(modelData)
formData.value.id = result
message.success('新增成功') message.success('新增成功')
try { try {
await message.confirm('创建流程成功,是否继续编辑?') await message.confirm('创建流程成功,是否继续编辑?')
@ -312,7 +311,7 @@ const handleDeploy = async () => {
await ModelApi.deployModel(formData.value.id) await ModelApi.deployModel(formData.value.id)
message.success('发布成功') message.success('发布成功')
// //
router.push({ name: 'BpmModel' }) await router.push({ name: 'BpmModel' })
} catch (error: any) { } catch (error: any) {
console.error('发布失败:', error) console.error('发布失败:', error)
message.warning(error.message || '发布失败') message.warning(error.message || '发布失败')