index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <ContentWrap>
  3. <div class="flex justify-between pl-20px items-center">
  4. <h3 class="font-extrabold">流程模型</h3>
  5. <!-- 搜索工作栏 -->
  6. <el-form
  7. v-if="!isCategorySorting"
  8. class="-mb-15px flex mr-10px"
  9. :model="queryParams"
  10. ref="queryFormRef"
  11. :inline="true"
  12. label-width="68px"
  13. @submit.prevent
  14. >
  15. <el-form-item prop="name" class="ml-auto">
  16. <el-input
  17. v-model="queryParams.name"
  18. placeholder="搜索流程"
  19. clearable
  20. @keyup.enter="handleQuery"
  21. class="!w-240px"
  22. >
  23. <template #prefix>
  24. <Icon icon="ep:search" class="mx-10px" />
  25. </template>
  26. </el-input>
  27. </el-form-item>
  28. <!-- 右上角:新建模型、更多操作 -->
  29. <el-form-item>
  30. <el-button type="primary" @click="openForm('create')" v-hasPermi="['bpm:model:create']">
  31. <Icon icon="ep:plus" class="mr-5px" /> 新建模型
  32. </el-button>
  33. </el-form-item>
  34. <el-form-item>
  35. <el-dropdown @command="(command) => handleCommand(command)" placement="bottom-end">
  36. <el-button class="w-30px" plain>
  37. <Icon icon="ep:setting" />
  38. </el-button>
  39. <template #dropdown>
  40. <el-dropdown-menu>
  41. <el-dropdown-item command="handleAddCategory">
  42. <Icon icon="ep:circle-plus" :size="13" class="mr-5px" />
  43. 新建分类
  44. </el-dropdown-item>
  45. <el-dropdown-item command="handleSort">
  46. <Icon icon="fa:sort-amount-desc" :size="13" class="mr-5px" />
  47. 分类排序
  48. </el-dropdown-item>
  49. </el-dropdown-menu>
  50. </template>
  51. </el-dropdown>
  52. </el-form-item>
  53. </el-form>
  54. <div class="mr-20px" v-else>
  55. <el-button @click="handleCategorySortCancel"> 取 消 </el-button>
  56. <el-button type="primary" @click="handleCategorySortSubmit"> 保存排序 </el-button>
  57. </div>
  58. </div>
  59. <el-divider />
  60. <!-- 按照分类,展示其所属的模型列表 -->
  61. <div class="px-15px">
  62. <draggable
  63. :disabled="!isCategorySorting"
  64. v-model="categoryGroup"
  65. item-key="id"
  66. :animation="400"
  67. >
  68. <template #item="{ element }">
  69. <ContentWrap
  70. class="rounded-lg transition-all duration-300 ease-in-out hover:shadow-xl"
  71. v-loading="loading"
  72. :body-style="{ padding: 0 }"
  73. :key="element.id"
  74. >
  75. <CategoryDraggableModel
  76. :isCategorySorting="isCategorySorting"
  77. :categoryInfo="element"
  78. @success="getList"
  79. />
  80. </ContentWrap>
  81. </template>
  82. </draggable>
  83. </div>
  84. </ContentWrap>
  85. <!-- 表单弹窗:添加/修改流程 -->
  86. <ModelForm ref="formRef" @success="getList" />
  87. <!-- 表单弹窗:添加分类 -->
  88. <CategoryForm ref="categoryFormRef" @success="getList" />
  89. <!-- 弹窗:表单详情 -->
  90. <Dialog title="表单详情" v-model="formDetailVisible" width="800">
  91. <form-create :rule="formDetailPreview.rule" :option="formDetailPreview.option" />
  92. </Dialog>
  93. </template>
  94. <script lang="ts" setup>
  95. import draggable from 'vuedraggable'
  96. import { CategoryApi } from '@/api/bpm/category'
  97. import * as ModelApi from '@/api/bpm/model'
  98. import ModelForm from './ModelForm.vue'
  99. import CategoryForm from '../category/CategoryForm.vue'
  100. import { groupBy, cloneDeep } from 'lodash-es'
  101. import CategoryDraggableModel from './CategoryDraggableModel.vue'
  102. defineOptions({ name: 'BpmModel' })
  103. const message = useMessage() // 消息弹窗
  104. const loading = ref(true) // 列表的加载中
  105. const isCategorySorting = ref(false) // 是否 category 正处于排序状态
  106. const queryParams = reactive({
  107. name: undefined
  108. })
  109. const queryFormRef = ref() // 搜索的表单
  110. const categoryGroup: any = ref([]) // 按照 category 分组的数据
  111. const originalData: any = ref([]) // 原始数据
  112. /** 查询所有分类 */
  113. const getAllCategory = async () => {
  114. const list = await CategoryApi.getCategorySimpleList()
  115. categoryGroup.value = list.map((item: any) => ({ ...item, modelList: [] }))
  116. }
  117. /** 查询所有流程模型接口 */
  118. const getAllModel = async () => {
  119. // 查询所有流程模型
  120. const list = await ModelApi.getModelList(queryParams.name)
  121. // 按照 categoryName 分组
  122. const groupedData = groupBy(list, 'categoryName')
  123. Object.keys(groupedData).forEach((key) => {
  124. const category = categoryGroup.value.find((item: any) => item.name === key)
  125. if (category) {
  126. category.modelList = groupedData[key]
  127. }
  128. })
  129. }
  130. /** 搜索按钮操作 */
  131. const handleQuery = () => {
  132. getList()
  133. }
  134. /** 添加/修改操作 */
  135. const formRef = ref()
  136. const openForm = (type: string, id?: number) => {
  137. formRef.value.open(type, id)
  138. }
  139. /** 流程表单的详情按钮操作 */
  140. const formDetailVisible = ref(false)
  141. const formDetailPreview = ref({
  142. rule: [],
  143. option: {}
  144. })
  145. /** 右上角设置按钮 */
  146. const handleCommand = (command: string) => {
  147. switch (command) {
  148. case 'handleAddCategory':
  149. handleAddCategory()
  150. break
  151. case 'handleSort':
  152. handleCategorySort()
  153. break
  154. default:
  155. break
  156. }
  157. }
  158. /** 新建分类 */
  159. const categoryFormRef = ref()
  160. const handleAddCategory = () => {
  161. categoryFormRef.value.open('create')
  162. }
  163. /** 分类排序的提交 */
  164. const handleCategorySort = () => {
  165. // 保存初始数据
  166. originalData.value = cloneDeep(categoryGroup.value)
  167. isCategorySorting.value = true
  168. }
  169. /** 分类排序的取消 */
  170. const handleCategorySortCancel = () => {
  171. // 恢复初始数据
  172. categoryGroup.value = cloneDeep(originalData.value)
  173. isCategorySorting.value = false
  174. }
  175. /** 分类排序的保存 */
  176. const handleCategorySortSubmit = async () => {
  177. // 保存排序
  178. const ids = categoryGroup.value.map((item: any) => item.id)
  179. await CategoryApi.updateCategorySortBatch(ids)
  180. // 刷新列表
  181. isCategorySorting.value = false
  182. message.success('排序分类成功')
  183. await getList()
  184. }
  185. /** 加载数据 */
  186. const getList = async () => {
  187. loading.value = true
  188. try {
  189. await getAllCategory()
  190. await getAllModel()
  191. } finally {
  192. loading.value = false
  193. }
  194. }
  195. /** 初始化 **/
  196. onMounted(() => {
  197. getList()
  198. })
  199. </script>
  200. <style lang="scss" scoped>
  201. :deep() {
  202. .el-table--fit .el-table__inner-wrapper:before {
  203. height: 0;
  204. }
  205. .el-card {
  206. border-radius: 8px;
  207. }
  208. .el-form--inline .el-form-item {
  209. margin-right: 10px;
  210. }
  211. .el-divider--horizontal {
  212. margin-top: 6px;
  213. }
  214. }
  215. </style>