index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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="handleCategoryAdd">
  42. <Icon icon="ep:circle-plus" :size="13" class="mr-5px" />
  43. 新建分类
  44. </el-dropdown-item>
  45. <el-dropdown-item command="handleCategorySort">
  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. <CategoryForm ref="categoryFormRef" @success="getList" />
  87. <!-- 弹窗:表单详情 -->
  88. <Dialog title="表单详情" v-model="formDetailVisible" width="800">
  89. <form-create :rule="formDetailPreview.rule" :option="formDetailPreview.option" />
  90. </Dialog>
  91. </template>
  92. <script lang="ts" setup>
  93. import draggable from 'vuedraggable'
  94. import { CategoryApi } from '@/api/bpm/category'
  95. import * as ModelApi from '@/api/bpm/model'
  96. import CategoryForm from '../category/CategoryForm.vue'
  97. import { cloneDeep } from 'lodash-es'
  98. import CategoryDraggableModel from './CategoryDraggableModel.vue'
  99. defineOptions({ name: 'BpmModel' })
  100. const { push } = useRouter()
  101. const message = useMessage() // 消息弹窗
  102. const loading = ref(true) // 列表的加载中
  103. const isCategorySorting = ref(false) // 是否 category 正处于排序状态
  104. const queryParams = reactive({
  105. name: undefined
  106. })
  107. const queryFormRef = ref() // 搜索的表单
  108. const categoryGroup: any = ref([]) // 按照 category 分组的数据
  109. const originalData: any = ref([]) // 原始数据
  110. /** 搜索按钮操作 */
  111. const handleQuery = () => {
  112. getList()
  113. }
  114. /** 添加/修改操作 */
  115. const openForm = (type: string, id?: number) => {
  116. if (type === 'create') {
  117. push({ name: 'BpmModelCreate' })
  118. } else {
  119. push({
  120. name: 'BpmModelUpdate',
  121. params: { id }
  122. })
  123. }
  124. }
  125. /** 流程表单的详情按钮操作 */
  126. const formDetailVisible = ref(false)
  127. const formDetailPreview = ref({
  128. rule: [],
  129. option: {}
  130. })
  131. /** 右上角设置按钮 */
  132. const handleCommand = (command: string) => {
  133. switch (command) {
  134. case 'handleCategoryAdd':
  135. handleCategoryAdd()
  136. break
  137. case 'handleCategorySort':
  138. handleCategorySort()
  139. break
  140. default:
  141. break
  142. }
  143. }
  144. /** 新建分类 */
  145. const categoryFormRef = ref()
  146. const handleCategoryAdd = () => {
  147. categoryFormRef.value.open('create')
  148. }
  149. /** 分类排序的提交 */
  150. const handleCategorySort = () => {
  151. // 保存初始数据
  152. originalData.value = cloneDeep(categoryGroup.value)
  153. isCategorySorting.value = true
  154. }
  155. /** 分类排序的取消 */
  156. const handleCategorySortCancel = () => {
  157. // 恢复初始数据
  158. categoryGroup.value = cloneDeep(originalData.value)
  159. isCategorySorting.value = false
  160. }
  161. /** 分类排序的保存 */
  162. const handleCategorySortSubmit = async () => {
  163. // 保存排序
  164. const ids = categoryGroup.value.map((item: any) => item.id)
  165. await CategoryApi.updateCategorySortBatch(ids)
  166. // 刷新列表
  167. isCategorySorting.value = false
  168. message.success('排序分类成功')
  169. await getList()
  170. }
  171. /** 加载数据 */
  172. const getList = async () => {
  173. loading.value = true
  174. try {
  175. // 查询模型 + 分裂的列表
  176. const modelList = await ModelApi.getModelList(queryParams.name)
  177. const categoryList = await CategoryApi.getCategorySimpleList()
  178. // 按照 category 聚合
  179. // 注意:必须一次性赋值给 categoryGroup,否则每次操作后,列表会重新渲染,滚动条的位置会偏离!!!
  180. categoryGroup.value = categoryList.map((category: any) => ({
  181. ...category,
  182. modelList: modelList.filter((model: any) => model.categoryName == category.name)
  183. }))
  184. } finally {
  185. loading.value = false
  186. }
  187. }
  188. /** 初始化 **/
  189. onActivated(() => {
  190. getList()
  191. })
  192. </script>
  193. <style lang="scss" scoped>
  194. :deep() {
  195. .el-table--fit .el-table__inner-wrapper:before {
  196. height: 0;
  197. }
  198. .el-card {
  199. border-radius: 8px;
  200. }
  201. .el-form--inline .el-form-item {
  202. margin-right: 10px;
  203. }
  204. .el-divider--horizontal {
  205. margin-top: 6px;
  206. }
  207. }
  208. </style>