Commit ce60f630 by YunaiV

【功能优化】菜单管理:使用 el-table-v2 解决菜单过多后,存在卡顿的问题

parent ea133da1
...@@ -5,18 +5,10 @@ const { t } = useI18n() // 国际化 ...@@ -5,18 +5,10 @@ const { t } = useI18n() // 国际化
export function hasPermi(app: App<Element>) { export function hasPermi(app: App<Element>) {
app.directive('hasPermi', (el, binding) => { app.directive('hasPermi', (el, binding) => {
const { wsCache } = useCache()
const { value } = binding const { value } = binding
const all_permission = '*:*:*'
const userInfo = wsCache.get(CACHE_KEY.USER)
const permissions = userInfo?.permissions || []
if (value && value instanceof Array && value.length > 0) { if (value && value instanceof Array && value.length > 0) {
const permissionFlag = value const hasPermissions = hasPermission(value)
const hasPermissions = permissions.some((permission: string) => {
return all_permission === permission || permissionFlag.includes(permission)
})
if (!hasPermissions) { if (!hasPermissions) {
el.parentNode && el.parentNode.removeChild(el) el.parentNode && el.parentNode.removeChild(el)
...@@ -26,3 +18,14 @@ export function hasPermi(app: App<Element>) { ...@@ -26,3 +18,14 @@ export function hasPermi(app: App<Element>) {
} }
}) })
} }
export const hasPermission = (permission: string[]) => {
const { wsCache } = useCache()
const all_permission = '*:*:*'
const userInfo = wsCache.get(CACHE_KEY.USER)
const permissions = userInfo?.permissions || []
return permissions.some((p: string) => {
return all_permission === p || permission.includes(p)
})
}
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
<template #default="{ height, width }"> <template #default="{ height, width }">
<!-- Virtualized Table 虚拟化表格:高性能,解决表格在大数据量下的卡顿问题 --> <!-- Virtualized Table 虚拟化表格:高性能,解决表格在大数据量下的卡顿问题 -->
<el-table-v2 <el-table-v2
v-loading="loading"
:columns="columns" :columns="columns"
:data="list" :data="list"
:width="width" :width="width"
...@@ -31,7 +32,7 @@ ...@@ -31,7 +32,7 @@
<AreaForm ref="formRef" /> <AreaForm ref="formRef" />
</template> </template>
<script setup lang="tsx"> <script setup lang="tsx">
import type { Column } from 'element-plus' import { Column } from 'element-plus'
import AreaForm from './AreaForm.vue' import AreaForm from './AreaForm.vue'
import * as AreaApi from '@/api/system/area' import * as AreaApi from '@/api/system/area'
...@@ -40,7 +41,7 @@ defineOptions({ name: 'SystemArea' }) ...@@ -40,7 +41,7 @@ defineOptions({ name: 'SystemArea' })
// 表格的 column 字段 // 表格的 column 字段
const columns: Column[] = [ const columns: Column[] = [
{ {
dataKey: 'id', // 需要渲染当前列的数据字段。例如说:{id:9527, name:'Mike'},则填 id dataKey: 'id', // 需要渲染当前列的数据字段
title: '编号', // 显示在单元格表头的文本 title: '编号', // 显示在单元格表头的文本
width: 400, // 当前列的宽度,必须设置 width: 400, // 当前列的宽度,必须设置
fixed: true, // 是否固定列 fixed: true, // 是否固定列
...@@ -52,14 +53,17 @@ const columns: Column[] = [ ...@@ -52,14 +53,17 @@ const columns: Column[] = [
width: 200 width: 200
} }
] ]
// 表格的数据 const loading = ref(true) // 列表的加载中
const list = ref([]) const list = ref([]) // 表格的数据
/** /** 获得数据列表 */
* 获得数据列表
*/
const getList = async () => { const getList = async () => {
loading.value = true
try {
list.value = await AreaApi.getAreaTree() list.value = await AreaApi.getAreaTree()
} finally {
loading.value = false
}
} }
/** 添加/修改操作 */ /** 添加/修改操作 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment