index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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('/bpm/manager/model/create-update')
  122. } else {
  123. push(`/bpm/manager/model/create-update?id=${id}`)
  124. }
  125. }
  126. /** 流程表单的详情按钮操作 */
  127. const formDetailVisible = ref(false)
  128. const formDetailPreview = ref({
  129. rule: [],
  130. option: {}
  131. })
  132. /** 右上角设置按钮 */
  133. const handleCommand = (command: string) => {
  134. switch (command) {
  135. case 'handleCategoryAdd':
  136. handleCategoryAdd()
  137. break
  138. case 'handleCategorySort':
  139. handleCategorySort()
  140. break
  141. default:
  142. break
  143. }
  144. }
  145. /** 新建分类 */
  146. const categoryFormRef = ref()
  147. const handleCategoryAdd = () => {
  148. categoryFormRef.value.open('create')
  149. }
  150. /** 分类排序的提交 */
  151. const handleCategorySort = () => {
  152. // 保存初始数据
  153. originalData.value = cloneDeep(categoryGroup.value)
  154. isCategorySorting.value = true
  155. }
  156. /** 分类排序的取消 */
  157. const handleCategorySortCancel = () => {
  158. // 恢复初始数据
  159. categoryGroup.value = cloneDeep(originalData.value)
  160. isCategorySorting.value = false
  161. }
  162. /** 分类排序的保存 */
  163. const handleCategorySortSubmit = async () => {
  164. // 保存排序
  165. const ids = categoryGroup.value.map((item: any) => item.id)
  166. await CategoryApi.updateCategorySortBatch(ids)
  167. // 刷新列表
  168. isCategorySorting.value = false
  169. message.success('排序分类成功')
  170. await getList()
  171. }
  172. /** 加载数据 */
  173. const getList = async () => {
  174. loading.value = true
  175. try {
  176. // 查询模型 + 分裂的列表
  177. const modelList = await ModelApi.getModelList(queryParams.name)
  178. const categoryList = await CategoryApi.getCategorySimpleList()
  179. // 按照 category 聚合
  180. // 注意:必须一次性赋值给 categoryGroup,否则每次操作后,列表会重新渲染,滚动条的位置会偏离!!!
  181. categoryGroup.value = categoryList.map((category: any) => ({
  182. ...category,
  183. modelList: modelList.filter((model: any) => model.categoryName == category.name)
  184. }))
  185. } finally {
  186. loading.value = false
  187. }
  188. }
  189. /** 初始化 **/
  190. onMounted(() => {
  191. getList()
  192. })
  193. </script>
  194. <style lang="scss" scoped>
  195. :deep() {
  196. .el-table--fit .el-table__inner-wrapper:before {
  197. height: 0;
  198. }
  199. .el-card {
  200. border-radius: 8px;
  201. }
  202. .el-form--inline .el-form-item {
  203. margin-right: 10px;
  204. }
  205. .el-divider--horizontal {
  206. margin-top: 6px;
  207. }
  208. }
  209. </style>