Skip to content

Commit

Permalink
Merge pull request #64 from sj-distributor/enhance-login-permission
Browse files Browse the repository at this point in the history
Enhance login permission
  • Loading branch information
chenmeiling12 authored Nov 13, 2024
2 parents 7274772 + c5acc01 commit 192aec9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions web/src/dtos/mine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export enum FrontRolePermissionEnum {
CanViewCameraAiFeedbackListPage = "CanViewCameraAiFeedbackListPage",
CanExportExcelCameraAiFeedback = "CanExportExcelCameraAiFeedback",
CanViewDetailCameraAiFeedback = "CanViewDetailCameraAiFeedback",
CanEnterCameraAi = "CanEnterCameraAi",
}
40 changes: 38 additions & 2 deletions web/src/pages/login/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useState } from "react";
import { IUserInfo } from "@/dtos";
import { useAuth } from "@/hooks/use-auth";
import { Login } from "@/services/home";
import { GetMineRoleList } from "@/services/default";
import { FrontRolePermissionEnum } from "@/dtos/mine";

export const useAction = () => {
const { signIn, message } = useAuth();
Expand All @@ -22,6 +24,16 @@ export const useAction = () => {
}));
};

const hanldeNoPermission = () => {
message.error("您没有访问权限");

localStorage.removeItem(
(window as any).appsettings?.tokenKey ?? "tokenKey"
);

localStorage.removeItem((window as any).appsettings?.userNameKey);
};

const onLogin = () => {
setLoginLoading(true);
if (
Expand All @@ -31,14 +43,38 @@ export const useAction = () => {
Login(userInfo)
.then((res) => {
if (res) {
message.success("登录成功");
localStorage.setItem((window as any).appsettings?.tokenKey, res);
localStorage.setItem(
(window as any).appsettings?.userNameKey,
userInfo.userName
);

signIn(res, userInfo.userName);
GetMineRoleList()
.then((response) => {
if (
response.rolePermissionData.some((item) =>
item.permissions.some(
(permission) =>
permission.name ===
FrontRolePermissionEnum.CanEnterCameraAi
)
)
) {
message.success("登录成功");

signIn(
localStorage.getItem(
(window as any).appsettings?.tokenKey ?? "tokenKey"
) ?? "",
userInfo.userName
);
} else {
hanldeNoPermission();
}
})
.catch(() => {
hanldeNoPermission();
});
}
})
.catch(() => {
Expand Down

0 comments on commit 192aec9

Please sign in to comment.