Vue3 重构:流程实例的详情(流程任务列表)

This commit is contained in:
YunaiV 2023-03-28 07:45:18 +08:00
parent 4388d6565a
commit 7587acedb0

View File

@ -97,9 +97,9 @@
</ContentWrap> </ContentWrap>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useUserStore } from '@/store/modules/user'
import { setConfAndFields2 } from '@/utils/formCreate' import { setConfAndFields2 } from '@/utils/formCreate'
import type { ApiAttrs } from '@form-create/element-ui/types/config' import type { ApiAttrs } from '@form-create/element-ui/types/config'
import { useUserStore } from '@/store/modules/user'
import * as DefinitionApi from '@/api/bpm/definition' import * as DefinitionApi from '@/api/bpm/definition'
import * as ProcessInstanceApi from '@/api/bpm/processInstance' import * as ProcessInstanceApi from '@/api/bpm/processInstance'
import * as TaskApi from '@/api/bpm/task' import * as TaskApi from '@/api/bpm/task'
@ -177,16 +177,19 @@ const handleBack = async (task) => {
console.log(task) console.log(task)
} }
// ========== ========== /** 获得详情 */
onMounted(() => {
getDetail()
})
const getDetail = () => { const getDetail = () => {
// 1. // 1.
getProcessInstance()
// 2.
getTaskList()
}
/** 加载流程实例 */
const getProcessInstance = async () => {
try {
processInstanceLoading.value = true processInstanceLoading.value = true
ProcessInstanceApi.getProcessInstanceApi(id) const data = await ProcessInstanceApi.getProcessInstanceApi(id)
.then((data) => {
if (!data) { if (!data) {
message.error('查询不到流程信息!') message.error('查询不到流程信息!')
return return
@ -210,29 +213,26 @@ const getDetail = () => {
} }
// //
DefinitionApi.getProcessDefinitionBpmnXML(processDefinition.id).then((data) => { bpmnXML.value = await DefinitionApi.getProcessDefinitionBpmnXML(processDefinition.id)
bpmnXML.value = data } finally {
})
})
.finally(() => {
processInstanceLoading.value = false processInstanceLoading.value = false
}) }
}
// 2. /** 加载任务列表 */
const getTaskList = async () => {
try {
//
tasksLoad.value = true tasksLoad.value = true
runningTasks.value = [] const data = await TaskApi.getTaskListByProcessInstanceId(id)
auditForms.value = []
TaskApi.getTaskListByProcessInstanceId(id)
.then((data) => {
//
tasks.value = [] tasks.value = []
// // 1.1
data.forEach((task) => { data.forEach((task) => {
if (task.result !== 4) { if (task.result !== 4) {
tasks.value.push(task) tasks.value.push(task)
} }
}) })
// // 1.2
tasks.value.sort((a, b) => { tasks.value.sort((a, b) => {
// //
if (a.endTime && b.endTime) { if (a.endTime && b.endTime) {
@ -247,25 +247,31 @@ const getDetail = () => {
} }
}) })
// //
runningTasks.value = []
auditForms.value = []
tasks.value.forEach((task) => { tasks.value.forEach((task) => {
// 1.1 // 2.1
if (task.result !== 1) { if (task.result !== 1) {
return return
} }
// 1.2 // 2.2
if (!task.assigneeUser || task.assigneeUser.id !== userId) { if (!task.assigneeUser || task.assigneeUser.id !== userId) {
return return
} }
// 2. // 2.3
runningTasks.value.push({ ...task }) runningTasks.value.push({ ...task })
auditForms.value.push({ auditForms.value.push({
reason: '' reason: ''
}) })
}) })
}) } finally {
.finally(() => {
tasksLoad.value = false tasksLoad.value = false
})
} }
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script> </script>