Skip to content

Commit da11d3b

Browse files
authored
feat: 修复头像问题,调整鉴权页面,更新后端接口 (#139)
* feat: 添加github链接 * fix: 修复头像问题 * feat: 修改鉴权页面 * feat: 减少不必要请求 * fix: 修复css
1 parent 4aa82d7 commit da11d3b

File tree

11 files changed

+170
-158
lines changed

11 files changed

+170
-158
lines changed

.env.development

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
NEXT_PUBLIC_SERVER_URL=http://localhost:8080
2-
NEXT_PUBLIC_WS_URL=ws://localhost:8080
1+
NEXT_PUBLIC_SERVER_URL=http://1.117.152.40:8080
2+
NEXT_PUBLIC_WS_URL=ws://1.117.152.40:8080
33

44
MODEL_API_BASE_URL=https://dashscope.aliyuncs.com/api/v1/apps/
55

.env.production

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# TODO 生产环境域名
21
NEXT_PUBLIC_SERVER_URL=http://1.117.152.40:8080
32
NEXT_PUBLIC_WS_URL=ws://1.117.152.40:8080
43

src/app/cooperation/layout.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,35 @@
1+
'use client';
2+
3+
import { useEffect } from 'react';
4+
import { usePathname, useRouter } from 'next/navigation';
5+
6+
import { PATHS, STORAGE_KEY_AUTH } from '@/utils/constants';
7+
import { useAuthStore } from '@/store/authStore';
8+
19
export default function CooperationLayout({
210
children,
311
}: Readonly<{
412
children: React.ReactNode;
513
}>) {
14+
const { setAuth, getAuth } = useAuthStore();
15+
const router = useRouter();
16+
const pathname = usePathname();
17+
useEffect(() => {
18+
let auth = getAuth();
19+
20+
if (!auth.access_token) {
21+
const storagedAuth = localStorage.getItem(STORAGE_KEY_AUTH);
22+
23+
if (storagedAuth) {
24+
auth = JSON.parse(storagedAuth);
25+
setAuth(auth);
26+
}
27+
}
28+
29+
if (!auth.access_token) {
30+
router.push(`${PATHS.LOGIN}?redirect=${pathname}`);
31+
}
32+
}, [pathname]);
33+
634
return <div className=" flex w-[100vw] h-[100vh] overflow-hidden">{children}</div>;
735
}

src/app/edit/[projectId]/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const Page: React.FC<{ children: React.ReactNode; params: any }> = ({ children,
157157
</div>
158158
<div className=" w-full flex flex-1 overflow-hidden">
159159
{/* 侧边栏 */}
160-
<div className="bg-[#2e3138] text-gray-400 w-[2.9vw] flex flex-col justify-between items-center py-4">
160+
<div className="bg-[#2e3138] text-gray-400 w-[2.9vw] flex flex-col justify-between items-center py-4 z-50">
161161
<div className="flex flex-col items-center space-y-6">
162162
<Link href={`/edit/${params.projectId}/file`}>
163163
<FaFileAlt
@@ -226,7 +226,7 @@ const Page: React.FC<{ children: React.ReactNode; params: any }> = ({ children,
226226
</Panel>
227227
<ResizeHandle className=" w-[3px] bg-transparent" />
228228
<Panel className="bg-[#202327]" minSize={1} defaultSize={35}>
229-
<div className=" h-full">
229+
<div className=" h-full z-[999]">
230230
<Preview />
231231
</div>
232232
</Panel>

src/app/layout.tsx

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
'use client';
22

33
import { Inter } from 'next/font/google';
4-
import { useEffect } from 'react';
5-
import { usePathname, useRouter } from 'next/navigation';
64

75
import NextProcessLoader from '@/components/nextTopLoader';
8-
import { PATHS, PATHS_SKIPPED_AUTH, STORAGE_KEY_AUTH } from '@/utils/constants';
9-
import { useAuthStore } from '@/store/authStore';
106

117
import './globals.css';
128
import './xterm.css';
@@ -18,34 +14,6 @@ export default function RootLayout({
1814
}: Readonly<{
1915
children: React.ReactNode;
2016
}>) {
21-
const { setAuth, getAuth } = useAuthStore();
22-
const router = useRouter();
23-
const pathname = usePathname();
24-
25-
useEffect(() => {
26-
// 首先,从zustand获取登录信息
27-
let auth = getAuth();
28-
29-
// TODO 使用localstorage存放登录信息不合适
30-
// 如果zustand中没有登录信息,则从localStorage中读取
31-
if (!auth.access_token) {
32-
const storagedAuth = localStorage.getItem(STORAGE_KEY_AUTH);
33-
34-
if (storagedAuth) {
35-
// 将localStorage中的登录信息同步到zustand
36-
auth = JSON.parse(storagedAuth);
37-
38-
setAuth(auth);
39-
}
40-
}
41-
42-
if (!PATHS_SKIPPED_AUTH.includes(pathname) && !auth.access_token) {
43-
// 当前路由需登录但未登录时,跳转到登录页
44-
// FIXME: 跳转时,会短暂显示目标页,再跳转到登录页
45-
router.push(`${PATHS.LOGIN}?redirect=${pathname}`);
46-
}
47-
}, [pathname]);
48-
4917
return (
5018
<html lang="en" suppressHydrationWarning>
5119
<body className={inter.className}>

src/components/cooperation/avatarList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export const AnimatedTooltip = ({
66
items,
77
}: {
88
items: {
9-
id: number;
9+
id: string;
1010
name: string;
1111
designation: string;
1212
image: string;
1313
}[];
1414
}) => {
15-
const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);
15+
const [hoveredIndex, setHoveredIndex] = useState<string | null>(null);
1616

1717
return (
1818
<div className="flex flex-row gap-2">

0 commit comments

Comments
 (0)