index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <XTable @register="registerTable">
  5. <template #toolbar_buttons>
  6. <!-- 操作:新增 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. title="新建流程"
  11. v-hasPermi="['bpm:process-instance:query']"
  12. @click="handleCreate"
  13. />
  14. </template>
  15. <!-- 当前审批任务 -->
  16. <template #tasks_default="{ row }">
  17. <el-button
  18. v-for="task in row.tasks"
  19. :key="task.id"
  20. type="text"
  21. @click="handleFormDetail(task.id)"
  22. >
  23. <span>{{ task.name }}</span>
  24. </el-button>
  25. </template>
  26. <!-- 操作 -->
  27. <template #actionbtns_default="{ row }">
  28. <XButton
  29. type="primary"
  30. title="取消"
  31. v-if="row.result === 1"
  32. preIcon="ep:delete"
  33. @click="handleCancel(row)"
  34. />
  35. <XButton type="primary" title="详情" preIcon="ep:edit-pen" @click="handleDetail(row)" />
  36. </template>
  37. </XTable>
  38. </ContentWrap>
  39. </template>
  40. <script setup lang="ts">
  41. // 全局相关的 import
  42. import { ref } from 'vue'
  43. import { ElMessage, ElMessageBox } from 'element-plus'
  44. import { useXTable } from '@/hooks/web/useXTable'
  45. import { useRouter } from 'vue-router'
  46. // 业务相关的 import
  47. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  48. // import { decodeFields } from '@/utils/formGenerator' // TODO 芋艿:后续根据情况清理
  49. import { allSchemas } from './process.data'
  50. const router = useRouter() // 路由
  51. // ========== 列表相关 ==========
  52. const [registerTable] = useXTable({
  53. allSchemas: allSchemas,
  54. getListApi: ProcessInstanceApi.getMyProcessInstancePageApi
  55. })
  56. // 流程表单的弹出框
  57. const detailOpen = ref(false)
  58. const detailForm = ref()
  59. /** 发起流程操作 **/
  60. const handleCreate = () => {
  61. router.push({
  62. name: 'BpmProcessInstanceCreate'
  63. })
  64. }
  65. /** 流程表单的详情按钮操作 */
  66. const handleFormDetail = (row) => {
  67. // 情况一:使用流程表单
  68. if (row.formId) {
  69. // 设置值 TODO 芋艿:动态表单做完后,需要测试下
  70. detailForm.value = {
  71. ...JSON.parse(row.formConf),
  72. fields: decodeFields([], row.formFields)
  73. }
  74. // 弹窗打开
  75. detailOpen.value = true
  76. // 情况二:使用业务表单
  77. } else if (row.formCustomCreatePath) {
  78. router.push({ path: row.formCustomCreatePath })
  79. }
  80. }
  81. // 列表操作
  82. const handleDetail = (row) => {
  83. console.log(row, 'row')
  84. router.push({ path: '/process-instance/detail', query: { id: row.id } })
  85. }
  86. /** 取消按钮操作 */
  87. const handleCancel = (row) => {
  88. const id = row.id
  89. ElMessageBox.prompt('请输入取消原因?', '取消流程', {
  90. type: 'warning',
  91. confirmButtonText: '确定',
  92. cancelButtonText: '取消',
  93. inputPattern: /^[\s\S]*.*\S[\s\S]*$/, // 判断非空,且非空格
  94. inputErrorMessage: '取消原因不能为空'
  95. })
  96. .then(({ value }) => {
  97. return ProcessInstanceApi.cancelProcessInstanceApi(id, value)
  98. })
  99. .then(() => {
  100. ElMessage({
  101. message: '取消成功',
  102. type: 'success'
  103. })
  104. })
  105. }
  106. </script>