Skip to content

Commit f740670

Browse files
author
puhui999
committed
流程表单:使用异步组件的方式动态加载业务表单指定的查看表单的组件,直接显示到审批页面,不再需要点击查看
1 parent 604b886 commit f740670

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

src/utils/routerHelper.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
import type { RouteLocationNormalized, Router, RouteRecordNormalized } from 'vue-router'
12
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
2-
import type { Router, RouteLocationNormalized, RouteRecordNormalized } from 'vue-router'
33
import { isUrl } from '@/utils/is'
4-
import { omit, cloneDeep } from 'lodash-es'
4+
import { cloneDeep, omit } from 'lodash-es'
55

66
const modules = import.meta.glob('../views/**/*.{vue,tsx}')
7-
7+
/**
8+
* 注册一个异步组件
9+
* @param componentPath 例:/bpm/oa/leave/detail
10+
*/
11+
export const registerComponent = (componentPath: string) => {
12+
for (const item in modules) {
13+
if (item.includes(componentPath)) {
14+
// 使用异步组件的方式来动态加载组件
15+
// @ts-ignore
16+
return defineAsyncComponent(modules[item])
17+
}
18+
}
19+
}
820
/* Layout */
921
export const Layout = () => import('@/layout/Layout.vue')
1022

src/views/bpm/oa/leave/detail.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<ContentWrap>
3-
<el-descriptions border :column="1">
3+
<el-descriptions :column="1" border>
44
<el-descriptions-item label="请假类型">
55
<dict-tag :type="DICT_TYPE.BPM_OA_LEAVE_TYPE" :value="detailData.type" />
66
</el-descriptions-item>
@@ -21,6 +21,7 @@ import { DICT_TYPE } from '@/utils/dict'
2121
import { formatDate } from '@/utils/formatTime'
2222
import { propTypes } from '@/utils/propTypes'
2323
import * as LeaveApi from '@/api/bpm/leave'
24+
2425
const { query } = useRoute() // 查询参数
2526
2627
const props = defineProps({
@@ -34,7 +35,7 @@ const queryId = query.id as unknown as number // 从 URL 传递过来的 id 编
3435
const getInfo = async () => {
3536
detailLoading.value = true
3637
try {
37-
detailData.value = await LeaveApi.getLeave(queryId || props.id)
38+
detailData.value = await LeaveApi.getLeave(props.id || queryId)
3839
} finally {
3940
detailLoading.value = false
4041
}

src/views/bpm/processInstance/detail/index.vue

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,78 @@
22
<ContentWrap>
33
<!-- 审批信息 -->
44
<el-card
5-
class="box-card"
6-
v-loading="processInstanceLoading"
75
v-for="(item, index) in runningTasks"
86
:key="index"
7+
v-loading="processInstanceLoading"
8+
class="box-card"
99
>
1010
<template #header>
1111
<span class="el-icon-picture-outline">审批任务【{{ item.name }}】</span>
1212
</template>
13-
<el-col :span="16" :offset="6">
13+
<el-col :offset="6" :span="16">
1414
<el-form
1515
:ref="'form' + index"
1616
:model="auditForms[index]"
1717
:rules="auditRule"
1818
label-width="100px"
1919
>
20-
<el-form-item label="流程名" v-if="processInstance && processInstance.name">
20+
<el-form-item v-if="processInstance && processInstance.name" label="流程名">
2121
{{ processInstance.name }}
2222
</el-form-item>
23-
<el-form-item label="流程发起人" v-if="processInstance && processInstance.startUser">
23+
<el-form-item v-if="processInstance && processInstance.startUser" label="流程发起人">
2424
{{ processInstance.startUser.nickname }}
25-
<el-tag type="info" size="small">{{ processInstance.startUser.deptName }}</el-tag>
25+
<el-tag size="small" type="info">{{ processInstance.startUser.deptName }}</el-tag>
2626
</el-form-item>
2727
<el-form-item label="审批建议" prop="reason">
2828
<el-input
29-
type="textarea"
3029
v-model="auditForms[index].reason"
3130
placeholder="请输入审批建议"
31+
type="textarea"
3232
/>
3333
</el-form-item>
3434
</el-form>
3535
<div style="margin-left: 10%; margin-bottom: 20px; font-size: 14px">
3636
<el-button type="success" @click="handleAudit(item, true)">
37-
<Icon icon="ep:select" /> 通过
37+
<Icon icon="ep:select" />
38+
通过
3839
</el-button>
3940
<el-button type="danger" @click="handleAudit(item, false)">
40-
<Icon icon="ep:close" /> 不通过
41+
<Icon icon="ep:close" />
42+
不通过
4143
</el-button>
4244
<el-button type="primary" @click="openTaskUpdateAssigneeForm(item.id)">
43-
<Icon icon="ep:edit" /> 转办
45+
<Icon icon="ep:edit" />
46+
转办
4447
</el-button>
4548
<el-button type="primary" @click="handleDelegate(item)">
46-
<Icon icon="ep:position" /> 委派
49+
<Icon icon="ep:position" />
50+
委派
4751
</el-button>
4852
<el-button type="warning" @click="handleBack(item)">
49-
<Icon icon="ep:back" /> 回退
53+
<Icon icon="ep:back" />
54+
回退
5055
</el-button>
5156
</div>
5257
</el-col>
5358
</el-card>
5459

5560
<!-- 申请信息 -->
56-
<el-card class="box-card" v-loading="processInstanceLoading">
61+
<el-card v-loading="processInstanceLoading" class="box-card">
5762
<template #header>
5863
<span class="el-icon-document">申请信息【{{ processInstance.name }}】</span>
5964
</template>
6065
<!-- 情况一:流程表单 -->
61-
<el-col v-if="processInstance?.processDefinition?.formType === 10" :span="16" :offset="6">
66+
<el-col v-if="processInstance?.processDefinition?.formType === 10" :offset="6" :span="16">
6267
<form-create
6368
ref="fApi"
64-
:rule="detailForm.rule"
65-
:option="detailForm.option"
6669
v-model="detailForm.value"
70+
:option="detailForm.option"
71+
:rule="detailForm.rule"
6772
/>
6873
</el-col>
69-
<!-- 情况二:流程表单 -->
74+
<!-- 情况二:业务表单 -->
7075
<div v-if="processInstance?.processDefinition?.formType === 20">
71-
<router-link
72-
:to="
73-
processInstance.processDefinition.formCustomViewPath +
74-
'?id=' +
75-
processInstance.businessKey
76-
"
77-
>
78-
<el-button type="primary"><Icon icon="ep:view" /> 点击查看</el-button>
79-
</router-link>
76+
<autoComponent :id="processInstance.businessKey" />
8077
</div>
8178
</el-card>
8279

@@ -85,18 +82,18 @@
8582

8683
<!-- 高亮流程图 -->
8784
<ProcessInstanceBpmnViewer
88-
:id="id"
89-
:process-instance="processInstance"
85+
:id="`${id}`"
86+
:bpmn-xml="bpmnXML"
9087
:loading="processInstanceLoading"
88+
:process-instance="processInstance"
9189
:tasks="tasks"
92-
:bpmn-xml="bpmnXML"
9390
/>
9491

9592
<!-- 弹窗:转派审批人 -->
9693
<TaskUpdateAssigneeForm ref="taskUpdateAssigneeFormRef" @success="getDetail" />
9794
</ContentWrap>
9895
</template>
99-
<script setup lang="ts" name="BpmProcessInstanceDetail">
96+
<script lang="ts" name="BpmProcessInstanceDetail" setup>
10097
import { useUserStore } from '@/store/modules/user'
10198
import { setConfAndFields2 } from '@/utils/formCreate'
10299
import type { ApiAttrs } from '@form-create/element-ui/types/config'
@@ -106,6 +103,8 @@ import * as TaskApi from '@/api/bpm/task'
106103
import TaskUpdateAssigneeForm from './TaskUpdateAssigneeForm.vue'
107104
import ProcessInstanceBpmnViewer from './ProcessInstanceBpmnViewer.vue'
108105
import ProcessInstanceTaskList from './ProcessInstanceTaskList.vue'
106+
import { registerComponent } from '@/utils/routerHelper'
107+
109108
const { query } = useRoute() // 查询参数
110109
const message = useMessage() // 消息弹窗
111110
const { proxy } = getCurrentInstance() as any
@@ -184,7 +183,7 @@ const getDetail = () => {
184183
// 2. 获得流程任务列表(审批记录)
185184
getTaskList()
186185
}
187-
186+
const autoComponent = ref(null) // 异步组件
188187
/** 加载流程实例 */
189188
const getProcessInstance = async () => {
190189
try {
@@ -195,7 +194,7 @@ const getProcessInstance = async () => {
195194
return
196195
}
197196
processInstance.value = data
198-
197+
autoComponent.value = registerComponent(data.processDefinition.formCustomViewPath)
199198
// 设置表单信息
200199
const processDefinition = data.processDefinition
201200
if (processDefinition.formType === 10) {
@@ -213,7 +212,7 @@ const getProcessInstance = async () => {
213212
}
214213
215214
// 加载流程图
216-
bpmnXML.value = await DefinitionApi.getProcessDefinitionBpmnXML(processDefinition.id)
215+
bpmnXML.value = await DefinitionApi.getProcessDefinitionBpmnXML(processDefinition.id as number)
217216
} finally {
218217
processInstanceLoading.value = false
219218
}

0 commit comments

Comments
 (0)