InstanceDetail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <template>
  2. <el-drawer
  3. v-model="visible"
  4. title="流程详情"
  5. direction="rtl"
  6. size="55%"
  7. :close-on-click-modal="false"
  8. :destroy-on-close="true"
  9. @closed="handleClose"
  10. >
  11. <div v-loading="loading" class="detail-content">
  12. <FilePreview v-model="previewVisible" :url="previewUrl" />
  13. <!-- 流程基本信息 -->
  14. <div class="info-section">
  15. <el-descriptions :column="3" size="small" border>
  16. <el-descriptions-item label="流程名称">{{ progress?.definition?.name }}</el-descriptions-item>
  17. <el-descriptions-item label="实例编号">{{ progress?.instance?.instanceNo || progress?.instance?.id }}</el-descriptions-item>
  18. <el-descriptions-item label="状态">
  19. <el-tag :type="instanceStatusTagType(progress?.instance?.status)">
  20. {{ instanceStatusText(progress?.instance?.status) }}
  21. </el-tag>
  22. </el-descriptions-item>
  23. <el-descriptions-item label="剩余节点">
  24. <el-tag type="warning">{{ progress?.remainingNodeCount || 0 }} 个待审批</el-tag>
  25. </el-descriptions-item>
  26. <el-descriptions-item label="发起时间">{{ progress?.instance?.startTime }}</el-descriptions-item>
  27. <el-descriptions-item label="结束时间">{{ progress?.instance?.endTime || '-' }}</el-descriptions-item>
  28. </el-descriptions>
  29. </div>
  30. <!-- 表单数据 -->
  31. <div v-if="formDataDisplay" class="form-data-section">
  32. <h4>表单数据</h4>
  33. <FormDataDisplay
  34. :form-schema="progress?.definition?.formSchema"
  35. :form-data="progress?.instance?.formData"
  36. />
  37. </div>
  38. <!-- 附件列表 -->
  39. <div class="attachment-section">
  40. <h4>附件列表</h4>
  41. <div v-if="attachments.length > 0" class="attachment-list">
  42. <div v-for="att in attachments" :key="att.id" class="attachment-item">
  43. <el-link type="primary" @click="openPreview(att.fileUrl)">
  44. <el-icon><Document /></el-icon>
  45. <span class="attachment-name" :title="att.fileName">{{ att.fileName }}</span>
  46. </el-link>
  47. <span class="attachment-meta">
  48. {{ att.nodeName || '发起' }}
  49. <template v-if="att.uploaderName">· {{ att.uploaderName }}</template>
  50. <template v-if="att.createTime">· {{ att.createTime }}</template>
  51. </span>
  52. <el-image
  53. v-if="isImage(att.fileUrl)"
  54. :src="getFileUrl(att.fileUrl)"
  55. :preview-src-list="imagePreviewList"
  56. fit="cover"
  57. style="width: 60px; height: 60px; margin-left: 8px;"
  58. />
  59. </div>
  60. </div>
  61. <el-empty v-else description="暂无附件" :image-size="60" style="padding: 10px 0;" />
  62. </div>
  63. <el-divider />
  64. <div class="detail-body">
  65. <!-- 左侧:流程节点时间线 -->
  66. <div class="timeline-section">
  67. <h4>流程进度</h4>
  68. <el-timeline>
  69. <el-timeline-item
  70. v-for="node in progress?.nodes"
  71. :key="node.nodeId"
  72. :type="timelineType(node.status)"
  73. :icon="timelineIcon(node.status)"
  74. :color="timelineColor(node.status)"
  75. >
  76. <div class="node-item" :class="{ 'current-node': node.status === 'current' }">
  77. <div class="node-title">
  78. <span class="node-name">{{ node.nodeName }}</span>
  79. <el-tag v-if="node.isMyTurn" type="danger" size="small" effect="dark">待我处理</el-tag>
  80. </div>
  81. <div v-if="node.tasks?.length" class="node-tasks">
  82. <div
  83. v-for="task in node.tasks"
  84. :key="task.id"
  85. class="task-item"
  86. >
  87. <span class="task-assignee">{{ task.assigneeName || '用户' + task.assigneeId }}</span>
  88. <el-tag :type="taskStatusType(task.status)" size="small">
  89. {{ taskStatusText(task.status) }}
  90. </el-tag>
  91. <span v-if="task.comment" class="task-comment">{{ task.comment }}</span>
  92. </div>
  93. </div>
  94. </div>
  95. </el-timeline-item>
  96. </el-timeline>
  97. </div>
  98. <!-- 右侧:审批操作区 -->
  99. <div class="action-section">
  100. <template v-if="myPendingTask">
  101. <h4>审批操作</h4>
  102. <el-form ref="formRef" :model="form" label-width="80px">
  103. <el-form-item label="操作">
  104. <el-radio-group v-model="form.action">
  105. <el-radio label="pass">通过</el-radio>
  106. <el-radio label="reject">拒绝</el-radio>
  107. <el-radio label="rollback">回退</el-radio>
  108. <el-radio label="transfer">转办</el-radio>
  109. </el-radio-group>
  110. </el-form-item>
  111. <el-form-item v-if="form.action === 'rollback'" label="回退到">
  112. <el-select v-model="form.targetNodeId" filterable placeholder="请选择回退节点" style="width: 100%">
  113. <el-option
  114. v-for="node in rollbackNodeOptions"
  115. :key="node.nodeId"
  116. :label="node.nodeName"
  117. :value="node.nodeId"
  118. />
  119. </el-select>
  120. </el-form-item>
  121. <el-form-item v-if="form.action === 'transfer'" label="转给人">
  122. <el-select v-model="form.transferTo" filterable placeholder="请选择转办人" style="width: 100%">
  123. <el-option v-for="u in userList" :key="u.id" :label="u.realName || u.username" :value="u.id" />
  124. </el-select>
  125. </el-form-item>
  126. <el-form-item label="附件">
  127. <el-upload
  128. v-model:file-list="attachmentList"
  129. action="#"
  130. :http-request="handleUpload"
  131. :before-upload="beforeFileUpload"
  132. :before-remove="() => true"
  133. :limit="5"
  134. multiple
  135. :on-preview="handleFilePreview"
  136. >
  137. <el-button type="primary" size="small">上传附件</el-button>
  138. </el-upload>
  139. </el-form-item>
  140. <el-form-item label="意见">
  141. <el-input v-model="form.comment" type="textarea" placeholder="请输入审批意见" />
  142. </el-form-item>
  143. <el-form-item>
  144. <el-button type="primary" :loading="submitting" @click="submitApprove">提交</el-button>
  145. <el-button :loading="submitting" @click="handleAddSign">加签</el-button>
  146. </el-form-item>
  147. </el-form>
  148. </template>
  149. <template v-else>
  150. <el-empty description="当前没有需要您处理的审批任务" />
  151. </template>
  152. <el-divider />
  153. <!-- 审批历史 -->
  154. <h4>审批历史</h4>
  155. <div v-if="progress?.records?.length" class="record-list">
  156. <div
  157. v-for="record in progress.records"
  158. :key="record.id"
  159. class="record-item"
  160. >
  161. <div class="record-header">
  162. <span class="record-operator">{{ record.operatorName || '用户' + record.operatorId }}</span>
  163. <el-tag :type="recordActionType(record.actionResult)" size="small">
  164. {{ recordActionText(record.actionResult) }}
  165. </el-tag>
  166. <span class="record-time">{{ record.createTime }}</span>
  167. </div>
  168. <div v-if="record.comment" class="record-comment">{{ record.comment }}</div>
  169. <div v-if="record.attachmentUrls" class="record-attachments">
  170. <el-link
  171. v-for="(url, idx) in parseAttachments(record.attachmentUrls)"
  172. :key="idx"
  173. type="primary"
  174. @click="openPreview(url)"
  175. size="small"
  176. >
  177. 附件{{ idx + 1 }}: {{ getFileName(url) }}
  178. </el-link>
  179. </div>
  180. </div>
  181. </div>
  182. <el-empty v-else description="暂无审批记录" />
  183. </div>
  184. </div>
  185. </div>
  186. </el-drawer>
  187. <!-- 加签弹窗 -->
  188. <el-dialog
  189. v-model="addSignDialogVisible"
  190. title="加签"
  191. width="400px"
  192. :close-on-click-modal="false"
  193. >
  194. <el-select v-model="addSignUserId" filterable placeholder="请选择加签人" style="width: 100%">
  195. <el-option v-for="u in userList" :key="u.id" :label="u.realName || u.username" :value="u.id" />
  196. </el-select>
  197. <template #footer>
  198. <el-button @click="addSignDialogVisible = false">取消</el-button>
  199. <el-button type="primary" :loading="submitting" @click="confirmAddSign">确认</el-button>
  200. </template>
  201. </el-dialog>
  202. </template>
  203. <script setup lang="ts">
  204. import { ref, reactive, computed, watch } from 'vue'
  205. import { ElMessage } from 'element-plus'
  206. import { getProgress, getInstanceAttachments } from '@/api/flow/instance'
  207. import { approveTask, rejectTask, returnTask, transferTask, addSignTask, getTransferableUsers } from '@/api/flow/task'
  208. import { uploadFile } from '@/api/file'
  209. import { beforeFileUpload, getFileUrl, getFileName, getUploadUrl, parseAttachments, collectAttachmentUrls } from '@/utils/file'
  210. import { instanceStatusText, instanceStatusTagType, taskStatusText, taskStatusType, recordActionText, recordActionType } from '@/utils/flow'
  211. import FilePreview from '@/components/FilePreview/index.vue'
  212. import FormDataDisplay from '@/components/FormDataDisplay/index.vue'
  213. import type { ProcessProgress, FlowTask, NodeProgress, ApprovalAction, Attachment } from '@/types/flow'
  214. import type { User } from '@/types/system'
  215. import { CircleCheck, Clock, Document } from '@element-plus/icons-vue'
  216. const props = defineProps<{
  217. modelValue: boolean
  218. instanceId: number
  219. }>()
  220. const emit = defineEmits<{
  221. (e: 'update:modelValue', val: boolean): void
  222. (e: 'approved'): void
  223. }>()
  224. const visible = computed({
  225. get: () => props.modelValue,
  226. set: (val) => emit('update:modelValue', val)
  227. })
  228. const loading = ref(false)
  229. const previewVisible = ref(false)
  230. const previewUrl = ref('')
  231. const progress = ref<ProcessProgress | null>(null)
  232. type ApprovalActionType = 'pass' | 'reject' | 'rollback' | 'transfer'
  233. const form = reactive<{
  234. action: ApprovalActionType
  235. comment: string
  236. transferTo: number | undefined
  237. targetNodeId: string | undefined
  238. }>({
  239. action: 'pass',
  240. comment: '',
  241. transferTo: undefined,
  242. targetNodeId: undefined
  243. })
  244. const attachmentList = ref<any[]>([])
  245. const submitting = ref(false)
  246. const addSignDialogVisible = ref(false)
  247. const addSignUserId = ref<number | undefined>(undefined)
  248. const rollbackNodeOptions = computed<NodeProgress[]>(() => {
  249. if (!progress.value) return []
  250. return progress.value.nodes.filter(n => n.status === 'completed')
  251. })
  252. const userList = ref<User[]>([])
  253. async function loadTransferableUsers() {
  254. const task = myPendingTask.value
  255. if (!task) {
  256. userList.value = []
  257. return
  258. }
  259. try {
  260. // 按当前节点审批角色过滤可选用户,已自动排除当前登录人
  261. userList.value = await getTransferableUsers(task.id)
  262. } catch {
  263. userList.value = []
  264. }
  265. }
  266. // 是否有表单数据用于展示
  267. const formDataDisplay = computed(() => {
  268. return !!progress.value?.instance?.formData
  269. })
  270. const attachments = ref<Attachment[]>([])
  271. // 实例附件列表(从附件表读取,包含所有节点上传的历史附件)
  272. const instanceAttachments = computed(() => {
  273. return attachments.value.map(a => a.fileUrl)
  274. })
  275. // 图片预览列表
  276. const imagePreviewList = computed(() => {
  277. return attachments.value.filter(a => isImage(a.fileUrl)).map(a => getFileUrl(a.fileUrl))
  278. })
  279. async function loadAttachments() {
  280. if (!props.instanceId) return
  281. try {
  282. attachments.value = await getInstanceAttachments(props.instanceId)
  283. } catch {
  284. attachments.value = []
  285. }
  286. }
  287. function handleFilePreview(file: any) {
  288. const url = getUploadUrl(file)
  289. if (url) openPreview(url)
  290. }
  291. function openPreview(url: string) {
  292. previewUrl.value = url
  293. previewVisible.value = true
  294. }
  295. function isImage(url: string): boolean {
  296. return /\.(png|jpe?g|gif|webp|bmp)$/i.test(url)
  297. }
  298. async function handleUpload(options: any) {
  299. try {
  300. const res = await uploadFile(options.file)
  301. options.onSuccess(res)
  302. } catch (e) {
  303. options.onError(e)
  304. }
  305. }
  306. // 查找当前登录用户需要处理的待办任务
  307. const myPendingTask = computed<FlowTask | null>(() => {
  308. if (!progress.value) return null
  309. for (const node of progress.value.nodes) {
  310. if (node.isMyTurn && node.tasks) {
  311. const pending = node.tasks.find(t => t.status === 0)
  312. if (pending) return pending
  313. }
  314. }
  315. return null
  316. })
  317. function timelineType(status: string) {
  318. if (status === 'completed') return 'success'
  319. if (status === 'current') return 'warning'
  320. return 'info'
  321. }
  322. function timelineIcon(status: string) {
  323. if (status === 'completed') return CircleCheck
  324. if (status === 'current') return Clock
  325. return undefined
  326. }
  327. function timelineColor(status: string) {
  328. if (status === 'completed') return '#67C23A'
  329. if (status === 'current') return '#E6A23C'
  330. return '#909399'
  331. }
  332. async function loadProgress() {
  333. if (!props.instanceId) return
  334. loading.value = true
  335. try {
  336. // 静默加载进度,无权限时不在详情页弹全局错误提示
  337. const res = await getProgress(props.instanceId, { silent: true })
  338. progress.value = res
  339. } catch {
  340. progress.value = null
  341. } finally {
  342. loading.value = false
  343. }
  344. }
  345. async function submitApprove() {
  346. const task = myPendingTask.value
  347. if (!task) return
  348. if (form.action === 'transfer' && !form.transferTo) {
  349. ElMessage.warning('请选择转办人')
  350. return
  351. }
  352. if (form.action === 'rollback' && !form.targetNodeId) {
  353. ElMessage.warning('请选择回退节点')
  354. return
  355. }
  356. submitting.value = true
  357. try {
  358. const data: ApprovalAction = {
  359. action: form.action,
  360. comment: form.comment
  361. }
  362. if (form.action === 'transfer' && form.transferTo) {
  363. data.transferTo = Number(form.transferTo)
  364. }
  365. if (form.action === 'rollback' && form.targetNodeId) {
  366. data.targetNodeId = form.targetNodeId
  367. }
  368. if (attachmentList.value.length > 0) {
  369. data.attachmentUrls = collectAttachmentUrls(attachmentList.value)
  370. }
  371. switch (form.action) {
  372. case 'pass':
  373. await approveTask(task.id, data)
  374. break
  375. case 'reject':
  376. await rejectTask(task.id, data)
  377. break
  378. case 'rollback':
  379. await returnTask(task.id, data)
  380. break
  381. case 'transfer':
  382. await transferTask(task.id, data)
  383. break
  384. }
  385. ElMessage.success('审批提交成功')
  386. form.action = 'pass'
  387. form.comment = ''
  388. form.transferTo = undefined
  389. form.targetNodeId = undefined
  390. attachmentList.value = []
  391. // 刷新进度展示最新状态,不关闭抽屉
  392. await loadProgress()
  393. emit('approved')
  394. } finally {
  395. submitting.value = false
  396. }
  397. }
  398. function handleClose() {
  399. progress.value = null
  400. attachmentList.value = []
  401. attachments.value = []
  402. }
  403. function handleAddSign() {
  404. const task = myPendingTask.value
  405. if (!task) return
  406. addSignUserId.value = undefined
  407. addSignDialogVisible.value = true
  408. }
  409. async function confirmAddSign() {
  410. const task = myPendingTask.value
  411. if (!task || !addSignUserId.value) {
  412. ElMessage.warning('请选择加签人')
  413. return
  414. }
  415. submitting.value = true
  416. try {
  417. await addSignTask(task.id, addSignUserId.value)
  418. ElMessage.success('加签成功')
  419. addSignDialogVisible.value = false
  420. addSignUserId.value = undefined
  421. await loadProgress()
  422. } finally {
  423. submitting.value = false
  424. }
  425. }
  426. watch(() => props.instanceId, (id) => {
  427. if (id && props.modelValue) {
  428. loadProgress()
  429. }
  430. })
  431. watch(() => props.modelValue, async (val) => {
  432. if (val && props.instanceId) {
  433. await loadProgress()
  434. await loadTransferableUsers()
  435. loadAttachments()
  436. }
  437. })
  438. </script>
  439. <style scoped>
  440. .detail-content {
  441. height: calc(100vh - 120px);
  442. overflow-y: auto;
  443. padding-right: 8px;
  444. }
  445. .info-section {
  446. margin-bottom: 10px;
  447. }
  448. .form-data-section,
  449. .attachment-section {
  450. margin-bottom: 10px;
  451. }
  452. .form-data-section h4,
  453. .attachment-section h4 {
  454. margin: 0 0 8px 0;
  455. font-size: 15px;
  456. color: #303133;
  457. }
  458. .attachment-list {
  459. display: flex;
  460. flex-wrap: wrap;
  461. gap: 8px;
  462. }
  463. .attachment-item {
  464. display: flex;
  465. align-items: center;
  466. flex-wrap: wrap;
  467. gap: 8px;
  468. padding: 8px 12px;
  469. background: #f5f7fa;
  470. border-radius: 4px;
  471. }
  472. .attachment-name {
  473. max-width: 220px;
  474. overflow: hidden;
  475. text-overflow: ellipsis;
  476. white-space: nowrap;
  477. }
  478. .attachment-meta {
  479. font-size: 12px;
  480. color: #909399;
  481. }
  482. .detail-body {
  483. display: flex;
  484. gap: 24px;
  485. }
  486. .timeline-section {
  487. flex: 1;
  488. min-width: 0;
  489. }
  490. .action-section {
  491. flex: 1;
  492. min-width: 0;
  493. border-left: 1px solid #ebeef5;
  494. padding-left: 24px;
  495. }
  496. .timeline-section h4,
  497. .action-section h4 {
  498. margin: 0 0 16px 0;
  499. font-size: 15px;
  500. color: #303133;
  501. }
  502. .node-item {
  503. padding: 4px 0;
  504. }
  505. .node-item.current-node {
  506. background: #fdf6ec;
  507. padding: 8px;
  508. border-radius: 4px;
  509. }
  510. .node-title {
  511. display: flex;
  512. align-items: center;
  513. gap: 8px;
  514. margin-bottom: 6px;
  515. }
  516. .node-name {
  517. font-weight: bold;
  518. color: #303133;
  519. }
  520. .node-tasks {
  521. padding-left: 8px;
  522. }
  523. .task-item {
  524. display: flex;
  525. align-items: center;
  526. gap: 8px;
  527. font-size: 13px;
  528. color: #606266;
  529. margin: 4px 0;
  530. }
  531. .task-comment {
  532. color: #909399;
  533. }
  534. .record-list {
  535. max-height: 300px;
  536. overflow-y: auto;
  537. }
  538. .record-item {
  539. padding: 10px 0;
  540. border-bottom: 1px solid #ebeef5;
  541. }
  542. .record-item:last-child {
  543. border-bottom: none;
  544. }
  545. .record-header {
  546. display: flex;
  547. align-items: center;
  548. gap: 10px;
  549. margin-bottom: 6px;
  550. }
  551. .record-operator {
  552. font-weight: bold;
  553. color: #303133;
  554. }
  555. .record-time {
  556. font-size: 12px;
  557. color: #909399;
  558. }
  559. .record-comment {
  560. font-size: 13px;
  561. color: #606266;
  562. background: #f5f7fa;
  563. padding: 6px 10px;
  564. border-radius: 4px;
  565. margin-bottom: 6px;
  566. }
  567. .record-attachments {
  568. display: flex;
  569. flex-wrap: wrap;
  570. gap: 8px;
  571. }
  572. </style>