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

pull/624/MERGE
YunaiV 2024-12-15 17:08:02 +08:00
parent c083a0c986
commit 5e386336b9
5 changed files with 68 additions and 69 deletions

View File

@ -332,8 +332,8 @@ const remainingRouter: AppRouteRecordRaw[] = [
}
},
{
path: 'manager/model/create-update',
component: () => import('@/views/bpm/model/CreateUpdate.vue'),
path: 'manager/model/create-update', // TODO @goldenzqqq是不是拆分成两个一个 create 创建流程;一个 update 修改流程?
component: () => import('@/views/bpm/model/CreateUpdate.vue'), // TODO @goldenzqqq是不是放到 '@/views/bpm/model/form/index.vue'。然后,原本的 editor/index.vue 是不是可以清理了呀?
name: 'BpmModelCreateUpdate',
meta: {
noCache: true,

View File

@ -339,21 +339,7 @@ const handleChangeState = async (row: any) => {
/** 设计流程 */
const handleDesign = (row: any) => {
// if (row.type == BpmModelType.BPMN) {
// push({
// name: 'BpmModelEditor',
// query: {
// modelId: row.id
// }
// })
// } else {
// push({
// name: 'SimpleModelDesign',
// query: {
// modelId: row.id
// }
// })
// }
// TODO @goldenzqqq使 name
push(`/bpm/manager/model/create-update?id=${row.id}`)
}
@ -497,6 +483,7 @@ const handleDeleteCategory = async () => {
/** 添加流程模型弹窗 */
const modelFormRef = ref()
const openModelForm = (type: string, id?: number) => {
// TODO @goldenzqqq使 name
if (type === 'create') {
push('/bpm/manager/model/create-update')
} else {

View File

@ -50,6 +50,8 @@
<!-- 主体内容 -->
<ContentWrap class="mt-50px">
<!-- 第一步基本信息 -->
<!-- TODO @goldenzqqq是不是可以居中哈1024 -->
<!-- TODO @goldenzqqq有必要把第一步第二步拆成独立的 vue 组件哇主要是把相关的 html还有 js 逻辑可以挪进去让主的 index.vue 更精简一点 -->
<div v-show="currentStep === 0">
<el-form
ref="formRef"
@ -200,6 +202,7 @@
<div v-if="currentStep === 1">
<!-- 第二步表单设计 -->
<!-- TODO @goldenzqqq是不是可以居中哈1024 -->
<el-form
ref="formRef"
:model="formData"
@ -316,9 +319,7 @@ const router = useRouter()
const route = useRoute()
const userStore = useUserStoreWithOut()
//
const currentStep = ref(0)
//
const currentStep = ref(0) //
const formRef = ref()
const formData: any = ref({
id: undefined,
@ -337,9 +338,7 @@ const formData: any = ref({
managerUserType: undefined,
startUserIds: [],
managerUserIds: []
})
//
}) //
const formRules = {
name: [{ required: true, message: '流程名称不能为空', trigger: 'blur' }],
key: [{ required: true, message: '流程标识不能为空', trigger: 'blur' }],
@ -352,7 +351,7 @@ const formRules = {
formCustomViewPath: [{ required: true, message: '表单查看地址不能为空', trigger: 'blur' }],
visible: [{ required: true, message: '是否可见不能为空', trigger: 'blur' }],
managerUserIds: [{ required: true, message: '流程管理员不能为空', trigger: 'blur' }]
}
} //
//
const xmlString = ref(undefined)
@ -368,19 +367,19 @@ const selectedManagerUsers = ref<UserVO[]>([])
const userSelectFormRef = ref()
const currentSelectType = ref<'start' | 'manager'>('start')
//
/** 打开发起人选择 */
const openStartUserSelect = () => {
currentSelectType.value = 'start'
userSelectFormRef.value.open(0, selectedStartUsers.value)
}
//
/** 打开管理员选择 */
const openManagerUserSelect = () => {
currentSelectType.value = 'manager'
userSelectFormRef.value.open(0, selectedManagerUsers.value)
}
//
/** 处理用户选择确认 */
const handleUserSelectConfirm = (_, users: UserVO[]) => {
if (currentSelectType.value === 'start') {
selectedStartUsers.value = users
@ -391,7 +390,7 @@ const handleUserSelectConfirm = (_, users: UserVO[]) => {
}
}
//
/** 处理发起人类型变化 */
const handleStartUserTypeChange = (value: number) => {
if (value !== 1) {
selectedStartUsers.value = []
@ -399,7 +398,7 @@ const handleStartUserTypeChange = (value: number) => {
}
}
//
/** 处理管理员类型变化 */
const handleManagerUserTypeChange = (value: number) => {
if (value !== 1) {
selectedManagerUsers.value = []
@ -407,19 +406,21 @@ const handleManagerUserTypeChange = (value: number) => {
}
}
//
/** 移除发起人 */
const handleRemoveStartUser = (user: UserVO) => {
selectedStartUsers.value = selectedStartUsers.value.filter((u) => u.id !== user.id)
formData.value.startUserIds = formData.value.startUserIds.filter((id) => id !== user.id)
formData.value.startUserIds = formData.value.startUserIds.filter((id: number) => id !== user.id)
}
//
/** 移除管理员 */
const handleRemoveManagerUser = (user: UserVO) => {
selectedManagerUsers.value = selectedManagerUsers.value.filter((u) => u.id !== user.id)
formData.value.managerUserIds = formData.value.managerUserIds.filter((id) => id !== user.id)
formData.value.managerUserIds = formData.value.managerUserIds.filter(
(id: number) => id !== user.id
)
}
//
/** 保存操作 */
const handleSave = async () => {
try {
if (formData.value.id) {
@ -436,7 +437,7 @@ const handleSave = async () => {
}
}
//
/** 发布操作 */
const handleDeploy = async () => {
try {
await message.confirm('是否确认发布该流程?')
@ -445,7 +446,8 @@ const handleDeploy = async () => {
await handleSave()
await ModelApi.deployModel(formData.value.id)
message.success('发布成功')
router.push({ path: '/bpm/manager/model' })
// TODO @goldenzqqq使 name
await router.push({ path: '/bpm/manager/model' })
} catch (error) {
if (error instanceof Error) {
// ,
@ -465,7 +467,7 @@ const handleDeploy = async () => {
}
}
//
/** 初始化数据 */
const initData = async () => {
const modelId = route.query.id as unknown as string
if (modelId) {
@ -497,16 +499,12 @@ const initData = async () => {
userList.value = await UserApi.getSimpleUserList()
}
onMounted(async () => {
await initData()
})
//
/** 第一步校验 */
const validateStep1 = async () => {
await formRef.value?.validate(['name', 'key', 'category', 'icon', 'type', 'visible'])
}
//
/** 第二步校验 */
const validateStep2 = async () => {
await formRef.value?.validate([
'formType',
@ -516,13 +514,14 @@ const validateStep2 = async () => {
])
}
//
/** 第三步校验 */
const validateStep3 = async () => {
if (!xmlString.value) {
throw new Error('请设计流程')
}
}
/** 校验全部 */
const validateAllSteps = async () => {
for (const step of steps) {
if (step.validator) {
@ -531,13 +530,14 @@ const validateAllSteps = async () => {
}
}
// TODO @goldenzqqq step1step2step3 basicformdesigner
const steps = [
{ title: '基本信息', validator: validateStep1 },
{ title: '表单设计', validator: validateStep2 },
{ title: '流程设计', validator: validateStep3 }
]
//
/** 处理设计器保存成功 */
const handleDesignSuccess = (bpmnXml?: string) => {
if (bpmnXml) {
// XML
@ -546,7 +546,7 @@ const handleDesignSuccess = (bpmnXml?: string) => {
message.success('保存成功')
}
//
/** 步骤切换处理 */
const handleStepClick = async (index: number) => {
// keyname
if (index === 2) {
@ -555,11 +555,12 @@ const handleStepClick = async (index: number) => {
return
}
}
// TODO @goldenzqqq
currentStep.value = index
}
//
/** 添加一个计算属性来判断是否显示设计器 */
const showDesigner = computed(() => {
return (
currentStep.value === 2 &&
@ -585,6 +586,11 @@ onBeforeUnmount(() => {
w.bpmnInstances = null
}
})
/** 初始化 */
onMounted(async () => {
await initData()
})
</script>
<style lang="scss" scoped>

View File

@ -201,11 +201,12 @@ import { DICT_TYPE, getBoolDictOptions, getIntDictOptions } from '@/utils/dict'
import { ElMessageBox } from 'element-plus'
import * as ModelApi from '@/api/bpm/model'
import * as FormApi from '@/api/bpm/form'
import { CategoryApi } from '@/api/bpm/category'
import { CategoryApi, CategoryVO } from '@/api/bpm/category'
import { BpmModelFormType, BpmModelType } from '@/utils/constants'
import { UserVO } from '@/api/system/user'
import * as UserApi from '@/api/system/user'
import { useUserStoreWithOut } from '@/store/modules/user'
import { FormVO } from '@/api/bpm/form'
defineOptions({ name: 'ModelForm' })
@ -251,12 +252,12 @@ const formRules = reactive({
managerUserIds: [{ required: true, message: '流程管理员不能为空', trigger: 'blur' }]
})
const formRef = ref() // Ref
const formList = ref([]) //
const categoryList = ref([]) //
const formList = ref<FormVO[]>([]) //
const categoryList = ref<CategoryVO[]>([]) //
const userList = ref<UserVO[]>([]) //
const selectedStartUsers = ref<UserVO[]>([]) //
const selectedManagerUsers = ref<UserVO[]>([]) //
const userSelectFormRef = ref() // ref
const userSelectFormRef = ref() // ref
const currentSelectType = ref<'start' | 'manager'>('start') //
/** 打开弹窗 */
@ -363,7 +364,7 @@ const resetForm = () => {
selectedManagerUsers.value = []
}
//
/** 处理发起人类型变化 */
const handleStartUserTypeChange = (value: number) => {
if (value !== 1) {
selectedStartUsers.value = []
@ -371,7 +372,7 @@ const handleStartUserTypeChange = (value: number) => {
}
}
//
/** 处理管理员类型变化 */
const handleManagerUserTypeChange = (value: number) => {
if (value !== 1) {
selectedManagerUsers.value = []
@ -379,19 +380,19 @@ const handleManagerUserTypeChange = (value: number) => {
}
}
//
/** 打开发起人选择 */
const openStartUserSelect = () => {
currentSelectType.value = 'start'
userSelectFormRef.value.open(0, selectedStartUsers.value)
}
//
/** 打开管理员选择 */
const openManagerUserSelect = () => {
currentSelectType.value = 'manager'
userSelectFormRef.value.open(0, selectedManagerUsers.value)
}
//
/** 处理用户选择确认 */
const handleUserSelectConfirm = (_, users: UserVO[]) => {
if (currentSelectType.value === 'start') {
selectedStartUsers.value = users
@ -402,16 +403,18 @@ const handleUserSelectConfirm = (_, users: UserVO[]) => {
}
}
//
/** 移除发起人 */
const handleRemoveStartUser = (user: UserVO) => {
selectedStartUsers.value = selectedStartUsers.value.filter((u) => u.id !== user.id)
formData.value.startUserIds = formData.value.startUserIds.filter((id) => id !== user.id)
formData.value.startUserIds = formData.value.startUserIds.filter((id: number) => id !== user.id)
}
//
/** 移除管理员 */
const handleRemoveManagerUser = (user: UserVO) => {
selectedManagerUsers.value = selectedManagerUsers.value.filter((u) => u.id !== user.id)
formData.value.managerUserIds = formData.value.managerUserIds.filter((id) => id !== user.id)
formData.value.managerUserIds = formData.value.managerUserIds.filter(
(id: number) => id !== user.id
)
}
</script>

View File

@ -32,7 +32,6 @@ import CustomContentPadProvider from '@/components/bpmnProcessDesigner/package/d
//
import CustomPaletteProvider from '@/components/bpmnProcessDesigner/package/designer/plugins/palette'
import * as ModelApi from '@/api/bpm/model'
import { getForm, FormVO } from '@/api/bpm/form'
defineOptions({ name: 'BpmModelEditor' })
@ -82,7 +81,7 @@ const initBpmnInstances = () => {
}
//
return Object.values(instances).every(instance => instance)
return Object.values(instances).every((instance) => instance)
} catch (error) {
console.error('初始化 bpmnInstances 失败:', error)
return false
@ -168,7 +167,7 @@ onMounted(async () => {
}
})
//
/** 更新模型数据 */
const updateModelData = async (key?: string, name?: string) => {
if (key && name) {
xmlString.value = getDefaultBpmnXml(key, name)
@ -185,12 +184,16 @@ const updateModelData = async (key?: string, name?: string) => {
}
}
// keyname
watch([() => props.modelKey, () => props.modelName], async ([newKey, newName]) => {
if (!props.modelId && newKey && newName && modeler.value) {
await updateModelData(newKey, newName)
}
}, { immediate: true, deep: true })
// key name
watch(
[() => props.modelKey, () => props.modelName],
async ([newKey, newName]) => {
if (!props.modelId && newKey && newName && modeler.value) {
await updateModelData(newKey, newName)
}
},
{ immediate: true, deep: true }
)
//
onBeforeUnmount(() => {