Skip to content

Commit 9459a72

Browse files
committed
feat: 流程模型新增/修改/设计合为一个页面基本切换tab逻辑校验与页面样式优化
1 parent 5063db4 commit 9459a72

File tree

5 files changed

+179
-85
lines changed

5 files changed

+179
-85
lines changed

src/components/SimpleProcessDesignerV2/src/SimpleProcessDesigner.vue

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@ import * as UserGroupApi from '@/api/bpm/userGroup'
3838
defineOptions({
3939
name: 'SimpleProcessDesigner'
4040
})
41+
4142
const emits = defineEmits(['success']) // 保存成功事件
4243
4344
const props = defineProps({
4445
modelId: {
4546
type: String,
46-
required: true
47+
required: false
48+
},
49+
modelKey: {
50+
type: String,
51+
required: false
52+
},
53+
modelName: {
54+
type: String,
55+
required: false
4756
}
4857
})
4958
@@ -69,28 +78,36 @@ const message = useMessage() // 国际化
6978
const processNodeTree = ref<SimpleFlowNode | undefined>()
7079
const errorDialogVisible = ref(false)
7180
let errorNodes: SimpleFlowNode[] = []
81+
7282
const saveSimpleFlowModel = async (simpleModelNode: SimpleFlowNode) => {
7383
if (!simpleModelNode) {
7484
message.error('模型数据为空')
7585
return
7686
}
7787
try {
7888
loading.value = true
79-
const data = {
80-
id: props.modelId,
81-
simpleModel: simpleModelNode
82-
}
83-
const result = await updateBpmSimpleModel(data)
84-
if (result) {
85-
message.success('修改成功')
86-
emits('success')
89+
if (props.modelId) {
90+
// 编辑模式
91+
const data = {
92+
id: props.modelId,
93+
simpleModel: simpleModelNode
94+
}
95+
const result = await updateBpmSimpleModel(data)
96+
if (result) {
97+
message.success('修改成功')
98+
emits('success')
99+
} else {
100+
message.alert('修改失败')
101+
}
87102
} else {
88-
message.alert('修改失败')
103+
// 新建模式,直接返回数据
104+
emits('success', simpleModelNode)
89105
}
90106
} finally {
91107
loading.value = false
92108
}
93109
}
110+
94111
// 校验节点设置。 暂时以 showText 为空 未节点错误配置
95112
const validateNode = (node: SimpleFlowNode | undefined, errorNodes: SimpleFlowNode[]) => {
96113
if (node) {
@@ -134,12 +151,14 @@ onMounted(async () => {
134151
try {
135152
loading.value = true
136153
// 获取表单字段
137-
const bpmnModel = await getModel(props.modelId)
138-
if (bpmnModel) {
139-
formType.value = bpmnModel.formType
140-
if (formType.value === 10) {
141-
const bpmnForm = (await getForm(bpmnModel.formId)) as unknown as FormVO
142-
formFields.value = bpmnForm?.fields
154+
if (props.modelId) {
155+
const bpmnModel = await getModel(props.modelId)
156+
if (bpmnModel) {
157+
formType.value = bpmnModel.formType
158+
if (formType.value === 10) {
159+
const bpmnForm = (await getForm(bpmnModel.formId)) as unknown as FormVO
160+
formFields.value = bpmnForm?.fields
161+
}
143162
}
144163
}
145164
// 获得角色列表
@@ -155,14 +174,18 @@ onMounted(async () => {
155174
// 获取用户组列表
156175
userGroupOptions.value = await UserGroupApi.getUserGroupSimpleList()
157176
158-
//获取 SIMPLE 设计器模型
159-
const result = await getBpmSimpleModel(props.modelId)
160-
if (result) {
161-
processNodeTree.value = result
162-
} else {
163-
// 初始值
177+
if (props.modelId) {
178+
//获取 SIMPLE 设计器模型
179+
const result = await getBpmSimpleModel(props.modelId)
180+
if (result) {
181+
processNodeTree.value = result
182+
}
183+
}
184+
185+
// 如果没有现有模型,创建初始模型
186+
if (!processNodeTree.value) {
164187
processNodeTree.value = {
165-
name: '发起人',
188+
name: props.modelName || '发起人',
166189
type: NodeType.START_USER_NODE,
167190
id: NodeId.START_USER_NODE_ID,
168191
childNode: {

src/views/bpm/model/CategoryDraggableModel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ import { formatDate } from '@/utils/formatTime'
249249
import * as ModelApi from '@/api/bpm/model'
250250
import * as FormApi from '@/api/bpm/form'
251251
import { setConfAndFields2 } from '@/utils/formCreate'
252-
import { BpmModelFormType, BpmModelType } from '@/utils/constants'
252+
import { BpmModelFormType } from '@/utils/constants'
253253
import { checkPermi } from '@/utils/permission'
254254
import { useUserStoreWithOut } from '@/store/modules/user'
255255
import { useAppStore } from '@/store/modules/app'

src/views/bpm/model/CreateUpdate.vue

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
11
<template>
22
<!-- 头部导航栏 -->
33
<div
4-
class="absolute top-0 left-0 right-0 h-50px bg-white border-bottom z-10 flex items-center justify-between px-20px"
4+
class="absolute top-0 left-0 right-0 h-50px bg-white border-bottom z-10 flex items-center px-20px"
55
>
6-
<div class="flex items-center">
7-
<Icon icon="ep:arrow-left" class="cursor-pointer" @click="router.back()" />
8-
<span class="ml-10px text-16px">{{ formData.name || '创建流程' }}</span>
6+
<!-- 左侧标题,固定宽度 -->
7+
<div class="w-200px flex items-center overflow-hidden">
8+
<Icon icon="ep:arrow-left" class="cursor-pointer flex-shrink-0" @click="router.back()" />
9+
<span class="ml-10px text-16px truncate" :title="formData.name || '创建流程'">
10+
{{ formData.name || '创建流程' }}
11+
</span>
912
</div>
1013

11-
<!-- 步骤条 -->
14+
<!-- 步骤条,固定在中间 -->
1215
<div class="flex-1 flex items-center justify-center h-full">
13-
<div
14-
v-for="(step, index) in steps"
15-
:key="index"
16-
class="flex items-center cursor-pointer mx-15px relative h-full"
17-
:class="[
18-
currentStep === index
19-
? 'text-[#3473ff] border-[#3473ff] border-b-2 border-b-solid'
20-
: 'text-gray-500'
21-
]"
22-
@click="currentStep = index"
23-
>
16+
<div class="w-400px flex items-center justify-between h-full">
2417
<div
25-
class="w-28px h-28px rounded-full flex items-center justify-center mr-8px border-2 border-solid text-15px"
18+
v-for="(step, index) in steps"
19+
:key="index"
20+
class="flex items-center cursor-pointer mx-15px relative h-full"
2621
:class="[
2722
currentStep === index
28-
? ' bg-[#3473ff] text-white'
29-
: 'border-gray-300 bg-white text-gray-500'
23+
? 'text-[#3473ff] border-[#3473ff] border-b-2 border-b-solid'
24+
: 'text-gray-500'
3025
]"
26+
@click="handleStepClick(index)"
3127
>
32-
{{ index + 1 }}
28+
<div
29+
class="w-28px h-28px rounded-full flex items-center justify-center mr-8px border-2 border-solid text-15px"
30+
:class="[
31+
currentStep === index
32+
? 'bg-[#3473ff] text-white border-[#3473ff]'
33+
: 'border-gray-300 bg-white text-gray-500'
34+
]"
35+
>
36+
{{ index + 1 }}
37+
</div>
38+
<span class="text-16px font-bold whitespace-nowrap">{{ step.title }}</span>
3339
</div>
34-
<span class="text-16px font-bold">{{ step.title }}</span>
3540
</div>
3641
</div>
3742

38-
<!-- 操作按钮 -->
39-
<div class="flex items-center gap-1">
43+
<!-- 右侧按钮,固定宽度 -->
44+
<div class="w-200px flex items-center justify-end gap-2">
4045
<el-button @click="handleSave">保 存</el-button>
4146
<el-button type="primary" @click="handleDeploy">发 布</el-button>
4247
</div>
@@ -264,15 +269,26 @@
264269
</el-form>
265270
</div>
266271

272+
<!-- 第三步:流程设计 -->
267273
<div v-show="currentStep === 2">
268274
<!-- BPMN设计器 -->
269275
<template v-if="formData.type === BpmModelType.BPMN">
270-
<BpmModelEditor :model-id="formData.id" @success="handleDesignSuccess" />
276+
<BpmModelEditor
277+
:model-id="formData.id"
278+
:model-key="formData.key"
279+
:model-name="formData.name"
280+
@success="handleDesignSuccess"
281+
/>
271282
</template>
272283

273284
<!-- Simple设计器 -->
274285
<template v-else>
275-
<SimpleModelDesign :model-id="formData.id" @success="handleDesignSuccess" />
286+
<SimpleModelDesign
287+
:model-id="formData.id"
288+
:model-key="formData.key"
289+
:model-name="formData.name"
290+
@success="handleDesignSuccess"
291+
/>
276292
</template>
277293
</div>
278294
</ContentWrap>
@@ -520,9 +536,27 @@ const steps = [
520536
]
521537
522538
// 处理设计器保存成功
523-
const handleDesignSuccess = () => {
539+
const handleDesignSuccess = (bpmnXml?: string) => {
540+
if (bpmnXml) {
541+
// 新建时,保存设计器生成的XML
542+
formData.value.bpmnXml = bpmnXml
543+
}
524544
message.success('保存成功')
525545
}
546+
547+
// 步骤切换处理
548+
const handleStepClick = async (index: number) => {
549+
// 如果是切换到第三步(流程设计),需要校验key和name
550+
if (index === 2 && !formData.value.id) {
551+
// 新增时才校验
552+
if (!formData.value.key || !formData.value.name) {
553+
message.warning('请先填写流程标识和流程名称')
554+
return
555+
}
556+
}
557+
558+
currentStep.value = index
559+
}
526560
</script>
527561

528562
<style lang="scss" scoped>

src/views/bpm/model/editor/index.vue

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
ref="processDesigner"
1212
@init-finished="initModeler"
1313
:additionalModel="controlForm.additionalModel"
14+
:model="model"
1415
@save="save"
1516
/>
1617
<!-- 流程属性器,负责编辑每个流程节点的属性 -->
@@ -35,14 +36,15 @@ import * as ModelApi from '@/api/bpm/model'
3536
defineOptions({ name: 'BpmModelEditor' })
3637
3738
const props = defineProps<{
38-
modelId: string
39+
modelId?: string
40+
modelKey?: string
41+
modelName?: string
3942
}>()
43+
4044
const emit = defineEmits(['success'])
41-
const router = useRouter() // 路由
42-
const { query } = useRoute() // 路由的查询
4345
const message = useMessage() // 国际化
4446
45-
const xmlString = ref(undefined) // BPMN XML
47+
const xmlString = ref<string>() // BPMN XML
4648
const modeler = ref(null) // BPMN Modeler
4749
const controlForm = ref({
4850
simulation: true,
@@ -61,16 +63,32 @@ const initModeler = (item) => {
6163
}, 10)
6264
}
6365
66+
/** 获取默认的BPMN XML */
67+
const getDefaultBpmnXml = (key: string, name: string) => {
68+
return `<?xml version="1.0" encoding="UTF-8"?>
69+
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.activiti.org/processdef">
70+
<process id="${key}" name="${name}" isExecutable="true" />
71+
<bpmndi:BPMNDiagram id="BPMNDiagram">
72+
<bpmndi:BPMNPlane id="${key}_di" bpmnElement="${key}" />
73+
</bpmndi:BPMNDiagram>
74+
</definitions>`
75+
}
76+
6477
/** 添加/修改模型 */
6578
const save = async (bpmnXml: string) => {
6679
try {
67-
const data = {
68-
...model.value,
69-
bpmnXml: bpmnXml
70-
} as unknown as ModelApi.ModelVO
71-
// 提交
72-
await ModelApi.updateModelBpmn(data)
73-
emit('success')
80+
if (props.modelId) {
81+
// 编辑模式
82+
const data = {
83+
...model.value,
84+
bpmnXml: bpmnXml
85+
} as unknown as ModelApi.ModelVO
86+
await ModelApi.updateModelBpmn(data)
87+
emit('success')
88+
} else {
89+
// 新建模式,直接返回XML
90+
emit('success', bpmnXml)
91+
}
7492
} catch (error) {
7593
console.error('保存失败:', error)
7694
message.error('保存失败')
@@ -79,28 +97,40 @@ const save = async (bpmnXml: string) => {
7997
8098
/** 初始化 */
8199
onMounted(async () => {
82-
if (!props.modelId) {
83-
message.error('缺少模型 modelId 编号')
84-
return
100+
if (props.modelId) {
101+
// 编辑模式
102+
try {
103+
// 查询模型
104+
const data = await ModelApi.getModel(props.modelId)
105+
model.value = {
106+
...data,
107+
bpmnXml: undefined // 清空 bpmnXml 属性
108+
}
109+
xmlString.value = data.bpmnXml || getDefaultBpmnXml(data.key, data.name)
110+
} catch (error) {
111+
console.error('获取模型失败:', error)
112+
message.error('获取模型失败')
113+
}
114+
} else if (props.modelKey && props.modelName) {
115+
// 新建模式,使用传入的key和name创建默认XML
116+
xmlString.value = getDefaultBpmnXml(props.modelKey, props.modelName)
117+
model.value = {
118+
key: props.modelKey,
119+
name: props.modelName
120+
} as ModelApi.ModelVO
85121
}
86-
// 查询模型
87-
const data = await ModelApi.getModel(String(props.modelId))
88-
if (!data.bpmnXml) {
89-
// 首次创建的 Model 模型,它是没有 bpmnXml,此时需要给它一个默认的
90-
data.bpmnXml = ` <?xml version="1.0" encoding="UTF-8"?>
91-
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.activiti.org/processdef">
92-
<process id="${data.key}" name="${data.name}" isExecutable="true" />
93-
<bpmndi:BPMNDiagram id="BPMNDiagram">
94-
<bpmndi:BPMNPlane id="${data.key}_di" bpmnElement="${data.key}" />
95-
</bpmndi:BPMNDiagram>
96-
</definitions>`
97-
}
98-
model.value = {
99-
...data,
100-
bpmnXml: undefined // 清空 bpmnXml 属性
101-
}
102-
xmlString.value = data.bpmnXml
103122
})
123+
124+
// 监听key和name的变化
125+
watch([() => props.modelKey, () => props.modelName], ([newKey, newName]) => {
126+
if (!props.modelId && newKey && newName) {
127+
xmlString.value = getDefaultBpmnXml(newKey, newName)
128+
model.value = {
129+
key: newKey,
130+
name: newName
131+
} as ModelApi.ModelVO
132+
}
133+
}, { immediate: true })
104134
</script>
105135
<style lang="scss">
106136
.process-panel__container {

0 commit comments

Comments
 (0)