Skip to content

Commit 57820cb

Browse files
committed
faet: 分类下表格数据拖拽排序功能实现;重命名分类弹窗绘制;删除分类逻辑判断与提示框
1 parent a033706 commit 57820cb

File tree

2 files changed

+111
-18
lines changed

2 files changed

+111
-18
lines changed

src/views/bpm/model/CategoryDraggableModel.vue

Lines changed: 95 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@
99
>
1010
<Icon icon="ep:arrow-down-bold" color="#999" />
1111
</div>
12-
<div class="ml-auto mr-45px">
12+
<div class="ml-auto mr-45px flex items-center">
1313
<template v-if="!isSorting">
14-
<el-button link type="info" class="mr-10px" @click.stop="handleSort">
14+
<el-button link type="info" class="mr-20px" @click.stop="handleSort">
1515
<Icon icon="fa:sort-amount-desc" class="mr-5px" />
1616
排序
1717
</el-button>
18-
<el-button link type="info" @click.stop="handleGroup">
19-
<Icon icon="ep:setting" class="mr-5px" />
20-
分组
21-
</el-button>
18+
<el-dropdown @command="(command) => handleCategoryCommand(command)" placement="bottom">
19+
<el-button link type="info" @click.stop="handleGroup">
20+
<Icon icon="ep:setting" class="mr-5px" />
21+
分类
22+
</el-button>
23+
<template #dropdown>
24+
<el-dropdown-menu>
25+
<el-dropdown-item command="handleRename"> 重命名 </el-dropdown-item>
26+
<el-dropdown-item command="handleDeleteGroup"> 删除该类 </el-dropdown-item>
27+
</el-dropdown-menu>
28+
</template>
29+
</el-dropdown>
2230
</template>
2331
<template v-else>
2432
<el-button @click.stop="cancelSort"> 取 消 </el-button>
@@ -32,13 +40,13 @@
3240
<div class="color-gray-600 text-16px"> ({{ dataList?.length || 0 }}) </div>
3341
</div>
3442
</template>
35-
3643
<el-table
3744
:class="title"
3845
ref="tableRef"
3946
:header-cell-style="{ backgroundColor: isDark ? '' : '#edeff0', paddingLeft: '10px' }"
4047
:cell-style="{ paddingLeft: '10px' }"
41-
:data="dataList"
48+
:data="tableData"
49+
row-key="id"
4250
>
4351
<el-table-column label="流程名" prop="name" min-width="150">
4452
<template #default="scope">
@@ -183,10 +191,25 @@
183191
</el-table>
184192
</el-collapse-item>
185193
</el-collapse>
194+
195+
<!-- 弹窗:重命名分类 -->
196+
<Dialog :fullscreen="false" class="rename-dialog" v-model="renameVisible" width="400">
197+
<template #title>
198+
<div class="pl-10px font-bold text-18px"> 重命名分类 </div>
199+
</template>
200+
<div class="px-30px">
201+
<el-input v-model="renameVal" />
202+
</div>
203+
<template #footer>
204+
<div class="pr-25px pb-25px">
205+
<el-button @click="renameVisible = false">取 消</el-button>
206+
<el-button type="primary" @click="handleRenameConfirm">确 定</el-button>
207+
</div>
208+
</template>
209+
</Dialog>
186210
</template>
187211

