feat: 自定义选择审批人逻辑TODO,选择用户弹窗绘制与选择交互逻辑处理

This commit is contained in:
GoldenZqqq
2024-11-06 17:17:44 +08:00
parent 0fbd98291e
commit 92314ee945
4 changed files with 228 additions and 26 deletions

View File

@ -20,7 +20,7 @@
:option="detailForm.option"
@submit="submitForm"
>
<template #type-startUserSelect>
<!-- <template #type-startUserSelect>
<el-col :span="24">
<el-card class="mb-10px">
<template #header>指定审批人</template>
@ -51,7 +51,7 @@
</el-form>
</el-card>
</el-col>
</template>
</template> -->
</form-create>
</el-col>
@ -61,7 +61,7 @@
ref="timelineRef"
:activity-nodes="activityNodes"
:show-status-icon="false"
candidateField="candidateUserList"
:startUserSelectTasks="startUserSelectTasks"
/>
</el-col>
</el-row>
@ -104,7 +104,8 @@ import type { ApiAttrs } from '@form-create/element-ui/types/config'
import { useTagsViewStore } from '@/store/modules/tagsView'
import * as ProcessInstanceApi from '@/api/bpm/processInstance'
import * as DefinitionApi from '@/api/bpm/definition'
import * as UserApi from '@/api/system/user'
// import * as UserApi from '@/api/system/user'
import { activityNodes as aN, startUserSelectTasks as sUs } from './mock'
defineOptions({ name: 'ProcessDefinitionDetail' })
const props = defineProps<{
@ -125,7 +126,7 @@ const startUserSelectAssigneesFormRef = ref() // 发起人选择审批人的表
const startUserSelectTasks: any = ref([]) // 发起人需要选择审批人的用户任务列表
const startUserSelectAssignees = ref({}) // 发起人选择审批人的数据
const startUserSelectAssigneesFormRules = ref({}) // 发起人选择审批人的表单 Rules
const userList = ref<any[]>([]) // 用户列表
// const userList = ref<any[]>([]) // 用户列表
const bpmnXML: any = ref(null) // BPMN 数据
/** 当前的Tab */
const activeTab = ref('form')
@ -163,25 +164,25 @@ const initProcessInfo = async (row: any, formVariables?: any) => {
if (processDefinitionDetail) {
bpmnXML.value = processDefinitionDetail.bpmnXml
startUserSelectTasks.value = processDefinitionDetail.startUserSelectTasks
startUserSelectTasks.value = sUs
// 设置指定审批人
if (startUserSelectTasks.value?.length > 0) {
detailForm.value.rule.push({
type: 'startUserSelect',
props: {
title: '指定审批人'
}
})
// 设置校验规则
for (const userTask of startUserSelectTasks.value) {
startUserSelectAssignees.value[userTask.id] = []
startUserSelectAssigneesFormRules.value[userTask.id] = [
{ required: true, message: '请选择审批人', trigger: 'blur' }
]
}
// 加载用户列表
userList.value = await UserApi.getSimpleUserList()
}
// if (startUserSelectTasks.value?.length > 0) {
// detailForm.value.rule.push({
// type: 'startUserSelect',
// props: {
// title: '指定审批人'
// }
// })
// // 设置校验规则
// for (const userTask of startUserSelectTasks.value) {
// startUserSelectAssignees.value[userTask.id] = []
// startUserSelectAssigneesFormRules.value[userTask.id] = [
// { required: true, message: '请选择审批人', trigger: 'blur' }
// ]
// }
// // 加载用户列表
// userList.value = await UserApi.getSimpleUserList()
// }
}
// 情况二:业务表单
} else if (row.formCustomCreatePath) {
@ -205,6 +206,7 @@ const getApprovalDetail = async (row: any) => {
}
// 获取审批节点,显示 Timeline 的数据
activityNodes.value = data.activityNodes
activityNodes.value = aN
} finally {
}
}
@ -250,7 +252,7 @@ defineExpose({ initProcessInfo })
$wrap-padding-height: 20px;
$wrap-margin-height: 15px;
$button-height: 51px;
$process-header-height: 194px;
$process-header-height: 105px;
.processInstance-wrap-main {
height: calc(

View File

@ -0,0 +1,86 @@
import { ProcessInstanceVO, User, ApprovalTaskInfo, ApprovalNodeInfo } from '@/api/bpm/processInstance';
import { NodeType } from '@/components/SimpleProcessDesignerV2/src/consts'
const users: User[] = [
{ id: 1, nickname: 'Alice', avatar: 'https://picsum.photos/200?r=1' },
{ id: 2, nickname: 'Bob', avatar: 'https://picsum.photos/200?r=2' },
{ id: 3, nickname: 'Charlie', avatar: 'https://picsum.photos/200?r=3' },
{ id: 4, nickname: 'David', avatar: 'https://picsum.photos/200?r=4' }
];
const approvalTask1: ApprovalTaskInfo = {
id: 1,
ownerUser: users[0], // Alice is the owner (initiator)
assigneeUser: users[1], // Bob is the assignee
status: 1, // In Progress
reason: 'Please review and approve the request.'
};
const approvalTask2: ApprovalTaskInfo = {
id: 2,
ownerUser: users[1], // Bob is the owner (approver)
assigneeUser: users[2], // Charlie is the assignee
status: 0, // Pending approval
reason: 'Awaiting Bobs decision.'
};
const approvalTask3: ApprovalTaskInfo = {
id: 3,
ownerUser: users[2], // Charlie is the owner (approver)
assigneeUser: users[3], // David is the assignee
status: 0, // Pending approval
reason: 'Awaiting Charlies decision.'
};
const approvalNode1: ApprovalNodeInfo = {
id: 101,
name: 'Start Review',
nodeType: NodeType.START_USER_NODE,
status: 1, // In Progress
startTime: new Date('2024-11-01T10:00:00Z'),
tasks: [approvalTask1]
};
const approvalNode2: ApprovalNodeInfo = {
id: 102,
name: 'First Review',
nodeType: NodeType.USER_TASK_NODE,
status: 0, // Pending approval
startTime: new Date('2024-11-01T11:00:00Z'),
tasks: [approvalTask2],
candidateUsers: [users[2], users[3]] // Candidate users: Charlie and David
};
const approvalNode3: ApprovalNodeInfo = {
id: 103,
name: 'Second Review',
nodeType: NodeType.USER_TASK_NODE,
status: 0, // Pending approval
startTime: new Date('2024-11-01T12:00:00Z'),
tasks: [approvalTask3],
candidateUsers: [users[1], users[3]] // Candidate users: Bob and David
};
const processInstance: ProcessInstanceVO = {
id: 1001,
name: 'Request Approval Process',
processDefinitionId: 'proc-2024-001',
category: 'Approval Process',
result: 0, // Ongoing
tasks: [{ id: '1', name: 'Start Review' }, { id: '2', name: 'First Review' }, { id: '3', name: 'Second Review' }],
fields: ['field1', 'field2'],
status: 1, // In Progress
remark: 'This is a sample approval process.',
businessKey: 'BUS-12345',
createTime: '2024-11-01T09:00:00Z',
endTime: '',
processDefinition: undefined // Not populated in this example
};
// 模拟的 activityNodes 数据,传递给 ProcessInstanceTimeline 组件
const activityNodes: ApprovalNodeInfo[] = [approvalNode1, approvalNode2, approvalNode3];
export { processInstance, activityNodes, users };
export const startUserSelectTasks = users.map(user => ({id: user.id,name:user.nickname}))

View File

@ -36,7 +36,15 @@
{{ getApprovalNodeTime(activity) }}
</div>
</div>
<div class="flex items-center flex-wrap mt-1 gap2">
<!-- 需要自定义选择审批人 -->
<div
v-if="startUserSelectTasks?.length > 0 && activity.nodeType === NodeType.USER_TASK_NODE"
>
<el-button class="!px-8px" @click="handleSelectUser">
<Icon icon="fa:user-plus" />
</el-button>
</div>
<div v-else class="flex items-center flex-wrap mt-1 gap2">
<!-- 情况一遍历每个审批节点下的进行中task 任务 -->
<div v-for="(task, idx) in activity.tasks" :key="idx" class="flex flex-col pr-2 gap2">
<div
@ -121,6 +129,8 @@
</div>
</el-timeline-item>
</el-timeline>
<!-- 用户选择弹窗 -->
<UserSelectForm ref="userSelectFormRef" @confirm="handleUserSelectConfirm" />
</template>
<script lang="ts" setup>
@ -141,9 +151,11 @@ withDefaults(
defineProps<{
activityNodes: ProcessInstanceApi.ApprovalNodeInfo[] // 审批节点信息
showStatusIcon?: boolean // 是否显示头像右下角状态图标
startUserSelectTasks?: any[] // 发起人需要选择审批人的用户任务列表
}>(),
{
showStatusIcon: true // 默认值为 true
showStatusIcon: true, // 默认值为 true
startUserSelectTasks: () => [] // 默认值为空数组
}
)
@ -241,4 +253,14 @@ const getApprovalNodeTime = (node: ProcessInstanceApi.ApprovalNodeInfo) => {
return `${formatDate(node.startTime)}`
}
}
// 选择自定义审批人
const userSelectFormRef = ref()
const handleSelectUser = () => {
userSelectFormRef.value.open()
}
// 选择完成
const handleUserSelectConfirm = (userList) => {
console.log('[ userList ] >', userList)
}
</script>