Merge branch 'feature/bpm_fix_250121' of https://github.com/zws-code/yudao-ui-admin-vue3-fix into feature/bpm

This commit is contained in:
YunaiV 2025-01-23 19:33:21 +08:00
commit bf437421bb
4 changed files with 38 additions and 34 deletions

View File

@ -1,5 +1,5 @@
import type { App } from 'vue' import type {App} from 'vue'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache' import {useUserStore} from "@/store/modules/user";
const { t } = useI18n() // 国际化 const { t } = useI18n() // 国际化
@ -18,14 +18,9 @@ export function hasPermi(app: App<Element>) {
} }
}) })
} }
const userStore = useUserStore();
const all_permission = '*:*:*'
export const hasPermission = (permission: string[]) => { export const hasPermission = (permission: string[]) => {
const { wsCache } = useCache() return userStore.permissionsSet.has(all_permission) ||
const all_permission = '*:*:*' permission.some(permission => userStore.permissionsSet.has(permission))
const userInfo = wsCache.get(CACHE_KEY.USER) }
const permissions = userInfo?.permissions || []
return permissions.some((p: string) => {
return all_permission === p || permission.includes(p)
})
}

View File

@ -16,6 +16,7 @@ interface UserVO {
interface UserInfoVO { interface UserInfoVO {
// USER 缓存 // USER 缓存
permissions: string[] permissions: string[]
permissionsSet: Set<string>
roles: string[] roles: string[]
isSetUser: boolean isSetUser: boolean
user: UserVO user: UserVO
@ -24,6 +25,7 @@ interface UserInfoVO {
export const useUserStore = defineStore('admin-user', { export const useUserStore = defineStore('admin-user', {
state: (): UserInfoVO => ({ state: (): UserInfoVO => ({
permissions: [], permissions: [],
permissionsSet: new Set<string>(),
roles: [], roles: [],
isSetUser: false, isSetUser: false,
user: { user: {
@ -58,6 +60,7 @@ export const useUserStore = defineStore('admin-user', {
userInfo = await getInfo() userInfo = await getInfo()
} }
this.permissions = userInfo.permissions this.permissions = 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

View File

@ -1,4 +1,6 @@
import { CACHE_KEY, useCache } from '@/hooks/web/useCache' import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import {hasPermission} from "@/directives/permission/hasPermi";
const { t } = useI18n() // 国际化 const { t } = useI18n() // 国际化
@ -7,21 +9,8 @@ const { t } = useI18n() // 国际化
* @param {Array} value * @param {Array} value
* @returns {Boolean} * @returns {Boolean}
*/ */
export function checkPermi(value: string[]) { export function checkPermi(permission: string[]) {
if (value && value instanceof Array && value.length > 0) { return hasPermission(permission)
const { wsCache } = useCache()
const permissionDatas = value
const all_permission = '*:*:*'
const userInfo = wsCache.get(CACHE_KEY.USER)
const permissions = userInfo?.permissions || []
const hasPermission = permissions.some((permission: string) => {
return all_permission === permission || permissionDatas.includes(permission)
})
return !!hasPermission
} else {
console.error(t('permission.hasPermission'))
return false
}
} }
/** /**

View File

@ -158,7 +158,7 @@
link link
type="primary" type="primary"
@click="openModelForm('update', scope.row.id)" @click="openModelForm('update', scope.row.id)"
v-hasPermi="['bpm:model:update']" v-if="hasPermiUpdate"
:disabled="!isManagerUser(scope.row)" :disabled="!isManagerUser(scope.row)"
> >
修改 修改
@ -167,7 +167,7 @@
link link
type="primary" type="primary"
@click="openModelForm('copy', scope.row.id)" @click="openModelForm('copy', scope.row.id)"
v-hasPermi="['bpm:model:update']" v-if="hasPermiUpdate"
:disabled="!isManagerUser(scope.row)" :disabled="!isManagerUser(scope.row)"
> >
复制 复制
@ -177,7 +177,7 @@
class="!ml-5px" class="!ml-5px"
type="primary" type="primary"
@click="handleDeploy(scope.row)" @click="handleDeploy(scope.row)"
v-hasPermi="['bpm:model:deploy']" v-if="hasPermiDeploy"
:disabled="!isManagerUser(scope.row)" :disabled="!isManagerUser(scope.row)"
> >
发布 发布
@ -185,20 +185,20 @@
<el-dropdown <el-dropdown
class="!align-middle ml-5px" class="!align-middle ml-5px"
@command="(command) => handleModelCommand(command, scope.row)" @command="(command) => handleModelCommand(command, scope.row)"
v-hasPermi="['bpm:process-definition:query', 'bpm:model:update', 'bpm:model:delete']" v-if="hasPermiMore"
> >
<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" command="handleDefinitionList"
v-if="checkPermi(['bpm:process-definition:query'])" v-if="hasPermiPdQuery"
> >
历史 历史
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item <el-dropdown-item
command="handleChangeState" command="handleChangeState"
v-if="checkPermi(['bpm:model:update']) && scope.row.processDefinition" v-if="hasPermiUpdate && scope.row.processDefinition"
:disabled="!isManagerUser(scope.row)" :disabled="!isManagerUser(scope.row)"
> >
{{ scope.row.processDefinition.suspensionState === 1 ? '停用' : '启用' }} {{ scope.row.processDefinition.suspensionState === 1 ? '停用' : '启用' }}
@ -214,7 +214,7 @@
<el-dropdown-item <el-dropdown-item
type="danger" type="danger"
command="handleDelete" command="handleDelete"
v-if="checkPermi(['bpm:model:delete'])" v-if="hasPermiDelete"
:disabled="!isManagerUser(scope.row)" :disabled="!isManagerUser(scope.row)"
> >
删除 删除
@ -278,6 +278,23 @@ const originalData: any = ref([]) // 原始数据
const modelList: any = ref([]) // const modelList: any = ref([]) //
const isExpand = ref(false) // const isExpand = ref(false) //
const hasPermiUpdate = computed(() => {
return checkPermi(['bpm:model:update'])
})
const hasPermiDelete = computed(() => {
return checkPermi(['bpm:model:delete'])
})
const hasPermiDeploy = computed(() => {
return checkPermi(['bpm:model:deploy'])
})
const hasPermiMore = computed(() => {
return checkPermi(['bpm:process-definition:query', 'bpm:model:update', 'bpm:model:delete'])
})
const hasPermiPdQuery = computed(() => {
return checkPermi(['bpm:process-definition:query'])
})
/** '更多'操作按钮 */ /** '更多'操作按钮 */
const handleModelCommand = (command: string, row: any) => { const handleModelCommand = (command: string, row: any) => {
switch (command) { switch (command) {