From 37ecb4641bf64f559812203a258d72b61be8c551 Mon Sep 17 00:00:00 2001 From: shay7sev Date: Mon, 16 Mar 2026 15:55:33 +0800 Subject: [PATCH] fix(login): fix --- app/store/InfoCheck.tsx | 8 ++++---- components/layout/common.ts | 2 +- components/login/api/index.ts | 18 +++++++++--------- components/login/api/types.ts | 13 +++++++++++++ components/login/index.tsx | 23 +++++++++++++++-------- components/login/libs/cookie.ts | 17 ++++++++--------- 6 files changed, 50 insertions(+), 31 deletions(-) diff --git a/app/store/InfoCheck.tsx b/app/store/InfoCheck.tsx index e7e5e59..df4e073 100644 --- a/app/store/InfoCheck.tsx +++ b/app/store/InfoCheck.tsx @@ -1,22 +1,22 @@ "use client" -import { useUserStore } from "@/app/store/user" +import { usePermissionStore } from "@/components/label/store/auth" import { usePathname } from "next/navigation" import { useEffect } from "react" export function InfoCheck() { const pathname = usePathname() - const user_info = useUserStore.getState().user_info + const user_id = usePermissionStore.getState().user_id useEffect(() => { if (pathname.startsWith("/login")) { return } - if (!user_info.account) { + if (!user_id) { // tauri 打包后, 使用router.push跳转路由不执行,会导致白屏 window.location.href = "/login" } - }, [pathname, user_info.account]) + }, [pathname, user_id]) return <> } diff --git a/components/layout/common.ts b/components/layout/common.ts index 1732b8c..322a586 100644 --- a/components/layout/common.ts +++ b/components/layout/common.ts @@ -47,7 +47,7 @@ export const componentList: MenuItem[] = [ }, { title: "管理中心", - url: "admin", + url: "mgt", icon: "SystemIcon", }, ] diff --git a/components/login/api/index.ts b/components/login/api/index.ts index 75a3269..1661efc 100644 --- a/components/login/api/index.ts +++ b/components/login/api/index.ts @@ -4,13 +4,13 @@ import { Login } from "./types" const BASE_PATH = process.env.NEXT_PUBLIC_ENV === "production" - ? "https://basis.soft.cowarobot.com" - : "https://basis.softtest.cowarobot.com" + ? "https://label.soft.cowarobot.com" + : "https://label.softtest.cowarobot.com" // 获取验证码 export const getVerifyCode = (params: { phone: string }) => { return httpFetch>({ - url: BASE_PATH + `/api/v1/basis/login/get_verify_code`, + url: BASE_PATH + `/api/v1/label_server/login/get_verify_code`, method: "POST", body: JSON.stringify(params), }) @@ -18,10 +18,10 @@ export const getVerifyCode = (params: { phone: string }) => { // 账户登录 export const passwdLogin = (params: Login.ReqPasswdLogin) => { - return httpFetch>({ - url: BASE_PATH + `/api/v1/basis/login/passwd`, + return httpFetch({ + url: BASE_PATH + `/api/v1/label_server/user/login`, method: "POST", - body: JSON.stringify(params), + body: JSON.stringify({ ...params, name: params.account || params.phone }), isLogin: true, }) } @@ -29,7 +29,7 @@ export const passwdLogin = (params: Login.ReqPasswdLogin) => { // 验证码登录 export const verificationLogin = (params: Login.ReqVerificationLogin) => { return httpFetch>({ - url: BASE_PATH + `/api/v1/basis/login/verification`, + url: BASE_PATH + `/api/v1/label_server/login/verification`, method: "POST", body: JSON.stringify(params), isLogin: true, @@ -39,7 +39,7 @@ export const verificationLogin = (params: Login.ReqVerificationLogin) => { // 飞书登录 export const fetchFeishuLogin = (params: Login.ReqFeishuLogin) => { return httpFetch>({ - url: BASE_PATH + `/api/v1/basis/login/feishu`, + url: BASE_PATH + `/api/v1/label_server/login/feishu`, method: "POST", body: JSON.stringify(params), isLogin: true, @@ -49,7 +49,7 @@ export const fetchFeishuLogin = (params: Login.ReqFeishuLogin) => { // 刷新token export const refreshKey = (params: { token: string }) => { return httpFetch>({ - url: BASE_PATH + `/api/v1/basis/key/refresh`, + url: BASE_PATH + `/api/v1/label_server/user/refresh_token`, method: "POST", body: JSON.stringify(params), isRefresh: true, diff --git a/components/login/api/types.ts b/components/login/api/types.ts index a894fd9..deb54a9 100644 --- a/components/login/api/types.ts +++ b/components/login/api/types.ts @@ -58,6 +58,19 @@ export namespace Login { refresh_token: string } + export interface ResLabelLogin { + all_projects: Record> + base_city: string + collect_projects: Array + group_name: string + name: string + permissions: Record> + refresh_token: string + token: string + uid: number + work_status: number + } + export interface ResRefreshKey { access: string refresh: string diff --git a/components/login/index.tsx b/components/login/index.tsx index 1bf6459..35ffdbc 100644 --- a/components/login/index.tsx +++ b/components/login/index.tsx @@ -33,6 +33,7 @@ import { DigitalIcon } from "./resource/icons/digital" import { useLoginStore } from "./store" import tabClasses from "./Tab.module.css" // import { useSearchParams } from "next/navigation" +import { usePermissionStore } from "../label/store/auth" import Feishu from "./feishu/auto-login" import DarkBgImage from "./resource/images/dark-login-bg.png" import LightBgImage from "./resource/images/light-login-bg.png" @@ -176,6 +177,8 @@ export default function LoginPage({ useUserStore }: { useUserStore: any }) { const { setUserInfo, refreshToken } = useUserStore() + const { setUserPermissionInfo } = usePermissionStore() + // 表单提交处理 const handleAccountSubmit = accountForm.onSubmit( async (values) => { @@ -198,11 +201,15 @@ export default function LoginPage({ useUserStore }: { useUserStore: any }) { } try { const res = await passwdLogin(params) - const info = res.message - setUserInfo(info.tenant, info.user_info, info.rbac) + const { uid, name } = res + setUserPermissionInfo({ + user_id: uid, + user_name: name, + detailInfo: res, + }) refreshToken({ - access_token: info.access_token || "", - refresh_token: info.refresh_token || "", + access_token: res.token || "", + refresh_token: res.refresh_token || "", }) window.location.href = `${process.env.NEXT_PUBLIC_BASE_PATH}/` } catch (error) { @@ -396,18 +403,18 @@ export default function LoginPage({ useUserStore }: { useUserStore: any }) { className={tabClasses.tab}> 账户登录 - 手机号登录 - - */} + {/* 飞书扫码 - + */} + data: Login.ResLabelLogin }) => { const { clientIP, fingerprint, data } = props + const sessionKey = { clientIP, fingerprint: fingerprint, @@ -30,9 +31,9 @@ export const handleLoginData = async (props: { JSON.stringify({ clientIP, fingerprint: fingerprint, - user_name: data?.message?.user_info?.user_name, - access_token: data.message.access_token, - refresh_token: data.message.refresh_token, + user_name: data?.name, + access_token: data.token, + refresh_token: data.refresh_token, }), "EX", 172800 @@ -47,11 +48,9 @@ export const handleLoginData = async (props: { }) return { ...data, - message: { - ...data.message, - access_token: "", - refresh_token: "", - }, + token: "", + access_token: "", + refresh_token: "", } }