188212
<script lang="ts" setup>
189-
// 拖拽组件
190213
import Sortable from 'sortablejs'
191214
import { propTypes } from '@/utils/propTypes'
192215
import { formatDate } from '@/utils/formatTime'
@@ -201,6 +224,7 @@ import { cloneDeep } from 'lodash-es'
201224
202225
defineOptions({ name: 'BpmModel' })
203226
227+
const renameVisible = ref(false)
204228
const props = defineProps({
205229
// 分类后的数据
206230
dataList: propTypes.object.def([]),
@@ -214,6 +238,8 @@ const { t } = useI18n() // 国际化
214238
const { push } = useRouter() // 路由
215239
const userStore = useUserStoreWithOut() // 用户信息缓存
216240
const isSorting = ref(false) // 是否正处于排序状态
241+
const tableData: any = ref([])
242+
const originalData: any = ref([]) // 原始数据
217243
218244
/** '更多'操作按钮 */
219245
const handleCommand = (command: string, row: any) => {
@@ -232,6 +258,21 @@ const handleCommand = (command: string, row: any) => {
232258
}
233259
}
234260
261+
/* '分类'操作按钮 */
262+
const handleCategoryCommand = (command: string) => {
263+
switch (command) {
264+
case 'handleRename':
265+
renameVal.value = props.title
266+
renameVisible.value = true
267+
break
268+
case 'handleDeleteGroup':
269+
handleDeleteGroup()
270+
break
271+
default:
272+
break
273+
}
274+
}
275+
235276
/** 添加/修改操作 */
236277
const formRef = ref()
237278
const openForm = (type: string, id?: number) => {
@@ -340,23 +381,29 @@ const isManagerUser = (row: any) => {
340381
341382
/* 排序 */
342383
const handleSort = () => {
384+
// 保存初始数据
385+
originalData.value = cloneDeep(props.dataList)
343386
isSorting.value = true
344387
initSort()
345388
}
346389
347390
const saveSort = () => {
348391
// 接口调用
349392
console.log(tableData.value)
350-
cancelSort()
393+
// 刷新列表
394+
emit('success')
395+
isSorting.value = false
351396
}
352397
353398
const cancelSort = () => {
399+
// 恢复初始数据
400+
tableData.value = cloneDeep(originalData.value)
354401
isSorting.value = false
355402
}
356403
357-
/* 分组 */
404+
/* 分类 */
358405
const handleGroup = () => {
359-
console.log('分组')
406+
console.log('分类')
360407
}
361408
const tableRef = ref()
362409
// 创建拖拽实例
@@ -379,17 +426,48 @@ const initSort = () => {
379426
}
380427
})
381428
}
382-
const tableData: any = ref([])
383-
onMounted(() => {
429+
430+
// 更新表格数据
431+
const updateTableData = () => {
384432
tableData.value = cloneDeep(props.dataList)
433+
}
434+
435+
const renameVal = ref('')
436+
// 重命名弹窗确定
437+
const handleRenameConfirm = () => {
438+
if (!renameVal.value) {
439+
return message.warning('请输入名称')
440+
}
441+
}
442+
443+
// 删除分类
444+
const handleDeleteGroup = async () => {
445+
if (props.dataList.length > 0) {
446+
return message.warning('该分类下仍有流程定义,不允许删除')
447+
}
448+
await message.confirm('确认删除分类吗?')
449+
// 实际调用接口删除
450+
}
451+
onMounted(() => {
452+
updateTableData()
385453
})
454+
455+
defineExpose({ updateTableData })
386456
</script>
387457

458+
<style lang="scss">
459+
.rename-dialog.el-dialog {
460+
padding: 0 !important;
461+
.el-dialog__header {
462+
border-bottom: none;
463+
}
464+
.el-dialog__footer {
465+
border-top: none !important;
466+
}
467+
}
468+
</style>
388469
<style lang="scss" scoped>
389470
:deep() {
390-
.el-card {
391-
border-radius: 8px;
392-
}
393471
.el-form--inline .el-form-item {
394472
margin-right: 10px;
395473
}

src/views/bpm/model/index_new.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@
6161
v-for="(list, title) in categoryGroup"
6262
:key="title"
6363
>
64-
<CategoryDraggableModel :dataList="list" :title="title" @success="getList" />
64+
<CategoryDraggableModel
65+
ref="draggableModelRef"
66+
:dataList="list"
67+
:title="title"
68+
@success="getList"
69+
/>
6570
</ContentWrap>
6671
</div>
6772
</ContentWrap>
@@ -84,6 +89,7 @@ import CategoryDraggableModel from './CategoryDraggableModel.vue'
8489
8590
defineOptions({ name: 'BpmModel' })
8691
92+
const draggableModelRef = ref()
8793
const loading = ref(true) // 列表的加载中
8894
const queryParams = reactive({
8995
pageNo: 1,
@@ -103,6 +109,7 @@ const getList = async () => {
103109
const data = await ModelApi.getModelPage(queryParams)
104110
data.list = mockData
105111
categoryGroup.value = groupBy(data.list, 'categoryName')
112+
draggableModelRef.value?.updateTableData()
106113
} finally {
107114
loading.value = false
108115
}
@@ -131,3 +138,11 @@ onMounted(async () => {
131138
await getList()
132139
})
133140
</script>
141+
142+
<style lang="scss" scoped>
143+
:deep() {
144+
.el-card {
145+
border-radius: 8px;
146+
}
147+
}
148+
</style>

0 commit comments

Comments
 (0)