index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <!-- 第一步,通过流程定义的列表,选择对应的流程 -->
  3. <template v-if="!selectProcessDefinition">
  4. <el-input
  5. v-model="currentSearchKey"
  6. class="!w-50% mb-15px"
  7. placeholder="请输入流程名称"
  8. clearable
  9. @input="handleQuery"
  10. @clear="handleQuery"
  11. >
  12. <template #prefix>
  13. <Icon icon="ep:search" />
  14. </template>
  15. </el-input>
  16. <ContentWrap
  17. :class="{ 'process-definition-container': filteredProcessDefinitionList?.length }"
  18. class="position-relative pb-20px h-700px"
  19. v-loading="loading"
  20. >
  21. <el-row v-if="filteredProcessDefinitionList?.length" :gutter="20" class="!flex-nowrap">
  22. <el-col :span="5">
  23. <div class="flex flex-col">
  24. <div
  25. v-for="category in categoryList"
  26. :key="category.code"
  27. class="flex items-center p-10px cursor-pointer text-14px rounded-md"
  28. :class="categoryActive.code === category.code ? 'text-#3e7bff bg-#e8eeff' : ''"
  29. @click="handleCategoryClick(category)"
  30. >
  31. {{ category.name }}
  32. </div>
  33. </div>
  34. </el-col>
  35. <el-col :span="19">
  36. <el-scrollbar ref="scrollWrapper" height="700">
  37. <div
  38. class="mb-20px pl-10px"
  39. v-for="(definitions, categoryCode) in processDefinitionGroup"
  40. :key="categoryCode"
  41. :ref="`category-${categoryCode}`"
  42. >
  43. <h3 class="text-18px font-bold mb-10px mt-5px">
  44. {{ getCategoryName(categoryCode) }}
  45. </h3>
  46. <div class="grid grid-cols-3 gap3">
  47. <el-tooltip
  48. v-for="definition in definitions"
  49. :key="definition.id"
  50. :content="definition.description"
  51. placement="top"
  52. >
  53. <el-card
  54. shadow="hover"
  55. class="cursor-pointer definition-item-card"
  56. @click="handleSelect(definition)"
  57. >
  58. <template #default>
  59. <div class="flex">
  60. <el-image :src="definition.icon" class="w-32px h-32px" />
  61. <el-text class="!ml-10px" size="large">{{ definition.name }}</el-text>
  62. </div>
  63. </template>
  64. </el-card>
  65. </el-tooltip>
  66. </div>
  67. </div>
  68. </el-scrollbar>
  69. </el-col>
  70. </el-row>
  71. <el-empty class="!py-200px" :image-size="200" description="没有找到搜索结果" v-else />
  72. </ContentWrap>
  73. </template>
  74. <!-- 第二步,填写表单,进行流程的提交 -->
  75. <ProcessDefinitionDetail
  76. v-else
  77. ref="processDefinitionDetailRef"
  78. :selectProcessDefinition="selectProcessDefinition"
  79. @cancel="selectProcessDefinition = undefined"
  80. />
  81. </template>
  82. <script lang="ts" setup>
  83. import * as DefinitionApi from '@/api/bpm/definition'
  84. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  85. import { CategoryApi } from '@/api/bpm/category'
  86. import ProcessDefinitionDetail from './ProcessDefinitionDetail.vue'
  87. import { groupBy } from 'lodash-es'
  88. defineOptions({ name: 'BpmProcessInstanceCreate' })
  89. const { proxy } = getCurrentInstance() as any
  90. const route = useRoute() // 路由
  91. const message = useMessage() // 消息
  92. const currentSearchKey = ref('') // 当前搜索关键字
  93. const processInstanceId: any = route.query.processInstanceId
  94. const loading = ref(true) // 加载中
  95. const categoryList: any = ref([]) // 分类的列表
  96. const categoryActive: any = ref({}) // 选中的分类
  97. const processDefinitionList = ref([]) // 流程定义的列表
  98. /** 查询列表 */
  99. const getList = async () => {
  100. loading.value = true
  101. try {
  102. // 所有流程分类数据
  103. await getCategoryList()
  104. // 所有流程定义数据
  105. await getDefinitionList()
  106. // 如果 processInstanceId 非空,说明是重新发起
  107. if (processInstanceId?.length > 0) {
  108. const processInstance = await ProcessInstanceApi.getProcessInstance(processInstanceId)
  109. if (!processInstance) {
  110. message.error('重新发起流程失败,原因:流程实例不存在')
  111. return
  112. }
  113. const processDefinition = processDefinitionList.value.find(
  114. (item: any) => item.key == processInstance.processDefinition?.key
  115. )
  116. if (!processDefinition) {
  117. message.error('重新发起流程失败,原因:流程定义不存在')
  118. return
  119. }
  120. await handleSelect(processDefinition, processInstance.formVariables)
  121. }
  122. } finally {
  123. loading.value = false
  124. }
  125. }
  126. // 获取所有流程分类数据
  127. const getCategoryList = async () => {
  128. try {
  129. // 流程分类
  130. categoryList.value = await CategoryApi.getCategorySimpleList()
  131. if (categoryList.value.length > 0) {
  132. categoryActive.value = categoryList.value[0]
  133. }
  134. } finally {
  135. }
  136. }
  137. // 获取所有流程定义数据
  138. const getDefinitionList = async () => {
  139. try {
  140. // 流程定义
  141. processDefinitionList.value = await DefinitionApi.getProcessDefinitionList({
  142. suspensionState: 1
  143. })
  144. // 初始化过滤列表为全部流程定义
  145. filteredProcessDefinitionList.value = processDefinitionList.value
  146. } finally {
  147. }
  148. }
  149. /** 搜索流程 */
  150. const filteredProcessDefinitionList = ref([]) // 用于存储搜索过滤后的流程定义
  151. const handleQuery = () => {
  152. if (currentSearchKey.value.trim()) {
  153. // 如果有搜索关键字,进行过滤
  154. filteredProcessDefinitionList.value = processDefinitionList.value.filter(
  155. (definition: any) =>
  156. definition.name.toLowerCase().includes(currentSearchKey.value.toLowerCase()) // 假设搜索依据是流程定义的名称
  157. )
  158. } else {
  159. // 如果没有搜索关键字,恢复所有数据
  160. filteredProcessDefinitionList.value = processDefinitionList.value
  161. }
  162. }
  163. // 流程定义的分组
  164. const processDefinitionGroup: any = computed(() => {
  165. if (!processDefinitionList.value?.length) return {}
  166. return groupBy(filteredProcessDefinitionList.value, 'category')
  167. })
  168. // ========== 表单相关 ==========
  169. const selectProcessDefinition = ref() // 选择的流程定义
  170. const processDefinitionDetailRef = ref()
  171. /** 处理选择流程的按钮操作 **/
  172. const handleSelect = async (row, formVariables?) => {
  173. // 设置选择的流程
  174. selectProcessDefinition.value = row
  175. // 初始化流程定义详情
  176. await nextTick()
  177. processDefinitionDetailRef.value?.initProcessInfo(row, formVariables)
  178. }
  179. // 左侧分类切换
  180. const handleCategoryClick = (category) => {
  181. categoryActive.value = category
  182. const categoryRef = proxy.$refs[`category-${category.code}`] // 获取点击分类对应的 DOM 元素
  183. if (categoryRef?.length) {
  184. const scrollWrapper = proxy.$refs.scrollWrapper // 获取右侧滚动容器
  185. const categoryOffsetTop = categoryRef[0].offsetTop
  186. // 滚动到对应位置
  187. scrollWrapper.scrollTo({ top: categoryOffsetTop, behavior: 'smooth' })
  188. }
  189. }
  190. // 通过分类code获取对应的名称
  191. const getCategoryName = (categoryCode) => {
  192. return categoryList.value?.find((ctg) => ctg.code === categoryCode)?.name
  193. }
  194. /** 初始化 */
  195. onMounted(() => {
  196. getList()
  197. })
  198. </script>
  199. <style lang="scss" scoped>
  200. .process-definition-container::before {
  201. content: '';
  202. border-left: 1px solid #e6e6e6;
  203. position: absolute;
  204. left: 20.8%;
  205. height: 100%;
  206. }
  207. :deep() {
  208. .definition-item-card {
  209. .el-card__body {
  210. padding: 14px;
  211. }
  212. }
  213. }
  214. </style>