fix(login): fix
This commit is contained in:
@@ -1,22 +1,22 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useUserStore } from "@/app/store/user"
|
import { usePermissionStore } from "@/components/label/store/auth"
|
||||||
import { usePathname } from "next/navigation"
|
import { usePathname } from "next/navigation"
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
|
|
||||||
export function InfoCheck() {
|
export function InfoCheck() {
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
|
||||||
const user_info = useUserStore.getState().user_info
|
const user_id = usePermissionStore.getState().user_id
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (pathname.startsWith("/login")) {
|
if (pathname.startsWith("/login")) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!user_info.account) {
|
if (!user_id) {
|
||||||
// tauri 打包后, 使用router.push跳转路由不执行,会导致白屏
|
// tauri 打包后, 使用router.push跳转路由不执行,会导致白屏
|
||||||
window.location.href = "/login"
|
window.location.href = "/login"
|
||||||
}
|
}
|
||||||
}, [pathname, user_info.account])
|
}, [pathname, user_id])
|
||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export const componentList: MenuItem[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "管理中心",
|
title: "管理中心",
|
||||||
url: "admin",
|
url: "mgt",
|
||||||
icon: "SystemIcon",
|
icon: "SystemIcon",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import { Login } from "./types"
|
|||||||
|
|
||||||
const BASE_PATH =
|
const BASE_PATH =
|
||||||
process.env.NEXT_PUBLIC_ENV === "production"
|
process.env.NEXT_PUBLIC_ENV === "production"
|
||||||
? "https://basis.soft.cowarobot.com"
|
? "https://label.soft.cowarobot.com"
|
||||||
: "https://basis.softtest.cowarobot.com"
|
: "https://label.softtest.cowarobot.com"
|
||||||
|
|
||||||
// 获取验证码
|
// 获取验证码
|
||||||
export const getVerifyCode = (params: { phone: string }) => {
|
export const getVerifyCode = (params: { phone: string }) => {
|
||||||
return httpFetch<ResultData<{}>>({
|
return httpFetch<ResultData<{}>>({
|
||||||
url: BASE_PATH + `/api/v1/basis/login/get_verify_code`,
|
url: BASE_PATH + `/api/v1/label_server/login/get_verify_code`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify(params),
|
||||||
})
|
})
|
||||||
@@ -18,10 +18,10 @@ export const getVerifyCode = (params: { phone: string }) => {
|
|||||||
|
|
||||||
// 账户登录
|
// 账户登录
|
||||||
export const passwdLogin = (params: Login.ReqPasswdLogin) => {
|
export const passwdLogin = (params: Login.ReqPasswdLogin) => {
|
||||||
return httpFetch<ResultData<Login.ResLogin>>({
|
return httpFetch<Login.ResLabelLogin>({
|
||||||
url: BASE_PATH + `/api/v1/basis/login/passwd`,
|
url: BASE_PATH + `/api/v1/label_server/user/login`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify({ ...params, name: params.account || params.phone }),
|
||||||
isLogin: true,
|
isLogin: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ export const passwdLogin = (params: Login.ReqPasswdLogin) => {
|
|||||||
// 验证码登录
|
// 验证码登录
|
||||||
export const verificationLogin = (params: Login.ReqVerificationLogin) => {
|
export const verificationLogin = (params: Login.ReqVerificationLogin) => {
|
||||||
return httpFetch<ResultData<Login.ResLogin>>({
|
return httpFetch<ResultData<Login.ResLogin>>({
|
||||||
url: BASE_PATH + `/api/v1/basis/login/verification`,
|
url: BASE_PATH + `/api/v1/label_server/login/verification`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify(params),
|
||||||
isLogin: true,
|
isLogin: true,
|
||||||
@@ -39,7 +39,7 @@ export const verificationLogin = (params: Login.ReqVerificationLogin) => {
|
|||||||
// 飞书登录
|
// 飞书登录
|
||||||
export const fetchFeishuLogin = (params: Login.ReqFeishuLogin) => {
|
export const fetchFeishuLogin = (params: Login.ReqFeishuLogin) => {
|
||||||
return httpFetch<ResultData<Login.ResLogin>>({
|
return httpFetch<ResultData<Login.ResLogin>>({
|
||||||
url: BASE_PATH + `/api/v1/basis/login/feishu`,
|
url: BASE_PATH + `/api/v1/label_server/login/feishu`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify(params),
|
||||||
isLogin: true,
|
isLogin: true,
|
||||||
@@ -49,7 +49,7 @@ export const fetchFeishuLogin = (params: Login.ReqFeishuLogin) => {
|
|||||||
// 刷新token
|
// 刷新token
|
||||||
export const refreshKey = (params: { token: string }) => {
|
export const refreshKey = (params: { token: string }) => {
|
||||||
return httpFetch<ResultData<Login.ResRefreshKey>>({
|
return httpFetch<ResultData<Login.ResRefreshKey>>({
|
||||||
url: BASE_PATH + `/api/v1/basis/key/refresh`,
|
url: BASE_PATH + `/api/v1/label_server/user/refresh_token`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(params),
|
body: JSON.stringify(params),
|
||||||
isRefresh: true,
|
isRefresh: true,
|
||||||
|
|||||||
@@ -58,6 +58,19 @@ export namespace Login {
|
|||||||
refresh_token: string
|
refresh_token: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ResLabelLogin {
|
||||||
|
all_projects: Record<string, Array<number>>
|
||||||
|
base_city: string
|
||||||
|
collect_projects: Array<number>
|
||||||
|
group_name: string
|
||||||
|
name: string
|
||||||
|
permissions: Record<string, Record<string, [boolean, any, string]>>
|
||||||
|
refresh_token: string
|
||||||
|
token: string
|
||||||
|
uid: number
|
||||||
|
work_status: number
|
||||||
|
}
|
||||||
|
|
||||||
export interface ResRefreshKey {
|
export interface ResRefreshKey {
|
||||||
access: string
|
access: string
|
||||||
refresh: string
|
refresh: string
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { DigitalIcon } from "./resource/icons/digital"
|
|||||||
import { useLoginStore } from "./store"
|
import { useLoginStore } from "./store"
|
||||||
import tabClasses from "./Tab.module.css"
|
import tabClasses from "./Tab.module.css"
|
||||||
// import { useSearchParams } from "next/navigation"
|
// import { useSearchParams } from "next/navigation"
|
||||||
|
import { usePermissionStore } from "../label/store/auth"
|
||||||
import Feishu from "./feishu/auto-login"
|
import Feishu from "./feishu/auto-login"
|
||||||
import DarkBgImage from "./resource/images/dark-login-bg.png"
|
import DarkBgImage from "./resource/images/dark-login-bg.png"
|
||||||
import LightBgImage from "./resource/images/light-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 { setUserInfo, refreshToken } = useUserStore()
|
||||||
|
|
||||||
|
const { setUserPermissionInfo } = usePermissionStore()
|
||||||
|
|
||||||
// 表单提交处理
|
// 表单提交处理
|
||||||
const handleAccountSubmit = accountForm.onSubmit(
|
const handleAccountSubmit = accountForm.onSubmit(
|
||||||
async (values) => {
|
async (values) => {
|
||||||
@@ -198,11 +201,15 @@ export default function LoginPage({ useUserStore }: { useUserStore: any }) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const res = await passwdLogin(params)
|
const res = await passwdLogin(params)
|
||||||
const info = res.message
|
const { uid, name } = res
|
||||||
setUserInfo(info.tenant, info.user_info, info.rbac)
|
setUserPermissionInfo({
|
||||||
|
user_id: uid,
|
||||||
|
user_name: name,
|
||||||
|
detailInfo: res,
|
||||||
|
})
|
||||||
refreshToken({
|
refreshToken({
|
||||||
access_token: info.access_token || "",
|
access_token: res.token || "",
|
||||||
refresh_token: info.refresh_token || "",
|
refresh_token: res.refresh_token || "",
|
||||||
})
|
})
|
||||||
window.location.href = `${process.env.NEXT_PUBLIC_BASE_PATH}/`
|
window.location.href = `${process.env.NEXT_PUBLIC_BASE_PATH}/`
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -396,18 +403,18 @@ export default function LoginPage({ useUserStore }: { useUserStore: any }) {
|
|||||||
className={tabClasses.tab}>
|
className={tabClasses.tab}>
|
||||||
账户登录
|
账户登录
|
||||||
</Tabs.Tab>
|
</Tabs.Tab>
|
||||||
<Tabs.Tab
|
{/* <Tabs.Tab
|
||||||
value="phone"
|
value="phone"
|
||||||
ref={setControlRef("phone")}
|
ref={setControlRef("phone")}
|
||||||
className={""}>
|
className={""}>
|
||||||
手机号登录
|
手机号登录
|
||||||
</Tabs.Tab>
|
</Tabs.Tab> */}
|
||||||
<Tabs.Tab
|
{/* <Tabs.Tab
|
||||||
value="feishu"
|
value="feishu"
|
||||||
ref={setControlRef("feishu")}
|
ref={setControlRef("feishu")}
|
||||||
className={tabClasses.tab}>
|
className={tabClasses.tab}>
|
||||||
飞书扫码
|
飞书扫码
|
||||||
</Tabs.Tab>
|
</Tabs.Tab> */}
|
||||||
<FloatingIndicator
|
<FloatingIndicator
|
||||||
target={activeTab ? controlsRefs[activeTab] : null}
|
target={activeTab ? controlsRefs[activeTab] : null}
|
||||||
parent={rootRef}
|
parent={rootRef}
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import { cookies } from "next/headers"
|
|||||||
export const handleLoginData = async (props: {
|
export const handleLoginData = async (props: {
|
||||||
clientIP: string
|
clientIP: string
|
||||||
fingerprint: string
|
fingerprint: string
|
||||||
data: ResultData<Login.ResLogin>
|
data: Login.ResLabelLogin
|
||||||
}) => {
|
}) => {
|
||||||
const { clientIP, fingerprint, data } = props
|
const { clientIP, fingerprint, data } = props
|
||||||
|
|
||||||
const sessionKey = {
|
const sessionKey = {
|
||||||
clientIP,
|
clientIP,
|
||||||
fingerprint: fingerprint,
|
fingerprint: fingerprint,
|
||||||
@@ -30,9 +31,9 @@ export const handleLoginData = async (props: {
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
clientIP,
|
clientIP,
|
||||||
fingerprint: fingerprint,
|
fingerprint: fingerprint,
|
||||||
user_name: data?.message?.user_info?.user_name,
|
user_name: data?.name,
|
||||||
access_token: data.message.access_token,
|
access_token: data.token,
|
||||||
refresh_token: data.message.refresh_token,
|
refresh_token: data.refresh_token,
|
||||||
}),
|
}),
|
||||||
"EX",
|
"EX",
|
||||||
172800
|
172800
|
||||||
@@ -47,11 +48,9 @@ export const handleLoginData = async (props: {
|
|||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
message: {
|
token: "",
|
||||||
...data.message,
|
|
||||||
access_token: "",
|
access_token: "",
|
||||||
refresh_token: "",
|
refresh_token: "",
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user