index_new.vue 12 KB

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