fix(entry): add entry
This commit is contained in:
37
api/fetch.ts
37
api/fetch.ts
@@ -156,7 +156,6 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
||||
}
|
||||
} else {
|
||||
const { status } = response
|
||||
|
||||
if (status === 400) {
|
||||
if (
|
||||
response.headers.get("Content-Type")?.includes("application/json")
|
||||
@@ -170,6 +169,42 @@ async function httpfetch<T>(options: OptionsProps): Promise<T> {
|
||||
Message.error({ content: errInfo || "" })
|
||||
throw new Error(errInfo)
|
||||
}
|
||||
} else if (status === 401) {
|
||||
try {
|
||||
const refreshResponse = await refreshKey({
|
||||
token: refresh_token,
|
||||
})
|
||||
if (refreshResponse.code === 200) {
|
||||
let access_token = refreshResponse.message?.access || ""
|
||||
let refresh_token = refreshResponse.message?.refresh || ""
|
||||
refreshToken({
|
||||
refresh_token,
|
||||
access_token,
|
||||
})
|
||||
const retry_request = createNewRequest(options, access_token)
|
||||
const retry_response = await fetch(retry_request)
|
||||
return options.isDownload
|
||||
? retry_response.blob()
|
||||
: retry_response.json()
|
||||
} else {
|
||||
const { code } = refreshResponse
|
||||
if (code === 406) {
|
||||
try {
|
||||
await deleteCookie()
|
||||
} catch (error) {
|
||||
rejected(error)
|
||||
} finally {
|
||||
// 清空身份信息并跳转至登录页面
|
||||
removeUserInfo()
|
||||
window.location.href = "/login"
|
||||
}
|
||||
} else {
|
||||
throw new Error("重新获取token失败!")
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
rejected(error)
|
||||
}
|
||||
} else if (status === 403) {
|
||||
if (
|
||||
response.headers.get("Content-Type")?.includes("application/json")
|
||||
|
||||
35
app/entry/page.tsx
Normal file
35
app/entry/page.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
"use client"
|
||||
|
||||
import { useUserStore } from "@/app/store/user"
|
||||
import { usePermissionStore } from "@/components/label/store/auth"
|
||||
import { getUserPermission } from "@/components/login/api"
|
||||
import { useCallback, useEffect } from "react"
|
||||
|
||||
export default function EntryCheck() {
|
||||
const user_info = useUserStore.getState().user_info
|
||||
const { setUserPermissionInfo } = usePermissionStore()
|
||||
|
||||
const asyncGetUserPermission = useCallback(async () => {
|
||||
const { message: permissionRes } = await getUserPermission()
|
||||
const { uid, name } = permissionRes
|
||||
setUserPermissionInfo({
|
||||
user_id: uid,
|
||||
user_name: name,
|
||||
detailInfo: permissionRes,
|
||||
})
|
||||
}, [setUserPermissionInfo])
|
||||
|
||||
useEffect(() => {
|
||||
if (!user_info.account) {
|
||||
window.location.href = "/login"
|
||||
} else {
|
||||
try {
|
||||
asyncGetUserPermission()
|
||||
window.location.href = `${process.env.NEXT_PUBLIC_BASE_PATH}/management`
|
||||
} catch {
|
||||
window.location.href = "/login"
|
||||
}
|
||||
}
|
||||
}, [asyncGetUserPermission, user_info.account])
|
||||
return <></>
|
||||
}
|
||||
@@ -1,20 +1,10 @@
|
||||
"use client"
|
||||
|
||||
import { getUserList, userEditById } from "@/components/label/api/user"
|
||||
import { getUserList } from "@/components/label/api/user"
|
||||
import { User } from "@/components/label/api/user/typing"
|
||||
import useAuth from "@/components/label/hooks/useAuth"
|
||||
import { useAllUserStore } from "@/components/label/store/auth"
|
||||
import {
|
||||
ActionIcon,
|
||||
Badge,
|
||||
Button,
|
||||
Group,
|
||||
Paper,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
} from "@mantine/core"
|
||||
import { modals } from "@mantine/modals"
|
||||
import { Badge, Button, Group, Paper, Stack, TextInput } from "@mantine/core"
|
||||
import { notifications } from "@mantine/notifications"
|
||||
import { IconEdit, IconRefresh, IconSearch } from "@tabler/icons-react"
|
||||
import { DataTable, DataTableColumn } from "mantine-datatable"
|
||||
@@ -107,7 +97,7 @@ export default function TeamEmployeePage() {
|
||||
textAlign: "center",
|
||||
render: (record) => (
|
||||
<Group justify="center" gap={4} wrap="nowrap">
|
||||
{isShow("edit") ? (
|
||||
{/* {isShow("edit") ? (
|
||||
<Button
|
||||
variant="subtle"
|
||||
size="compact-xs"
|
||||
@@ -131,17 +121,18 @@ export default function TeamEmployeePage() {
|
||||
}}>
|
||||
重置密码
|
||||
</Button>
|
||||
) : null}
|
||||
) : null} */}
|
||||
{isShow("edit") ? (
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
<Button
|
||||
variant="transparent"
|
||||
leftSection={<IconEdit size={16} />}
|
||||
color="blue"
|
||||
onClick={() => {
|
||||
setSelectedUser(record)
|
||||
setEditOpened(true)
|
||||
}}>
|
||||
<IconEdit size={16} />
|
||||
</ActionIcon>
|
||||
编辑
|
||||
</Button>
|
||||
) : null}
|
||||
</Group>
|
||||
),
|
||||
@@ -234,6 +225,7 @@ export default function TeamEmployeePage() {
|
||||
fetching={loading}
|
||||
records={records}
|
||||
columns={columns}
|
||||
idAccessor="uid"
|
||||
noRecordsText="暂无数据"
|
||||
totalRecords={totalItems}
|
||||
recordsPerPage={pageSize}
|
||||
|
||||
@@ -107,7 +107,12 @@ export default function CreateModal({ opened, onCloseAction }: ComponentProps) {
|
||||
radius="xs"
|
||||
withAsterisk
|
||||
searchable
|
||||
data={finalUserOpts}
|
||||
data={finalUserOpts.map((item) => {
|
||||
return {
|
||||
label: item.label.toString(),
|
||||
value: item.value.toString(),
|
||||
}
|
||||
})}
|
||||
{...form.getInputProps("leader_uid")}
|
||||
/>
|
||||
<Select
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useEffect } from "react"
|
||||
export default function Home() {
|
||||
const router = useRouter()
|
||||
useEffect(() => {
|
||||
router.push("/management")
|
||||
router.push("/entry")
|
||||
}, [router])
|
||||
return <></>
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"use client"
|
||||
|
||||
import { useUserStore } from "@/app/store/user"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useEffect } from "react"
|
||||
import { useUserStore } from "@/app/store/user"
|
||||
|
||||
export function InfoCheck() {
|
||||
const pathname = usePathname()
|
||||
|
||||
@@ -3,11 +3,11 @@ import { BASE_LABEL_API } from "../const"
|
||||
import { Organization, User } from "./typing"
|
||||
|
||||
// 获取用户列表
|
||||
export const getUserList = (params: User.ListRequest) => {
|
||||
export const getUserList = (data: User.ListRequest) => {
|
||||
return httpFetch<User.ListResponse>({
|
||||
url: BASE_LABEL_API + "/api/v1/label_server/user/list",
|
||||
method: "GET",
|
||||
data: params,
|
||||
method: "POST",
|
||||
body: JSON.stringify({ ...data, tenant: "cowarobot" }),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { useCallback, useEffect } from "react"
|
||||
import { DigitalIcon } from "../resource/icons/digital"
|
||||
import { APP, PLATFORM, TENANT } from "@/components/login/libs/common"
|
||||
import { useLoginStore } from "@/components/login/store"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { APP, PLATFORM, TENANT } from "@/components/login/libs/common"
|
||||
import { useCallback, useEffect } from "react"
|
||||
import { fetchFeishuLogin } from "../api"
|
||||
import { DigitalIcon } from "../resource/icons/digital"
|
||||
import { APP_ID, APP_SECRECT } from "./util"
|
||||
import { fetchFeishuLogin, getUserPermission } from "../api"
|
||||
import { usePermissionStore } from "@/components/label/store/auth"
|
||||
|
||||
const HeaderIcon = DigitalIcon
|
||||
|
||||
@@ -22,8 +21,6 @@ const FeishuAutoLogin = ({ useUserStore }: { useUserStore: any }) => {
|
||||
const { setUserInfo, refreshToken } = useUserStore()
|
||||
const router = useRouter()
|
||||
|
||||
const { setUserPermissionInfo } = usePermissionStore()
|
||||
|
||||
const autoLogin = useCallback(
|
||||
(
|
||||
fingerprint: any,
|
||||
@@ -63,13 +60,6 @@ const FeishuAutoLogin = ({ useUserStore }: { useUserStore: any }) => {
|
||||
access_token: info.access_token || "",
|
||||
refresh_token: info.refresh_token || "",
|
||||
})
|
||||
const { message: permissionRes } = await getUserPermission()
|
||||
const { uid, name } = permissionRes
|
||||
setUserPermissionInfo({
|
||||
user_id: uid,
|
||||
user_name: name,
|
||||
detailInfo: permissionRes,
|
||||
})
|
||||
window.location.href = "/"
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
@@ -82,7 +72,7 @@ const FeishuAutoLogin = ({ useUserStore }: { useUserStore: any }) => {
|
||||
})
|
||||
})
|
||||
},
|
||||
[refreshToken, setUserPermissionInfo]
|
||||
[refreshToken]
|
||||
)
|
||||
|
||||
const isFeishu = useCallback(() => !!(window.h5sdk && window.tt), [])
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import { useCallback, useEffect, useState } from "react"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { Flex } from "@mantine/core"
|
||||
import { useLoginStore } from "@/components/login/store"
|
||||
import { APP_ID, APP_SECRECT, qr_load, qr_login } from "./util"
|
||||
import {
|
||||
APP,
|
||||
PLATFORM,
|
||||
TENANT,
|
||||
getQueryVariable,
|
||||
} from "@/components/login/libs/common"
|
||||
import { fetchFeishuLogin, getUserPermission } from "../api"
|
||||
import { usePermissionStore } from "@/components/label/store/auth"
|
||||
import { useLoginStore } from "@/components/login/store"
|
||||
import { Flex } from "@mantine/core"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { useCallback, useEffect, useState } from "react"
|
||||
import { fetchFeishuLogin } from "../api"
|
||||
import { APP_ID, APP_SECRECT, qr_load, qr_login } from "./util"
|
||||
|
||||
const QrLogin = ({ useUserStore }: { useUserStore: any }) => {
|
||||
const fingerprint = useLoginStore.getState().fingerprint
|
||||
@@ -39,8 +38,6 @@ const QrLogin = ({ useUserStore }: { useUserStore: any }) => {
|
||||
|
||||
const { setUserInfo, refreshToken } = useUserStore()
|
||||
|
||||
const { setUserPermissionInfo } = usePermissionStore()
|
||||
|
||||
const feishuLogin = useCallback(async () => {
|
||||
try {
|
||||
const params = {
|
||||
@@ -60,24 +57,11 @@ const QrLogin = ({ useUserStore }: { useUserStore: any }) => {
|
||||
access_token: info.access_token || "",
|
||||
refresh_token: info.refresh_token || "",
|
||||
})
|
||||
const { message: permissionRes } = await getUserPermission()
|
||||
const { uid, name } = permissionRes
|
||||
setUserPermissionInfo({
|
||||
user_id: uid,
|
||||
user_name: name,
|
||||
detailInfo: permissionRes,
|
||||
})
|
||||
window.location.href = "/"
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}, [
|
||||
fingerprint,
|
||||
redirect_url,
|
||||
refreshToken,
|
||||
setUserInfo,
|
||||
setUserPermissionInfo,
|
||||
])
|
||||
}, [fingerprint, redirect_url, refreshToken, setUserInfo])
|
||||
|
||||
useEffect(() => {
|
||||
if (times === 1) {
|
||||
|
||||
@@ -26,12 +26,7 @@ import {
|
||||
import { useForm } from "@mantine/form"
|
||||
import { useDisclosure } from "@mantine/hooks"
|
||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||
import {
|
||||
getUserPermission,
|
||||
getVerifyCode,
|
||||
passwdLogin,
|
||||
verificationLogin,
|
||||
} from "./api"
|
||||
import { getVerifyCode, passwdLogin, verificationLogin } from "./api"
|
||||
import QrLogin from "./feishu/qr-login"
|
||||
import { APP, PLATFORM, TENANT } from "./libs/common"
|
||||
import { DigitalIcon } from "./resource/icons/digital"
|
||||
@@ -44,7 +39,6 @@ import LightBgImage from "./resource/images/light-login-bg.png"
|
||||
import loginBg2Dark from "./resource/images/login-bg2-dark.png"
|
||||
import loginBg2Light from "./resource/images/login-bg2-light.png"
|
||||
import LogoDigImage from "./resource/images/logo-dig.png"
|
||||
import { usePermissionStore } from "../label/store/auth"
|
||||
|
||||
const HeaderIcon = DigitalIcon
|
||||
|
||||
@@ -56,8 +50,6 @@ export default function LoginPage({ useUserStore }: { useUserStore: any }) {
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const { setUserPermissionInfo } = usePermissionStore()
|
||||
|
||||
const [isClient, setIsClient] = useState(false)
|
||||
useEffect(() => {
|
||||
setIsClient(true)
|
||||
@@ -212,13 +204,6 @@ export default function LoginPage({ useUserStore }: { useUserStore: any }) {
|
||||
access_token: info.access_token || "",
|
||||
refresh_token: info.refresh_token || "",
|
||||
})
|
||||
const { message: permissionRes } = await getUserPermission()
|
||||
const { uid, name } = permissionRes
|
||||
setUserPermissionInfo({
|
||||
user_id: uid,
|
||||
user_name: name,
|
||||
detailInfo: permissionRes,
|
||||
})
|
||||
window.location.href = "/"
|
||||
} catch (error) {
|
||||
if (error) {
|
||||
@@ -310,13 +295,6 @@ export default function LoginPage({ useUserStore }: { useUserStore: any }) {
|
||||
access_token: info.access_token || "",
|
||||
refresh_token: info.refresh_token || "",
|
||||
})
|
||||
const { message: permissionRes } = await getUserPermission()
|
||||
const { uid, name } = permissionRes
|
||||
setUserPermissionInfo({
|
||||
user_id: uid,
|
||||
user_name: name,
|
||||
detailInfo: permissionRes,
|
||||
})
|
||||
window.location.href = "/"
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "登录失败,请重试"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server"
|
||||
import { cookies } from "next/headers"
|
||||
import { NextRequest, NextResponse } from "next/server"
|
||||
|
||||
const publicRoutes = ["/login", "/"]
|
||||
|
||||
@@ -35,22 +35,24 @@ export default async function middleware(req: NextRequest) {
|
||||
console.log("Lark environment detected, redirecting with auto login")
|
||||
return NextResponse.redirect(
|
||||
new URL(
|
||||
`${process.env.NEXT_PUBLIC_BASE_PATH}/login?auto=true`,
|
||||
// `${process.env.NEXT_PUBLIC_BASE_PATH}/login?auto=true`,
|
||||
`/login?auto=true`,
|
||||
req.nextUrl
|
||||
)
|
||||
)
|
||||
} else {
|
||||
return NextResponse.redirect(
|
||||
new URL(`${process.env.NEXT_PUBLIC_BASE_PATH}/login`, req.nextUrl)
|
||||
// new URL(`${process.env.NEXT_PUBLIC_BASE_PATH}/login`, req.nextUrl)
|
||||
new URL(`/login`, req.nextUrl)
|
||||
)
|
||||
}
|
||||
}
|
||||
// 5. Redirect to /dashboard if the user is authenticated
|
||||
if (isPublicRoute && session && !path.startsWith("/management")) {
|
||||
return NextResponse.redirect(
|
||||
new URL(`${process.env.NEXT_PUBLIC_BASE_PATH}/management`, req.nextUrl)
|
||||
)
|
||||
}
|
||||
// if (isPublicRoute && session && !path.startsWith("/management")) {
|
||||
// return NextResponse.redirect(
|
||||
// new URL(`${process.env.NEXT_PUBLIC_BASE_PATH}/management`, req.nextUrl)
|
||||
// )
|
||||
// }
|
||||
|
||||
return NextResponse.next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user