index.vue 6.5 KB

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