Skip to content

Commit 6c504ad

Browse files
committed
Merge branch 'feature/bpm' of https://github.com/GoldenZqqq/yudao-ui-admin-vue3 into feature/bpm
# Conflicts: # src/views/bpm/model/CategoryDraggableModel.vue
2 parents 8e8475f + 4319d86 commit 6c504ad

File tree

1 file changed

+101
-40
lines changed

1 file changed

+101
-40
lines changed

src/views/bpm/model/CategoryDraggableModel.vue

Lines changed: 101 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="flex items-center h-50px">
2+
<div class="flex items-center h-50px" v-memo="[categoryInfo.name, isCategorySorting]">
33
<!-- 头部:分类名 -->
44
<div class="flex items-center">
55
<el-tooltip content="拖动排序" v-if="isCategorySorting">
@@ -13,7 +13,7 @@
1313
<div class="color-gray-600 text-16px"> ({{ categoryInfo.modelList?.length || 0 }}) </div>
1414
</div>
1515
<!-- 头部:操作 -->
16-
<div class="flex-1 flex" v-if="!isCategorySorting">
16+
<div class="flex-1 flex" v-show="!isCategorySorting">
1717
<div
1818
v-if="categoryInfo.modelList.length > 0"
1919
class="ml-20px flex items-center"
@@ -69,44 +69,45 @@
6969
<el-collapse-transition>
7070
<div v-show="isExpand">
7171
<el-table
72+
v-if="modelList && modelList.length > 0"
7273
:class="categoryInfo.name"
7374
ref="tableRef"
74-
:header-cell-style="{ backgroundColor: isDark ? '' : '#edeff0', paddingLeft: '10px' }"
75-
:cell-style="{ paddingLeft: '10px' }"
76-
:row-style="{ height: '68px' }"
7775
:data="modelList"
7876
row-key="id"
77+
:header-cell-style="tableHeaderStyle"
78+
:cell-style="tableCellStyle"
79+
:row-style="{ height: '68px' }"
7980
>
8081
<el-table-column label="流程名" prop="name" min-width="150">
81-
<template #default="scope">
82+
<template #default="{ row }">
8283
<div class="flex items-center">
8384
<el-tooltip content="拖动排序" v-if="isModelSorting">
8485
<Icon
8586
icon="ic:round-drag-indicator"
8687
class="drag-icon cursor-move text-#8a909c mr-10px"
8788
/>
8889
</el-tooltip>
89-
<el-image :src="scope.row.icon" class="h-38px w-38px mr-10px rounded" />
90-
{{ scope.row.name }}
90+
<el-image v-if="row.icon" :src="row.icon" class="h-38px w-38px mr-10px rounded" />
91+
{{ row.name }}
9192
</div>
9293
</template>
9394
</el-table-column>
9495
<el-table-column label="可见范围" prop="startUserIds" min-width="150">
95-
<template #default="scope">
96-
<el-text v-if="!scope.row.startUsers || scope.row.startUsers.length === 0">
96+
<template #default="{ row }">
97+
<el-text v-if="!row.startUsers?.length">
9798
全部可见
9899
</el-text>
99-
<el-text v-else-if="scope.row.startUsers.length == 1">
100-
{{ scope.row.startUsers[0].nickname }}
100+
<el-text v-else-if="row.startUsers.length === 1">
101+
{{ row.startUsers[0].nickname }}
101102
</el-text>
102103
<el-text v-else>
103104
<el-tooltip
104105
class="box-item"
105106
effect="dark"
106107
placement="top"
107-
:content="scope.row.startUsers.map((user: any) => user.nickname).join('、')"
108+
:content="row.startUsers.map((user: any) => user.nickname).join('、')"
108109
>
109-
{{ scope.row.startUsers[0].nickname }}等 {{ scope.row.startUsers.length }} 人可见
110+
{{ row.startUsers[0].nickname }}等 {{ row.startUsers.length }} 人可见
110111
</el-tooltip>
111112
</el-text>
112113
</template>
@@ -245,7 +246,6 @@
245246
<script lang="ts" setup>
246247
import { CategoryApi, CategoryVO } from '@/api/bpm/category'
247248
import Sortable from 'sortablejs'
248-
import { propTypes } from '@/utils/propTypes'
249249
import { formatDate } from '@/utils/formatTime'
250250
import * as ModelApi from '@/api/bpm/model'
251251
import * as FormApi from '@/api/bpm/form'
@@ -254,15 +254,49 @@ import { BpmModelFormType } from '@/utils/constants'
254254
import { checkPermi } from '@/utils/permission'
255255
import { useUserStoreWithOut } from '@/store/modules/user'
256256
import { useAppStore } from '@/store/modules/app'
257-
import { cloneDeep } from 'lodash-es'
257+
import { cloneDeep, isEqual } from 'lodash-es'
258258
import { useTagsView } from '@/hooks/web/useTagsView'
259+
import { useDebounceFn } from '@vueuse/core'
259260
260261
defineOptions({ name: 'BpmModel' })
261262
262-
const props = defineProps({
263-
categoryInfo: propTypes.object.def([]), // 分类后的数据
264-
isCategorySorting: propTypes.bool.def(false) // 是否分类在排序
265-
})
263+
// 优化 Props 类型定义
264+
interface UserInfo {
265+
nickname: string
266+
[key: string]: any
267+
}
268+
269+
interface ProcessDefinition {
270+
deploymentTime: string
271+
version: number
272+
suspensionState: number
273+
}
274+
275+
interface ModelInfo {
276+
id: number
277+
name: string
278+
icon?: string
279+
startUsers?: UserInfo[]
280+
processDefinition?: ProcessDefinition
281+
formType?: number
282+
formId?: number
283+
formName?: string
284+
formCustomCreatePath?: string
285+
managerUserIds?: number[]
286+
[key: string]: any
287+
}
288+
289+
interface CategoryInfoProps {
290+
id: number
291+
name: string
292+
modelList: ModelInfo[]
293+
}
294+
295+
const props = defineProps<{
296+
categoryInfo: CategoryInfoProps
297+
isCategorySorting: boolean
298+
}>()
299+
266300
const emit = defineEmits(['success'])
267301
const message = useMessage() // 消息弹窗
268302
const { t } = useI18n() // 国际化
@@ -271,10 +305,26 @@ const userStore = useUserStoreWithOut() // 用户信息缓存
271305
const isDark = computed(() => useAppStore().getIsDark) // 是否黑暗模式
272306
273307
const isModelSorting = ref(false) // 是否正处于排序状态
274-
const originalData: any = ref([]) // 原始数据
275-
const modelList: any = ref([]) // 模型列表
308+
const originalData = ref<ModelInfo[]>([]) // 原始数据
309+
const modelList = ref<ModelInfo[]>([]) // 模型列表
276310
const isExpand = ref(false) // 是否处于展开状态
277311
312+
// 使用 computed 优化表格样式计算
313+
const tableHeaderStyle = computed(() => ({
314+
backgroundColor: isDark.value ? '' : '#edeff0',
315+
paddingLeft: '10px'
316+
}))
317+
318+
const tableCellStyle = computed(() => ({
319+
paddingLeft: '10px'
320+
}))
321+
322+
// 使用 computed 优化可见性判断
323+
const isManagerUser = computed(() => {
324+
const userId = userStore.getUser?.id
325+
return (row: ModelInfo) => row.managerUserIds?.includes(userId)
326+
})
327+
278328
/** 权限校验:通过 computed 解决列表的卡顿问题 */
279329
const hasPermiUpdate = computed(() => {
280330
return checkPermi(['bpm:model:update'])
@@ -449,14 +499,15 @@ const handleModelSortCancel = () => {
449499
450500
/** 创建拖拽实例 */
451501
const tableRef = ref()
452-
const initSort = () => {
502+
const initSort = useDebounceFn(() => {
453503
const table = document.querySelector(`.${props.categoryInfo.name} .el-table__body-wrapper tbody`)
504+
if (!table) return
505+
454506
Sortable.create(table, {
455507
group: 'shared',
456508
animation: 150,
457509
draggable: '.el-table__row',
458510
handle: '.drag-icon',
459-
// 结束拖动事件
460511
onEnd: ({ newDraggableIndex, oldDraggableIndex }) => {
461512
if (oldDraggableIndex !== newDraggableIndex) {
462513
modelList.value.splice(
@@ -467,15 +518,18 @@ const initSort = () => {
467518
}
468519
}
469520
})
470-
}
521+
}, 200)
471522
472523
/** 更新 modelList 模型列表 */
473-
const updateModeList = () => {
474-
modelList.value = cloneDeep(props.categoryInfo.modelList)
475-
if (props.categoryInfo.modelList.length > 0) {
476-
isExpand.value = true
524+
const updateModeList = useDebounceFn(() => {
525+
const newModelList = props.categoryInfo.modelList
526+
if (!isEqual(modelList.value, newModelList)) {
527+
modelList.value = cloneDeep(newModelList)
528+
if (newModelList?.length > 0) {
529+
isExpand.value = true
530+
}
477531
}
478-
}
532+
}, 100)
479533
480534
/** 重命名弹窗确定 */
481535
const renameCategoryVisible = ref(false)
@@ -526,14 +580,15 @@ const openModelForm = async (type: string, id?: number) => {
526580
}
527581
}
528582
529-
watch(() => props.categoryInfo.modelList, updateModeList, { immediate: true })
530-
watch(
531-
() => props.isCategorySorting,
532-
(val) => {
533-
if (val) isExpand.value = false
534-
},
535-
{ immediate: true }
536-
)
583+
watchEffect(() => {
584+
if (props.categoryInfo?.modelList) {
585+
updateModeList()
586+
}
587+
588+
if (props.isCategorySorting) {
589+
isExpand.value = false
590+
}
591+
})
537592
</script>
538593

539594
<style lang="scss">
@@ -550,10 +605,16 @@ watch(
550605
}
551606
</style>
552607
<style lang="scss" scoped>
553-
:deep() {
554-
.el-table__cell {
608+
.category-draggable-model {
609+
:deep(.el-table__cell) {
555610
overflow: hidden;
556611
border-bottom: none !important;
557612
}
613+
614+
// 优化表格渲染性能
615+
:deep(.el-table__body) {
616+
will-change: transform;
617+
transform: translateZ(0);
618+
}
558619
}
559620
</style>

0 commit comments

Comments
 (0)