Skip to content

Commit

Permalink
fix(修复前端超管判断逻辑)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanyxmo committed Oct 16, 2024
1 parent 5a1919b commit 7ab13d9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion storage/swagger/http.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export default function getTableColumns(dialog: UseDialogExpose, formRef: any, t
const msg = useMessage()

const showBtn = (auth: string | string[], row: RoleVo) => {
return hasAuth(auth) && row.id !== 1 && row.code !== 'SuperAdmin'
return hasAuth(auth) && row.id !== 1
}

return [
// 多选列
{ type: 'selection', showOverflowTooltip: false, label: () => t('crud.selection'),
cellRender: ({ row }): any => (row.id === 1 || row.name === 'SuperAdmin') ? '-' : undefined,
selectable: (row: RoleVo) => ![1].includes(row.id as number) || !['SuperAdmin'].includes(row.code as string),
cellRender: ({ row }): any => row.id === 1 ? '-' : undefined,
selectable: (row: RoleVo) => ![1].includes(row.id as number),
},
// 索引序号列
{ type: 'index' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export default function getTableColumns(dialog: UseDialogExpose, formRef: any, t
const msg = useMessage()

const showBtn = (auth: string | string[], row: UserVo) => {
return hasAuth(auth) && row.id !== 1 && row.username !== 'SuperAdmin'
return hasAuth(auth) && row.id !== 1
}

return [
// 多选列
{ type: 'selection', showOverflowTooltip: false, label: () => t('crud.selection'),
cellRender: ({ row }): any => (row.id === 1 || row.username === 'SuperAdmin') ? '-' : undefined,
selectable: (row: UserVo) => ![1].includes(row.id as number) || !['SuperAdmin'].includes(row.username as string),
cellRender: ({ row }): any => row.id === 1 ? '-' : undefined,
selectable: (row: UserVo) => ![1].includes(row.id as number),
},
// 索引序号列
{ type: 'index' },
Expand Down Expand Up @@ -117,7 +117,7 @@ export default function getTableColumns(dialog: UseDialogExpose, formRef: any, t
},
{
name: 'noAllowSuperAdmin',
show: ({ row }) => row.id === 1 && row.username === 'SuperAdmin',
show: ({ row }) => row.id === 1,
disabled: () => true,
text: () => t('crud.superAdminNoEdit'),
},
Expand Down
3 changes: 1 addition & 2 deletions web/src/store/modules/useUserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import useThemeColor from '@/hooks/useThemeColor.ts'
import useHttp from '@/hooks/auto-imports/useHttp.ts'
import * as PermissionApi from '~/base/api/permission.ts'
import type { MenuVo, RoleVo } from '~/base/api/permission.ts'
import isSuperAdmin from '@/utils/isSuperAdmin.ts'

export interface LoginParams {
username: string
Expand Down Expand Up @@ -134,7 +133,7 @@ const useUserStore = defineStore(
await routeStore.initRoutes(router, getMenu())
const codes: string[] = []
router.getRoutes()?.map(item => codes.push(item.name as string))
isSuperAdmin() && codes.unshift('*')
getRoles().includes('SuperAdmin') && codes.unshift('*')
setPermissions(codes)
await usePluginStore().callHooks('getUserInfo', data)
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/utils/isSuperAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
* @Link https://github.com/mineadmin
*/
export default function isSuperAdmin() {
return useUserStore().getUserInfo()?.username === 'SuperAdmin'
return useUserStore().getRoles().includes('SuperAdmin')
}
2 changes: 1 addition & 1 deletion web/src/utils/permission/hasRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function hasRole(value: string | string[], whetherCheckRouteMeta:
return false
}

if (roles[0] === 'SuperAdmin') {
if (roles.includes('SuperAdmin')) {
return true
}

Expand Down

0 comments on commit 7ab13d9

Please sign in to comment.