Skip to content

Commit 6fba4b7

Browse files
committed
【代码评审】BPM:流程编辑
1 parent d32a9a3 commit 6fba4b7

File tree

8 files changed

+51
-86
lines changed

8 files changed

+51
-86
lines changed

src/components/SimpleProcessDesignerV2/src/SimpleProcessDesigner.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ const props = defineProps({
6363
})
6464
6565
const processData = inject('processData') as Ref
66-
67-
6866
const loading = ref(false)
6967
const formFields = ref<string[]>([])
7068
const formType = ref(20)
@@ -110,7 +108,6 @@ const updateModel = () => {
110108
}
111109
}
112110
113-
114111
const saveSimpleFlowModel = async (simpleModelNode: SimpleFlowNode) => {
115112
if (!simpleModelNode) {
116113
return
@@ -201,7 +198,5 @@ onMounted(async () => {
201198
202199
const simpleProcessModelRef = ref()
203200
204-
205-
defineExpose({
206-
})
201+
defineExpose({})
207202
</script>

src/components/SimpleProcessDesignerV2/src/SimpleProcessModel.vue

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
<div class="position-absolute top-0px right-0px bg-#fff">
44
<el-row type="flex" justify="end">
55
<el-button-group key="scale-control" size="default">
6-
<el-button size="default" @click="exportJson()"><Icon icon="ep:download" />导出</el-button>
7-
<el-button size="default" @click="importJson()"><Icon icon="ep:upload" />导入</el-button>
6+
<el-button v-if="!readonly" size="default" @click="exportJson">
7+
<Icon icon="ep:download" /> 导出
8+
</el-button>
9+
<el-button v-if="!readonly" size="default" @click="importJson">
10+
<Icon icon="ep:upload" />导入
11+
</el-button>
812
<!-- 用于打开本地文件-->
913
<input
14+
v-if="!readonly"
1015
type="file"
1116
id="files"
1217
ref="refFile"
@@ -19,15 +24,6 @@
1924
<el-button size="default" class="w-80px"> {{ scaleValue }}% </el-button>
2025
<el-button size="default" :plain="true" :icon="ZoomIn" @click="zoomIn()" />
2126
</el-button-group>
22-
<!-- <el-button-->
23-
<!-- v-if="!readonly"-->
24-
<!-- size="default"-->
25-
<!-- class="ml-4px"-->
26-
<!-- type="primary"-->
27-
<!-- :icon="Select"-->
28-
<!-- @click="saveSimpleFlowModel"-->
29-
<!-- >保存模型</el-button-->
30-
<!-- >-->
3127
</el-row>
3228
</div>
3329
<div class="simple-process-model" :style="`transform: scale(${scaleValue / 100});`">
@@ -53,7 +49,7 @@
5349
import ProcessNodeTree from './ProcessNodeTree.vue'
5450
import { SimpleFlowNode, NodeType, NODE_DEFAULT_TEXT } from './consts'
5551
import { useWatchNode } from './node'
56-
import { ZoomOut, ZoomIn, ScaleToOriginal, Select } from '@element-plus/icons-vue'
52+
import { ZoomOut, ZoomIn, ScaleToOriginal } from '@element-plus/icons-vue'
5753
import { isString } from '@/utils/is'
5854
5955
defineOptions({
@@ -73,7 +69,7 @@ const props = defineProps({
7369
})
7470
7571
const emits = defineEmits<{
76-
'save': [node: SimpleFlowNode | undefined]
72+
save: [node: SimpleFlowNode | undefined]
7773
}>()
7874
7975
const processNodeTree = useWatchNode(props)
@@ -175,25 +171,28 @@ defineExpose({
175171
getCurrentFlowData
176172
})
177173
174+
/** 导出 JSON */
175+
// TODO @zws:增加一个 download 里面搞个 json 更好
178176
const exportJson = () => {
179-
const blob = new Blob([JSON.stringify(processNodeTree.value)]);
180-
const tempLink = document.createElement('a'); // 创建a标签
181-
const href = window.URL.createObjectURL(blob); // 创建下载的链接
182-
//filename
183-
const fileName = `model.json`;
184-
tempLink.href = href;
185-
tempLink.target = '_blank';
186-
tempLink.download = fileName;
187-
document.body.appendChild(tempLink);
188-
tempLink.click(); // 点击下载
189-
document.body.removeChild(tempLink); // 下载完成移除元素
190-
window.URL.revokeObjectURL(href); // 释放掉blob对象
177+
const blob = new Blob([JSON.stringify(processNodeTree.value)])
178+
const tempLink = document.createElement('a') // 创建a标签
179+
const href = window.URL.createObjectURL(blob) // 创建下载的链接
180+
// filename
181+
const fileName = `model.json`
182+
tempLink.href = href
183+
tempLink.target = '_blank'
184+
tempLink.download = fileName
185+
document.body.appendChild(tempLink)
186+
tempLink.click() // 点击下载
187+
document.body.removeChild(tempLink) // 下载完成移除元素
188+
window.URL.revokeObjectURL(href) // 释放掉 blob 对象
191189
}
190+
191+
/** 导入 JSON */
192+
const refFile = ref()
192193
const importJson = () => {
193194
refFile.value.click()
194195
}
195-
const refFile = ref()
196-
// 加载本地文件
197196
const importLocalFile = () => {
198197
const file = refFile.value.files[0]
199198
const reader = new FileReader()

src/router/modules/remaining.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
344344
}
345345
},
346346
{
347+
// TODO @zws:1)建议,在加一个路由。然后标题是“复制流程”,这样体验会好点;2)复制出来的数据,在名字前面,加“副本 ”,和钉钉保持一致!
347348
path: 'manager/model/:type/:id',
348349
component: () => import('@/views/bpm/model/form/index.vue'),
349350
name: 'BpmModelUpdate',

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const formType = ref(20)
5151
provide('formFields', formFields)
5252
provide('formType', formType)
5353
54-
//注入 流程数据
54+
// 注入流程数据
5555
const xmlString = inject('processData') as Ref
5656
5757
const modeler = shallowRef() // BPMN Modeler
@@ -66,13 +66,12 @@ const controlForm = ref({
6666
})
6767
const model = ref<ModelApi.ModelVO>() // 流程模型的信息
6868
69-
7069
/** 初始化 modeler */
70+
// TODO @zws:需要初始化,不然首次创建后,无法发布!相当于说,key、name 要去赋值下
7171
const initModeler = async (item) => {
7272
modeler.value = item
7373
}
7474
75-
7675
/** 添加/修改模型 */
7776
const save = async (bpmnXml: string) => {
7877
try {
@@ -84,7 +83,6 @@ const save = async (bpmnXml: string) => {
8483
}
8584
}
8685
87-
8886
// 在组件卸载时清理
8987
onBeforeUnmount(() => {
9088
modeler.value = null
@@ -94,8 +92,6 @@ onBeforeUnmount(() => {
9492
w.bpmnInstances = null
9593
}
9694
})
97-
98-
9995
</script>
10096
<style lang="scss">
10197
.process-panel__container {

src/views/bpm/model/form/ProcessDesign.vue

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ const handleDesignSuccess = async (data?: any) => {
6565
const showDesigner = computed(() => {
6666
return Boolean(modelData.value?.key && modelData.value?.name)
6767
})
68-
69-
// 组件创建时初始化数据
70-
onMounted(() => {
71-
})
72-
73-
// 组件卸载前保存数据
74-
onBeforeUnmount(async () => {
75-
76-
})
77-
7868
defineExpose({
7969
validate
8070
})

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@
6767
</div>
6868

6969
<!-- 第三步:流程设计 -->
70-
<ProcessDesign
71-
v-if="currentStep === 2"
72-
v-model="formData"
73-
ref="processDesignRef"
74-
/>
70+
<ProcessDesign v-if="currentStep === 2" v-model="formData" ref="processDesignRef" />
7571
</div>
7672
</div>
7773
</ContentWrap>
@@ -117,7 +113,7 @@ const validateProcess = async () => {
117113
await processDesignRef.value?.validate()
118114
}
119115
120-
const currentStep = ref(-1) // 步骤控制 一开始全部不展示等当前页面数据初始化完成
116+
const currentStep = ref(-1) // 步骤控制。-1 用于,一开始全部不展示等当前页面数据初始化完成
121117
122118
const steps = [
123119
{ title: '基本信息', validator: validateBasic },
@@ -148,14 +144,13 @@ const formData: any = ref({
148144
//流程数据
149145
const processData = ref<any>()
150146
151-
provide("processData", processData)
147+
provide('processData', processData)
152148
153149
// 数据列表
154150
const formList = ref([])
155151
const categoryList = ref([])
156152
const userList = ref<UserApi.UserVO[]>([])
157153
158-
159154
/** 初始化数据 */
160155
const initData = async () => {
161156
const modelId = route.params.id as string
@@ -178,20 +173,25 @@ const initData = async () => {
178173
// 获取用户列表
179174
userList.value = await UserApi.getSimpleUserList()
180175
176+
// 最终,设置 currentStep 切换到第一步
181177
currentStep.value = 0
182178
}
183179
184-
//根据类型切换流程数据
185-
watch(async () => formData.value.type, (newValue, oldValue) => {
186-
if (formData.value.type === BpmModelType.BPMN) {
187-
processData.value = formData.value.bpmnXml
188-
} else if (formData.value.type === BpmModelType.SIMPLE) {
189-
processData.value = formData.value.simpleModel
180+
/** 根据类型切换流程数据 */
181+
watch(
182+
async () => formData.value.type,
183+
() => {
184+
if (formData.value.type === BpmModelType.BPMN) {
185+
processData.value = formData.value.bpmnXml
186+
} else if (formData.value.type === BpmModelType.SIMPLE) {
187+
processData.value = formData.value.simpleModel
188+
}
189+
console.log('加载流程数据', processData.value)
190+
},
191+
{
192+
immediate: true
190193
}
191-
console.log('加载流程数据', processData.value)
192-
}, {
193-
immediate: true,
194-
})
194+
)
195195
196196
/** 校验所有步骤数据是否完整 */
197197
const validateAllSteps = async () => {
@@ -316,7 +316,7 @@ const handleDeploy = async () => {
316316
/** 步骤切换处理 */
317317
const handleStepClick = async (index: number) => {
318318
try {
319-
console.log('index', index);
319+
console.log('index', index)
320320
if (index !== 0) {
321321
await validateBasic()
322322
}
@@ -329,14 +329,12 @@ const handleStepClick = async (index: number) => {
329329
330330
// 切换步骤
331331
currentStep.value = index
332-
333332
} catch (error) {
334333
console.error('步骤切换失败:', error)
335334
message.warning('请先完善当前步骤必填信息')
336335
}
337336
}
338337
339-
340338
/** 返回列表页 */
341339
const handleBack = () => {
342340
// 先删除当前页签

src/views/bpm/model/index.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ const getList = async () => {
206206
}
207207
208208
/** 初始化 **/
209-
onMounted(() => {
210-
})
211-
onActivated(()=>{
209+
onActivated(() => {
212210
getList()
213211
})
214212
</script>

src/views/bpm/simple/SimpleModelDesign.vue

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defineOptions({
1717
name: 'SimpleModelDesign'
1818
})
1919
20-
const props = defineProps<{
20+
defineProps<{
2121
modelId?: string
2222
modelKey?: string
2323
modelName?: string
@@ -34,17 +34,5 @@ const handleSuccess = (data?: any) => {
3434
emit('success', data)
3535
}
3636
}
37-
38-
// 组件创建时初始化数据
39-
onMounted(() => {
40-
})
41-
42-
// 组件卸载前保存数据
43-
onBeforeUnmount(async () => {
44-
45-
})
46-
47-
defineExpose({
48-
})
4937
</script>
5038
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)