mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): add auth example
This commit is contained in:
21
src/hooks/business/auth.ts
Normal file
21
src/hooks/business/auth.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { useAuthStore } from '@/store/modules/auth';
|
||||
|
||||
export function useAuth() {
|
||||
const authStore = useAuthStore();
|
||||
|
||||
function hasAuth(codes: string | string[]) {
|
||||
if (!authStore.isLogin) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof codes === 'string') {
|
||||
return authStore.userInfo.buttons.includes(codes);
|
||||
}
|
||||
|
||||
return codes.some(code => authStore.userInfo.buttons.includes(code));
|
||||
}
|
||||
|
||||
return {
|
||||
hasAuth
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user