Skip to content

Commit ce60f63

Browse files
committed
【功能优化】菜单管理:使用 el-table-v2 解决菜单过多后,存在卡顿的问题
1 parent ea133da commit ce60f63

File tree

3 files changed

+141
-245
lines changed

3 files changed

+141
-245
lines changed

src/directives/permission/hasPermi.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@ const { t } = useI18n() // 国际化
55

66
export function hasPermi(app: App<Element>) {
77
app.directive('hasPermi', (el, binding) => {
8-
const { wsCache } = useCache()
98
const { value } = binding
10-
const all_permission = '*:*:*'
11-
const userInfo = wsCache.get(CACHE_KEY.USER)
12-
const permissions = userInfo?.permissions || []
139

1410
if (value && value instanceof Array && value.length > 0) {
15-
const permissionFlag = value
16-
17-
const hasPermissions = permissions.some((permission: string) => {
18-
return all_permission === permission || permissionFlag.includes(permission)
19-
})
11+
const hasPermissions = hasPermission(value)
2012

2113
if (!hasPermissions) {
2214
el.parentNode && el.parentNode.removeChild(el)
@@ -26,3 +18,14 @@ export function hasPermi(app: App<Element>) {
2618
}
2719
})
2820
}
21+
22+
export const hasPermission = (permission: string[]) => {
23+
const { wsCache } = useCache()
24+
const all_permission = '*:*:*'
25+
const userInfo = wsCache.get(CACHE_KEY.USER)
26+
const permissions = userInfo?.permissions || []
27+
28+
return permissions.some((p: string) => {
29+
return all_permission === p || permission.includes(p)
30+
})
31+
}

src/views/system/area/index.vue

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<template #default="{ height, width }">
1717
<!-- Virtualized Table 虚拟化表格:高性能,解决表格在大数据量下的卡顿问题 -->
1818
<el-table-v2
19+
v-loading="loading"
1920
:columns="columns"
2021
:data="list"
2122
:width="width"
@@ -31,7 +32,7 @@
3132
<AreaForm ref="formRef" />
3233
</template>
3334
<script setup lang="tsx">
34-
import type { Column } from 'element-plus'
35+
import { Column } from 'element-plus'
3536
import AreaForm from './AreaForm.vue'
3637
import * as AreaApi from '@/api/system/area'
3738
@@ -40,7 +41,7 @@ defineOptions({ name: 'SystemArea' })
4041
// 表格的 column 字段
4142
const columns: Column[] = [
4243
{
43-
dataKey: 'id', // 需要渲染当前列的数据字段。例如说:{id:9527, name:'Mike'},则填 id
44+
dataKey: 'id', // 需要渲染当前列的数据字段
4445
title: '编号', // 显示在单元格表头的文本
4546
width: 400, // 当前列的宽度,必须设置
4647
fixed: true, // 是否固定列
@@ -52,14 +53,17 @@ const columns: Column[] = [
5253
width: 200
5354
}
5455
]
55-
// 表格的数据
56-
const list = ref([])
56+
const loading = ref(true) // 列表的加载中
57+
const list = ref([]) // 表格的数据
5758
58-
/**
59-
* 获得数据列表
60-
*/
59+
/** 获得数据列表 */
6160
const getList = async () => {
62-
list.value = await AreaApi.getAreaTree()
61+
loading.value = true
62+
try {
63+
list.value = await AreaApi.getAreaTree()
64+
} finally {
65+
loading.value = false
66+
}
6367
}
6468
6569
/** 添加/修改操作 */

0 commit comments

Comments
 (0)