2026-03-26 20:18:20 +08:00
|
|
|
import { useAuthStore } from '@/store/modules/auth';
|
2026-04-23 09:05:55 +08:00
|
|
|
import { useObjectContextStore } from '@/store/modules/object-context';
|
2026-03-26 20:18:20 +08:00
|
|
|
|
|
|
|
|
export function useAuth() {
|
|
|
|
|
const authStore = useAuthStore();
|
2026-04-23 09:05:55 +08:00
|
|
|
const objectContextStore = useObjectContextStore();
|
2026-03-26 20:18:20 +08:00
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-23 09:05:55 +08:00
|
|
|
function hasObjectAuth(codes: string | string[]) {
|
|
|
|
|
const targetCodes = typeof codes === 'string' ? [codes] : codes;
|
|
|
|
|
|
|
|
|
|
return targetCodes.some(code => objectContextStore.buttonCodes.includes(code));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 20:18:20 +08:00
|
|
|
return {
|
2026-04-23 09:05:55 +08:00
|
|
|
hasAuth,
|
|
|
|
|
hasObjectAuth
|
2026-03-26 20:18:20 +08:00
|
|
|
};
|
|
|
|
|
}
|