【代码评审】BPM:流程编辑

pull/655/MERGE
YunaiV 2025-01-15 20:25:07 +08:00
parent d32a9a37bf
commit 6fba4b7228
8 changed files with 51 additions and 86 deletions

View File

@ -63,8 +63,6 @@ const props = defineProps({
}) })
const processData = inject('processData') as Ref const processData = inject('processData') as Ref
const loading = ref(false) const loading = ref(false)
const formFields = ref<string[]>([]) const formFields = ref<string[]>([])
const formType = ref(20) const formType = ref(20)
@ -110,7 +108,6 @@ const updateModel = () => {
} }
} }
const saveSimpleFlowModel = async (simpleModelNode: SimpleFlowNode) => { const saveSimpleFlowModel = async (simpleModelNode: SimpleFlowNode) => {
if (!simpleModelNode) { if (!simpleModelNode) {
return return
@ -201,7 +198,5 @@ onMounted(async () => {
const simpleProcessModelRef = ref() const simpleProcessModelRef = ref()
defineExpose({})
defineExpose({
})
</script> </script>

View File

@ -3,10 +3,15 @@
<div class="position-absolute top-0px right-0px bg-#fff"> <div class="position-absolute top-0px right-0px bg-#fff">
<el-row type="flex" justify="end"> <el-row type="flex" justify="end">
<el-button-group key="scale-control" size="default"> <el-button-group key="scale-control" size="default">
<el-button size="default" @click="exportJson()"><Icon icon="ep:download" />导出</el-button> <el-button v-if="!readonly" size="default" @click="exportJson">
<el-button size="default" @click="importJson()"><Icon icon="ep:upload" />导入</el-button> <Icon icon="ep:download" /> 导出
</el-button>
<el-button v-if="!readonly" size="default" @click="importJson">
<Icon icon="ep:upload" />导入
</el-button>
<!-- 用于打开本地文件--> <!-- 用于打开本地文件-->
<input <input
v-if="!readonly"
type="file" type="file"
id="files" id="files"
ref="refFile" ref="refFile"
@ -19,15 +24,6 @@
<el-button size="default" class="w-80px"> {{ scaleValue }}% </el-button> <el-button size="default" class="w-80px"> {{ scaleValue }}% </el-button>
<el-button size="default" :plain="true" :icon="ZoomIn" @click="zoomIn()" /> <el-button size="default" :plain="true" :icon="ZoomIn" @click="zoomIn()" />
</el-button-group> </el-button-group>
<!-- <el-button-->
<!-- v-if="!readonly"-->
<!-- size="default"-->
<!-- class="ml-4px"-->
<!-- type="primary"-->
<!-- :icon="Select"-->
<!-- @click="saveSimpleFlowModel"-->
<!-- >保存模型</el-button-->
<!-- >-->
</el-row> </el-row>
</div> </div>
<div class="simple-process-model" :style="`transform: scale(${scaleValue / 100});`"> <div class="simple-process-model" :style="`transform: scale(${scaleValue / 100});`">
@ -53,7 +49,7 @@
import ProcessNodeTree from './ProcessNodeTree.vue' import ProcessNodeTree from './ProcessNodeTree.vue'
import { SimpleFlowNode, NodeType, NODE_DEFAULT_TEXT } from './consts' import { SimpleFlowNode, NodeType, NODE_DEFAULT_TEXT } from './consts'
import { useWatchNode } from './node' import { useWatchNode } from './node'
import { ZoomOut, ZoomIn, ScaleToOriginal, Select } from '@element-plus/icons-vue' import { ZoomOut, ZoomIn, ScaleToOriginal } from '@element-plus/icons-vue'
import { isString } from '@/utils/is' import { isString } from '@/utils/is'
defineOptions({ defineOptions({
@ -73,7 +69,7 @@ const props = defineProps({
}) })
const emits = defineEmits<{ const emits = defineEmits<{
'save': [node: SimpleFlowNode | undefined] save: [node: SimpleFlowNode | undefined]
}>() }>()
const processNodeTree = useWatchNode(props) const processNodeTree = useWatchNode(props)
@ -175,25 +171,28 @@ defineExpose({
getCurrentFlowData getCurrentFlowData
}) })
/** 导出 JSON */
// TODO @zws download json
const exportJson = () => { const exportJson = () => {
const blob = new Blob([JSON.stringify(processNodeTree.value)]); const blob = new Blob([JSON.stringify(processNodeTree.value)])
const tempLink = document.createElement('a'); // a const tempLink = document.createElement('a') // a
const href = window.URL.createObjectURL(blob); // const href = window.URL.createObjectURL(blob) //
//filename // filename
const fileName = `model.json`; const fileName = `model.json`
tempLink.href = href; tempLink.href = href
tempLink.target = '_blank'; tempLink.target = '_blank'
tempLink.download = fileName; tempLink.download = fileName
document.body.appendChild(tempLink); document.body.appendChild(tempLink)
tempLink.click(); // tempLink.click() //
document.body.removeChild(tempLink); // document.body.removeChild(tempLink) //
window.URL.revokeObjectURL(href); // blob window.URL.revokeObjectURL(href) // blob
} }
/** 导入 JSON */
const refFile = ref()
const importJson = () => { const importJson = () => {
refFile.value.click() refFile.value.click()
} }
const refFile = ref()
//
const importLocalFile = () => { const importLocalFile = () => {
const file = refFile.value.files[0] const file = refFile.value.files[0]
const reader = new FileReader() const reader = new FileReader()

View File

@ -344,6 +344,7 @@ const remainingRouter: AppRouteRecordRaw[] = [
} }
}, },
{ {
// TODO @zws1建议在加一个路由。然后标题是“复制流程”这样体验会好点2复制出来的数据在名字前面加“副本 ”,和钉钉保持一致!
path: 'manager/model/:type/:id', path: 'manager/model/:type/:id',
component: () => import('@/views/bpm/model/form/index.vue'), component: () => import('@/views/bpm/model/form/index.vue'),
name: 'BpmModelUpdate', name: 'BpmModelUpdate',

View File

@ -51,7 +51,7 @@ const formType = ref(20)
provide('formFields', formFields) provide('formFields', formFields)
provide('formType', formType) provide('formType', formType)
// //
const xmlString = inject('processData') as Ref const xmlString = inject('processData') as Ref
const modeler = shallowRef() // BPMN Modeler const modeler = shallowRef() // BPMN Modeler
@ -66,13 +66,12 @@ const controlForm = ref({
}) })
const model = ref<ModelApi.ModelVO>() // const model = ref<ModelApi.ModelVO>() //
/** 初始化 modeler */ /** 初始化 modeler */
// TODO @zwskeyname
const initModeler = async (item) => { const initModeler = async (item) => {
modeler.value = item modeler.value = item
} }
/** 添加/修改模型 */ /** 添加/修改模型 */
const save = async (bpmnXml: string) => { const save = async (bpmnXml: string) => {
try { try {
@ -84,7 +83,6 @@ const save = async (bpmnXml: string) => {
} }
} }
// //
onBeforeUnmount(() => { onBeforeUnmount(() => {
modeler.value = null modeler.value = null
@ -94,8 +92,6 @@ onBeforeUnmount(() => {
w.bpmnInstances = null w.bpmnInstances = null
} }
}) })
</script> </script>
<style lang="scss"> <style lang="scss">
.process-panel__container { .process-panel__container {

View File

@ -65,16 +65,6 @@ const handleDesignSuccess = async (data?: any) => {
const showDesigner = computed(() => { const showDesigner = computed(() => {
return Boolean(modelData.value?.key && modelData.value?.name) return Boolean(modelData.value?.key && modelData.value?.name)
}) })
//
onMounted(() => {
})
//
onBeforeUnmount(async () => {
})
defineExpose({ defineExpose({
validate validate
}) })

View File

@ -67,11 +67,7 @@
</div> </div>
<!-- 第三步流程设计 --> <!-- 第三步流程设计 -->
<ProcessDesign <ProcessDesign v-if="currentStep === 2" v-model="formData" ref="processDesignRef" />
v-if="currentStep === 2"
v-model="formData"
ref="processDesignRef"
/>
</div> </div>
</div> </div>
</ContentWrap> </ContentWrap>
@ -117,7 +113,7 @@ const validateProcess = async () => {
await processDesignRef.value?.validate() await processDesignRef.value?.validate()
} }
const currentStep = ref(-1) // const currentStep = ref(-1) // -1
const steps = [ const steps = [
{ title: '基本信息', validator: validateBasic }, { title: '基本信息', validator: validateBasic },
@ -148,14 +144,13 @@ const formData: any = ref({
// //
const processData = ref<any>() const processData = ref<any>()
provide("processData", processData) provide('processData', processData)
// //
const formList = ref([]) const formList = ref([])
const categoryList = ref([]) const categoryList = ref([])
const userList = ref<UserApi.UserVO[]>([]) const userList = ref<UserApi.UserVO[]>([])
/** 初始化数据 */ /** 初始化数据 */
const initData = async () => { const initData = async () => {
const modelId = route.params.id as string const modelId = route.params.id as string
@ -178,20 +173,25 @@ const initData = async () => {
// //
userList.value = await UserApi.getSimpleUserList() userList.value = await UserApi.getSimpleUserList()
// currentStep
currentStep.value = 0 currentStep.value = 0
} }
// /** 根据类型切换流程数据 */
watch(async () => formData.value.type, (newValue, oldValue) => { watch(
if (formData.value.type === BpmModelType.BPMN) { async () => formData.value.type,
processData.value = formData.value.bpmnXml () => {
} else if (formData.value.type === BpmModelType.SIMPLE) { if (formData.value.type === BpmModelType.BPMN) {
processData.value = formData.value.simpleModel processData.value = formData.value.bpmnXml
} else if (formData.value.type === BpmModelType.SIMPLE) {
processData.value = formData.value.simpleModel
}
console.log('加载流程数据', processData.value)
},
{
immediate: true
} }
console.log('加载流程数据', processData.value) )
}, {
immediate: true,
})
/** 校验所有步骤数据是否完整 */ /** 校验所有步骤数据是否完整 */
const validateAllSteps = async () => { const validateAllSteps = async () => {
@ -316,7 +316,7 @@ const handleDeploy = async () => {
/** 步骤切换处理 */ /** 步骤切换处理 */
const handleStepClick = async (index: number) => { const handleStepClick = async (index: number) => {
try { try {
console.log('index', index); console.log('index', index)
if (index !== 0) { if (index !== 0) {
await validateBasic() await validateBasic()
} }
@ -329,14 +329,12 @@ const handleStepClick = async (index: number) => {
// //
currentStep.value = index currentStep.value = index
} catch (error) { } catch (error) {
console.error('步骤切换失败:', error) console.error('步骤切换失败:', error)
message.warning('请先完善当前步骤必填信息') message.warning('请先完善当前步骤必填信息')
} }
} }
/** 返回列表页 */ /** 返回列表页 */
const handleBack = () => { const handleBack = () => {
// //

View File

@ -206,9 +206,7 @@ const getList = async () => {
} }
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onActivated(() => {
})
onActivated(()=>{
getList() getList()
}) })
</script> </script>

View File

@ -17,7 +17,7 @@ defineOptions({
name: 'SimpleModelDesign' name: 'SimpleModelDesign'
}) })
const props = defineProps<{ defineProps<{
modelId?: string modelId?: string
modelKey?: string modelKey?: string
modelName?: string modelName?: string
@ -34,17 +34,5 @@ const handleSuccess = (data?: any) => {
emit('success', data) emit('success', data)
} }
} }
//
onMounted(() => {
})
//
onBeforeUnmount(async () => {
})
defineExpose({
})
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>