【代码评审】Bpm:模型列表的优化

pull/682/head
YunaiV 2025-01-23 19:40:49 +08:00
parent bf437421bb
commit 58455cd0a4
3 changed files with 17 additions and 18 deletions

View File

@ -1,8 +1,9 @@
import type { App } from 'vue' import type { App } from 'vue'
import {useUserStore} from "@/store/modules/user"; import { useUserStore } from '@/store/modules/user'
const { t } = useI18n() // 国际化 const { t } = useI18n() // 国际化
/** 判断权限的指令 directive */
export function hasPermi(app: App<Element>) { export function hasPermi(app: App<Element>) {
app.directive('hasPermi', (el, binding) => { app.directive('hasPermi', (el, binding) => {
const { value } = binding const { value } = binding
@ -18,9 +19,13 @@ export function hasPermi(app: App<Element>) {
} }
}) })
} }
const userStore = useUserStore();
/** 判断权限的方法 function */
const userStore = useUserStore()
const all_permission = '*:*:*' const all_permission = '*:*:*'
export const hasPermission = (permission: string[]) => { export const hasPermission = (permission: string[]) => {
return userStore.permissionsSet.has(all_permission) || return (
permission.some(permission => userStore.permissionsSet.has(permission)) userStore.permissions.has(all_permission) ||
permission.some((permission) => userStore.permissions.has(permission))
)
} }

View File

@ -15,8 +15,7 @@ interface UserVO {
interface UserInfoVO { interface UserInfoVO {
// USER 缓存 // USER 缓存
permissions: string[] permissions: Set<string>
permissionsSet: Set<string>
roles: string[] roles: string[]
isSetUser: boolean isSetUser: boolean
user: UserVO user: UserVO
@ -24,8 +23,7 @@ interface UserInfoVO {
export const useUserStore = defineStore('admin-user', { export const useUserStore = defineStore('admin-user', {
state: (): UserInfoVO => ({ state: (): UserInfoVO => ({
permissions: [], permissions: new Set<string>(),
permissionsSet: new Set<string>(),
roles: [], roles: [],
isSetUser: false, isSetUser: false,
user: { user: {
@ -36,7 +34,7 @@ export const useUserStore = defineStore('admin-user', {
} }
}), }),
getters: { getters: {
getPermissions(): string[] { getPermissions(): Set<string> {
return this.permissions return this.permissions
}, },
getRoles(): string[] { getRoles(): string[] {
@ -59,8 +57,7 @@ export const useUserStore = defineStore('admin-user', {
if (!userInfo) { if (!userInfo) {
userInfo = await getInfo() userInfo = await getInfo()
} }
this.permissions = userInfo.permissions this.permissions = new Set(userInfo.permissions)
this.permissionsSet = new Set(userInfo.permissions)
this.roles = userInfo.roles this.roles = userInfo.roles
this.user = userInfo.user this.user = userInfo.user
this.isSetUser = true this.isSetUser = true
@ -88,7 +85,7 @@ export const useUserStore = defineStore('admin-user', {
this.resetState() this.resetState()
}, },
resetState() { resetState() {
this.permissions = [] this.permissions = new Set<string>()
this.roles = [] this.roles = []
this.isSetUser = false this.isSetUser = false
this.user = { this.user = {

View File

@ -190,10 +190,7 @@
<el-button type="primary" link>更多</el-button> <el-button type="primary" link>更多</el-button>
<template #dropdown> <template #dropdown>
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item <el-dropdown-item command="handleDefinitionList" v-if="hasPermiPdQuery">
command="handleDefinitionList"
v-if="hasPermiPdQuery"
>
历史 历史
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item <el-dropdown-item
@ -278,6 +275,7 @@ const originalData: any = ref([]) // 原始数据
const modelList: any = ref([]) // const modelList: any = ref([]) //
const isExpand = ref(false) // const isExpand = ref(false) //
/** 权限校验:通过 computed 解决列表的卡顿问题 */
const hasPermiUpdate = computed(() => { const hasPermiUpdate = computed(() => {
return checkPermi(['bpm:model:update']) return checkPermi(['bpm:model:update'])
}) })
@ -294,7 +292,6 @@ const hasPermiPdQuery = computed(() => {
return checkPermi(['bpm:process-definition:query']) return checkPermi(['bpm:process-definition:query'])
}) })
/** '更多'操作按钮 */ /** '更多'操作按钮 */
const handleModelCommand = (command: string, row: any) => { const handleModelCommand = (command: string, row: any) => {
switch (command) { switch (command) {