Browse Source

加入注册页面 未成功

main
lk 3 months ago
parent
commit
42d07cdabd
  1. 4
      src/pages/login/index.tsx
  2. 8
      src/request.ts
  3. 5
      src/routes.tsx
  4. 16
      src/store/system/user.ts
  5. 2
      vite.config.ts

4
src/pages/login/index.tsx

@ -13,13 +13,13 @@ const { TabPane } = Tabs;
const Login = memo(() => {
const [upform] = Form.useForm();
const [emailform] = Form.useForm();
const { mutate: upMutate } = useAtomValue(upLoginAtom);
const { mutate: upLoginFun } = useAtomValue(upLoginAtom);
const { mutate: emailCodeMutate } = useAtomValue(emailCodeAtom);
const { mutate: emailLoginMutate } = useAtomValue(emailLoginAtom);
const uphandleSubmit = (values: any) => {
console.log(values);
upMutate(values);
upLoginFun(values);
};
const emailhandleSubmit = (values: any) => {
console.log(values);

8
src/request.ts

@ -71,7 +71,9 @@ axiosInstance.interceptors.response.use(
if (window.location.pathname === "/login") {
return Promise.reject(new Error("to login"));
}
if (window.location.pathname === "/register") {
return Promise.reject(new Error("register"));
}
// 401: 未登录
message.error("登录失败,跳转重新登录");
// eslint-disable-next-line no-case-declarations
@ -98,7 +100,9 @@ axiosInstance.interceptors.response.use(
if (window.location.pathname === "/login") {
return;
}
if (window.location.pathname === "/register") {
return;
}
setToken("");
// 401: 未登录
message.error("登录失败,跳转重新登录");

5
src/routes.tsx

@ -163,6 +163,11 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof LoginRouteImport
parentRoute: typeof rootRoute
},
'/register': {
preLoaderRoute: typeof layoutNormalRoute
parentRoute: typeof rootRoute
},
// '/system/menus': {
// preLoaderRoute: typeof menusRoute
// parentRoute: typeof layoutAuthRoute

16
src/store/system/user.ts

@ -17,6 +17,7 @@ export interface UPLoginRequest {
password: string;
code: string;
}
export interface LoginResponse {}
export const authAtom = atom<IAuth>({
isLogin: false,
@ -31,30 +32,30 @@ const devLogin = {
export const upLoginFormAtom = atom<UPLoginRequest>({
...(isDev ? devLogin : {}),
} as UPLoginRequest);
export const upLoginAtom = atomWithMutation<any, System.LoginRequest>((get) => ({
//============================================================================================================登录 登出
export const upLoginAtom = atomWithMutation<any, UPLoginRequest>((get) => ({
mutationKey: ["uplogin"],
mutationFn: async (params) => {
mutationFn: async (params: UPLoginRequest) => {
return await systemServ.uplogin(params);
},
onSuccess: (res) => {
message.success(t("login.success"));
// console.log('login success', res)
get(userMenuDataAtom).refetch().then();
return res.data;
},
retry: false,
}));
export const emailCodeAtom = atomWithMutation<any, any>((get) => ({
mutationKey: ["emailCode"],
mutationFn: async (params) => {
return await systemServ.emailCode(params);
},
onSuccess: (res) => {
message.success(t("login.success"));
//message.success(t("login.success"));
// console.log('login success', res)
get(userMenuDataAtom).refetch().then();
//get(userMenuDataAtom).refetch().then();
return res.data;
},
retry: false,
@ -67,7 +68,6 @@ export const emailLoginAtom = atomWithMutation<any, any>((get) => ({
onSuccess: (res) => {
message.success(t("login.success"));
// console.log('login success', res)
get(userMenuDataAtom).refetch().then();
return res.data;
},
retry: false,
@ -80,7 +80,7 @@ export const logoutAtom = atomWithMutation(() => ({
return true;
},
}));
//============================================================================================================
export const currentStaticUserAtom = atomWithStorage<IUserInfo | null>("user", null);
export const currentUserAtom = atomWithQuery<IApiResult<System.IUserInfo>, any, System.IUserInfo>((get) => {

2
vite.config.ts

@ -14,7 +14,7 @@ const proxyMap = {
//'/api/v1/certold': 'http://192.168.31.41:8000',
"/api/v1/cert": "http://127.0.0.1:8000",
//'/api/v1/cert': 'http://192.168.31.41:8000',
"/api/v1/sys": "http://192.168.31.41:8686/",
//"/api/v1/sys": "http://192.168.31.41:8686/",
} as Record<any, string>;
const proxyConfig = Object.keys(proxyMap).reduce(

Loading…
Cancel
Save