index_new.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <ContentWrap :bodyStyle="{ padding: '10px 20px' }" class="position-relative">
  3. <div class="processInstance-wrap-main">
  4. <el-scrollbar>
  5. <img
  6. class="position-absolute right-20px"
  7. width="150"
  8. :src="auditIcons[processInstance.status]"
  9. alt=""
  10. />
  11. <div class="text-#878c93 h-15px">编号:{{ id }}</div>
  12. <el-divider class="!my-8px" />
  13. <div class="flex items-center gap-5 mb-10px h-40px">
  14. <div class="text-26px font-bold mb-5px">{{ processInstance.name }}</div>
  15. <dict-tag
  16. v-if="processInstance.status"
  17. :type="DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS"
  18. :value="processInstance.status"
  19. />
  20. </div>
  21. <div class="flex items-center gap-5 mb-10px text-13px h-35px">
  22. <div
  23. class="bg-gray-100 h-35px rounded-3xl flex items-center p-8px gap-2 dark:color-gray-600"
  24. >
  25. <!-- <img class="rounded-full h-28px" src="@/assets/imgs/avatar.jpg" alt="" /> -->
  26. <el-avatar
  27. :size="28"
  28. v-if="processInstance?.startUser?.avatar"
  29. :src="processInstance?.startUser?.avatar"
  30. />
  31. <el-avatar :size="28" v-else-if="processInstance?.startUser?.nickname">
  32. {{ processInstance?.startUser?.nickname.substring(0, 1) }}
  33. </el-avatar>
  34. {{ processInstance?.startUser?.nickname }}
  35. </div>
  36. <div class="text-#878c93"> {{ formatDate(processInstance.startTime) }} 提交 </div>
  37. </div>
  38. <el-tabs v-model="activeTab" @tab-change="onTabChange">
  39. <!-- 表单信息 -->
  40. <el-tab-pane label="审批详情" name="form">
  41. <div class="form-scroll-area">
  42. <el-scrollbar>
  43. <el-row>
  44. <el-col :span="18" class="!flex !flex-col formCol">
  45. <!-- 表单信息 -->
  46. <div
  47. v-loading="processInstanceLoading"
  48. class="form-box flex flex-col mb-30px flex-1"
  49. >
  50. <!-- 情况一:流程表单 -->
  51. <el-col v-if="processInstance?.processDefinition?.formType === 10">
  52. <form-create
  53. v-model="detailForm.value"
  54. v-model:api="fApi"
  55. :option="detailForm.option"
  56. :rule="detailForm.rule"
  57. />
  58. </el-col>
  59. <!-- 情况二:业务表单 -->
  60. <div v-if="processInstance?.processDefinition?.formType === 20">
  61. <BusinessFormComponent :id="processInstance.businessKey" />
  62. </div>
  63. </div>
  64. </el-col>
  65. <el-col :span="6">
  66. <!-- 审批记录时间线 -->
  67. <ProcessInstanceTimeline ref="timelineRef" :process-instance-id="id" />
  68. </el-col>
  69. </el-row>
  70. </el-scrollbar>
  71. </div>
  72. </el-tab-pane>
  73. <!-- 流程图 -->
  74. <el-tab-pane label="流程图" name="diagram">
  75. <div class="form-scroll-area">
  76. <ProcessInstanceBpmnViewer :id="`${id}`" :loading="processInstanceLoading" />
  77. </div>
  78. </el-tab-pane>
  79. <!-- 流转记录 -->
  80. <el-tab-pane label="流转记录" name="record">
  81. <div class="form-scroll-area">
  82. <el-scrollbar>
  83. <ProcessInstanceTaskList
  84. :loading="tasksLoad"
  85. :process-instance="processInstance"
  86. :tasks="tasks"
  87. />
  88. </el-scrollbar>
  89. </div>
  90. </el-tab-pane>
  91. <!-- 流转评论 TODO 待开发 -->
  92. <el-tab-pane label="流转评论" name="comment">
  93. <div class="form-scroll-area">
  94. <el-scrollbar> 流转评论 </el-scrollbar>
  95. </div>
  96. </el-tab-pane>
  97. </el-tabs>
  98. <div class="b-t-solid border-t-1px border-[var(--el-border-color)]">
  99. <!-- 操作栏按钮 -->
  100. <ProcessInstanceOperationButton
  101. ref="operationButtonRef"
  102. :processInstance="processInstance"
  103. :userOptions="userOptions"
  104. @success="refresh"
  105. />
  106. </div>
  107. </el-scrollbar>
  108. </div>
  109. </ContentWrap>
  110. </template>
  111. <script lang="ts" setup>
  112. import { formatDate } from '@/utils/formatTime'
  113. import { DICT_TYPE } from '@/utils/dict'
  114. import { setConfAndFields2 } from '@/utils/formCreate'
  115. import type { ApiAttrs } from '@form-create/element-ui/types/config'
  116. import * as DefinitionApi from '@/api/bpm/definition'
  117. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  118. import * as TaskApi from '@/api/bpm/task'
  119. import ProcessInstanceBpmnViewer from './ProcessInstanceBpmnViewer.vue'
  120. import ProcessInstanceTaskList from './ProcessInstanceTaskList.vue'
  121. import ProcessInstanceOperationButton from './ProcessInstanceOperationButton.vue'
  122. import ProcessInstanceTimeline from './ProcessInstanceTimeline.vue'
  123. import { registerComponent } from '@/utils/routerHelper'
  124. import * as UserApi from '@/api/system/user'
  125. import { FieldPermissionType } from '@/components/SimpleProcessDesignerV2/src/consts'
  126. import audit1 from '@/assets/svgs/bpm/audit1.svg'
  127. import audit2 from '@/assets/svgs/bpm/audit2.svg'
  128. import audit3 from '@/assets/svgs/bpm/audit3.svg'
  129. defineOptions({ name: 'BpmProcessInstanceDetail' })
  130. const props = defineProps<{
  131. id: string // 流程实例的编号
  132. taskId?: string // 任务编号
  133. activityId?: string //流程活动编号,用于抄送查看
  134. }>()
  135. const message = useMessage() // 消息弹窗
  136. const processInstanceLoading = ref(false) // 流程实例的加载中
  137. const processInstance = ref<any>({}) // 流程实例
  138. let processDefinitionId = undefined // 流程定义 Id
  139. const operationButtonRef = ref()
  140. const timelineRef = ref()
  141. const bpmnXml = ref('') // BPMN XML
  142. const tasksLoad = ref(true) // 任务的加载中
  143. const tasks = ref<any[]>([]) // 任务列表
  144. const auditIcons = {
  145. 1: audit1,
  146. 2: audit2,
  147. 3: audit3
  148. }
  149. // ========== 申请信息 ==========
  150. const fApi = ref<ApiAttrs>() //
  151. const detailForm = ref({
  152. rule: [],
  153. option: {},
  154. value: {}
  155. }) // 流程实例的表单详情
  156. /** 获得详情 */
  157. const getDetail = async () => {
  158. // 1. 获得流程实例相关
  159. getProcessInstance()
  160. // 2. 获得流程任务列表
  161. getTaskList()
  162. }
  163. /** 加载流程实例 */
  164. const BusinessFormComponent = ref<any>(null) // 异步组件
  165. const getProcessInstance = async () => {
  166. try {
  167. processInstanceLoading.value = true
  168. const data = await ProcessInstanceApi.getProcessInstance(props.id)
  169. if (!data) {
  170. message.error('查询不到流程信息!')
  171. return
  172. }
  173. processInstance.value = data
  174. // 设置表单信息
  175. const processDefinition = data.processDefinition
  176. if (processDefinition.formType === 10) {
  177. // 获取表单字段权限
  178. let fieldsPermission = undefined
  179. if (props.taskId || props.activityId) {
  180. fieldsPermission = await ProcessInstanceApi.getFormFieldsPermission({
  181. processInstanceId: props.id,
  182. taskId: props.taskId,
  183. activityId: props.activityId
  184. })
  185. }
  186. if (detailForm.value.rule.length > 0) { // 避免刷新 form-create 表单不显示
  187. detailForm.value.value = data.formVariables
  188. } else {
  189. setConfAndFields2(
  190. detailForm,
  191. processDefinition.formConf,
  192. processDefinition.formFields,
  193. data.formVariables
  194. )
  195. }
  196. nextTick().then(() => {
  197. fApi.value?.btn.show(false)
  198. fApi.value?.resetBtn.show(false)
  199. fApi.value?.disabled(true)
  200. if (fieldsPermission) {
  201. Object.keys(fieldsPermission).forEach((item) => {
  202. setFieldPermission(item, fieldsPermission[item])
  203. })
  204. }
  205. })
  206. } else {
  207. // 注意:data.processDefinition.formCustomViewPath 是组件的全路径,例如说:/crm/contract/detail/index.vue
  208. BusinessFormComponent.value = registerComponent(data.processDefinition.formCustomViewPath)
  209. }
  210. processDefinitionId = processDefinition.id
  211. // 加载流程图
  212. // bpmnXml.value = (await DefinitionApi.getProcessDefinition(processDefinition.id))?.bpmnXml
  213. } finally {
  214. processInstanceLoading.value = false
  215. }
  216. }
  217. /**
  218. * 设置表单权限
  219. */
  220. const setFieldPermission = (field: string, permission: string) => {
  221. if (permission === FieldPermissionType.READ) {
  222. fApi.value?.disabled(true, field)
  223. }
  224. if (permission === FieldPermissionType.WRITE) {
  225. fApi.value?.disabled(false, field)
  226. }
  227. if (permission === FieldPermissionType.NONE) {
  228. fApi.value?.hidden(true, field)
  229. }
  230. }
  231. /** 加载任务列表 */
  232. const getTaskList = async () => {
  233. try {
  234. // 获得未取消的任务
  235. tasksLoad.value = true
  236. const data = await TaskApi.getTaskListByProcessInstanceId(props.id)
  237. tasks.value = []
  238. // 1.1 移除已取消的审批
  239. data.forEach((task: any) => {
  240. if (task.status !== 4) {
  241. tasks.value.push(task)
  242. }
  243. })
  244. // 1.2 排序,将未完成的排在前面,已完成的排在后面;
  245. tasks.value.sort((a, b) => {
  246. // 有已完成的情况,按照完成时间倒序
  247. if (a.endTime && b.endTime) {
  248. return b.endTime - a.endTime
  249. } else if (a.endTime) {
  250. return 1
  251. } else if (b.endTime) {
  252. return -1
  253. // 都是未完成,按照创建时间倒序
  254. } else {
  255. return b.createTime - a.createTime
  256. }
  257. })
  258. // 获得需要自己审批的任务
  259. operationButtonRef.value?.loadRunningTask(tasks.value)
  260. } finally {
  261. tasksLoad.value = false
  262. }
  263. }
  264. /**
  265. * 操作成功后刷新
  266. */
  267. const refresh = () => {
  268. // 重新获取详情
  269. getDetail()
  270. // 刷新审批详情 Timeline
  271. timelineRef.value?.refresh()
  272. }
  273. /** 当前的Tab */
  274. const activeTab = ref('form')
  275. /** Tab 切换 加载流程图,直接加载显示不出来,不知道啥原因,所以切换以后在加载 */
  276. const onTabChange = async (tabName: string) => {
  277. if (tabName === 'diagram' && processDefinitionId && !bpmnXml.value) {
  278. //加载流程图
  279. bpmnXml.value = (await DefinitionApi.getProcessDefinition(processDefinitionId))?.bpmnXml
  280. }
  281. }
  282. /** 初始化 */
  283. const userOptions = ref<UserApi.UserVO[]>([]) // 用户列表
  284. onMounted(async () => {
  285. getDetail()
  286. // 获得用户列表
  287. userOptions.value = await UserApi.getSimpleUserList()
  288. })
  289. </script>
  290. <style lang="scss" scoped>
  291. $wrap-padding-height: 30px;
  292. $wrap-margin-height: 15px;
  293. $button-height: 51px;
  294. $process-header-height: 194px;
  295. .processInstance-wrap-main {
  296. height: calc(
  297. 100vh - var(--top-tool-height) - var(--tags-view-height) - var(--app-footer-height) - 45px
  298. );
  299. max-height: calc(
  300. 100vh - var(--top-tool-height) - var(--tags-view-height) - var(--app-footer-height) - 45px
  301. );
  302. overflow: auto;
  303. .form-scroll-area {
  304. height: calc(
  305. 100vh - var(--top-tool-height) - var(--tags-view-height) - var(--app-footer-height) - 45px -
  306. $process-header-height - 40px
  307. );
  308. max-height: calc(
  309. 100vh - var(--top-tool-height) - var(--tags-view-height) - var(--app-footer-height) - 45px -
  310. $process-header-height - 40px
  311. );
  312. overflow: auto;
  313. }
  314. }
  315. .form-box {
  316. :deep(.el-card) {
  317. border: none;
  318. }
  319. }
  320. </style>