index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <!-- 第一步,通过流程定义的列表,选择对应的流程 -->
  3. <template v-if="!selectProcessDefinition">
  4. <el-input
  5. v-model="searchName"
  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 as any) }}
  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. :disabled="!definition.description || definition.description.trim().length === 0"
  52. placement="top"
  53. >
  54. <el-card
  55. shadow="hover"
  56. class="cursor-pointer definition-item-card"
  57. @click="handleSelect(definition)"
  58. >
  59. <template #default>
  60. <div class="flex">
  61. <el-image :src="definition.icon" class="w-32px h-32px" />
  62. <el-text class="!ml-10px" size="large">{{ definition.name }}</el-text>
  63. </div>
  64. </template>
  65. </el-card>
  66. </el-tooltip>
  67. </div>
  68. </div>
  69. </el-scrollbar>
  70. </el-col>
  71. </el-row>
  72. <el-empty class="!py-200px" :image-size="200" description="没有找到搜索结果" v-else />
  73. </ContentWrap>
  74. </template>
  75. <!-- 第二步,填写表单,进行流程的提交 -->
  76. <ProcessDefinitionDetail
  77. v-else
  78. ref="processDefinitionDetailRef"
  79. :selectProcessDefinition="selectProcessDefinition"
  80. @cancel="selectProcessDefinition = undefined"
  81. />
  82. </template>
  83. <script lang="ts" setup>
  84. import * as DefinitionApi from '@/api/bpm/definition'
  85. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  86. import { CategoryApi } from '@/api/bpm/category'
  87. import ProcessDefinitionDetail from './ProcessDefinitionDetail.vue'
  88. import { groupBy } from 'lodash-es'
  89. defineOptions({ name: 'BpmProcessInstanceCreate' })
  90. const { proxy } = getCurrentInstance() as any
  91. const route = useRoute() // 路由
  92. const message = useMessage() // 消息
  93. const searchName = ref('') // 当前搜索关键字
  94. const processInstanceId: any = route.query.processInstanceId // 流程实例编号。场景:重新发起时
  95. const loading = ref(true) // 加载中
  96. const categoryList: any = ref([]) // 分类的列表
  97. const categoryActive: any = ref({}) // 选中的分类
  98. const processDefinitionList = ref([]) // 流程定义的列表
  99. /** 查询列表 */
  100. const getList = async () => {
  101. loading.value = true
  102. try {
  103. // 所有流程分类数据
  104. await getCategoryList()
  105. // 所有流程定义数据
  106. await getProcessDefinitionList()
  107. // 如果 processInstanceId 非空,说明是重新发起
  108. if (processInstanceId?.length > 0) {
  109. const processInstance = await ProcessInstanceApi.getProcessInstance(processInstanceId)
  110. if (!processInstance) {
  111. message.error('重新发起流程失败,原因:流程实例不存在')
  112. return
  113. }
  114. const processDefinition = processDefinitionList.value.find(
  115. (item: any) => item.key == processInstance.processDefinition?.key
  116. )
  117. if (!processDefinition) {
  118. message.error('重新发起流程失败,原因:流程定义不存在')
  119. return
  120. }
  121. await handleSelect(processDefinition, processInstance.formVariables)
  122. }
  123. } finally {
  124. loading.value = false
  125. }
  126. }
  127. /** 获取所有流程分类数据 */
  128. const getCategoryList = async () => {
  129. try {
  130. // 流程分类
  131. categoryList.value = await CategoryApi.getCategorySimpleList()
  132. // 选中首个分类
  133. if (categoryList.value.length > 0) {
  134. categoryActive.value = categoryList.value[0]
  135. }
  136. } finally {
  137. }
  138. }
  139. /** 获取所有流程定义数据 */
  140. const getProcessDefinitionList = async () => {
  141. try {
  142. // 流程定义
  143. processDefinitionList.value = await DefinitionApi.getProcessDefinitionList({
  144. suspensionState: 1
  145. })
  146. // 初始化过滤列表为全部流程定义
  147. filteredProcessDefinitionList.value = processDefinitionList.value
  148. } finally {
  149. }
  150. }
  151. /** 搜索流程 */
  152. const filteredProcessDefinitionList = ref([]) // 用于存储搜索过滤后的流程定义
  153. const handleQuery = () => {
  154. if (searchName.value.trim()) {
  155. // 如果有搜索关键字,进行过滤
  156. filteredProcessDefinitionList.value = processDefinitionList.value.filter(
  157. (definition: any) => definition.name.toLowerCase().includes(searchName.value.toLowerCase()) // 假设搜索依据是流程定义的名称
  158. )
  159. } else {
  160. // 如果没有搜索关键字,恢复所有数据
  161. filteredProcessDefinitionList.value = processDefinitionList.value
  162. }
  163. }
  164. /** 流程定义的分组 */
  165. const processDefinitionGroup: any = computed(() => {
  166. if (!processDefinitionList.value?.length) {
  167. return {}
  168. }
  169. const grouped = groupBy(filteredProcessDefinitionList.value, 'category')
  170. // 按照 categoryList 的顺序重新组织数据
  171. const orderedGroup = {}
  172. categoryList.value.forEach((category: any) => {
  173. if (grouped[category.code]) {
  174. orderedGroup[category.code] = grouped[category.code]
  175. }
  176. })
  177. return orderedGroup
  178. })
  179. /** 左侧分类切换 */
  180. const handleCategoryClick = (category: any) => {
  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: string) => {
  192. return categoryList.value?.find((ctg: any) => ctg.code === categoryCode)?.name
  193. }
  194. // ========== 表单相关 ==========
  195. const selectProcessDefinition = ref() // 选择的流程定义
  196. const processDefinitionDetailRef = ref()
  197. /** 处理选择流程的按钮操作 **/
  198. const handleSelect = async (row, formVariables?) => {
  199. // 设置选择的流程
  200. selectProcessDefinition.value = row
  201. // 初始化流程定义详情
  202. await nextTick()
  203. processDefinitionDetailRef.value?.initProcessInfo(row, formVariables)
  204. }
  205. /** 初始化 */
  206. onMounted(() => {
  207. getList()
  208. })
  209. </script>
  210. <style lang="scss" scoped>
  211. .process-definition-container::before {
  212. content: '';
  213. border-left: 1px solid #e6e6e6;
  214. position: absolute;
  215. left: 20.8%;
  216. height: 100%;
  217. }
  218. :deep() {
  219. .definition-item-card {
  220. .el-card__body {
  221. padding: 14px;
  222. }
  223. }
  224. }
  225. </style>