feat(@vben/common-ui): 添加权限控制功能
This commit is contained in:
parent
d3c25dd899
commit
250b319c89
@ -11,9 +11,12 @@ import { objectOmit } from '@vueuse/core';
|
|||||||
import { Button, Image, Popconfirm, Switch, Tag } from 'ant-design-vue';
|
import { Button, Image, Popconfirm, Switch, Tag } from 'ant-design-vue';
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
import { useAuthStore } from '#/store';
|
||||||
|
|
||||||
import { useVbenForm } from './form';
|
import { useVbenForm } from './form';
|
||||||
|
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
setupVbenVxeTable({
|
setupVbenVxeTable({
|
||||||
configVxeTable: (vxeUI) => {
|
configVxeTable: (vxeUI) => {
|
||||||
vxeUI.setConfig({
|
vxeUI.setConfig({
|
||||||
@ -162,7 +165,11 @@ setupVbenVxeTable({
|
|||||||
});
|
});
|
||||||
return optBtn;
|
return optBtn;
|
||||||
})
|
})
|
||||||
.filter((opt) => opt.show !== false);
|
.filter(
|
||||||
|
(opt) =>
|
||||||
|
opt.show !== false &&
|
||||||
|
(!opt.permission || authStore.hasPerm(opt.permission)),
|
||||||
|
);
|
||||||
|
|
||||||
function renderBtn(opt: Recordable<any>, listen = true) {
|
function renderBtn(opt: Recordable<any>, listen = true) {
|
||||||
return h(
|
return h(
|
||||||
|
@ -134,6 +134,12 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
loginLoading.value = false;
|
loginLoading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 👇 添加 hasPerm 方法
|
||||||
|
function hasPerm(permission: string): boolean {
|
||||||
|
const userInfo = userStore.userInfo;
|
||||||
|
return Boolean(userInfo?.permissions?.includes(permission));
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
$reset,
|
$reset,
|
||||||
authLogin,
|
authLogin,
|
||||||
@ -141,5 +147,6 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
loginLoading,
|
loginLoading,
|
||||||
logout,
|
logout,
|
||||||
csrfToken,
|
csrfToken,
|
||||||
|
hasPerm,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -186,6 +186,7 @@ export function useColumns<T = UserApi.User>(
|
|||||||
nameField: 'name',
|
nameField: 'name',
|
||||||
nameTitle: '用户',
|
nameTitle: '用户',
|
||||||
onClick: onActionClick,
|
onClick: onActionClick,
|
||||||
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
code: 'edit',
|
code: 'edit',
|
||||||
@ -196,7 +197,6 @@ export function useColumns<T = UserApi.User>(
|
|||||||
text: '删除',
|
text: '删除',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
|
||||||
name: 'CellOperation',
|
name: 'CellOperation',
|
||||||
},
|
},
|
||||||
field: 'operation',
|
field: 'operation',
|
||||||
|
Loading…
Reference in New Issue
Block a user