diff --git a/web_ui/src/app/infra/api/api-types/index.ts b/web_ui/src/app/infra/api/api-types/index.ts index a68c022f..69aa4515 100644 --- a/web_ui/src/app/infra/api/api-types/index.ts +++ b/web_ui/src/app/infra/api/api-types/index.ts @@ -46,8 +46,8 @@ export interface LLMModel { extra_args: object; api_keys: string[]; abilities: string[]; - created_at: string; - updated_at: string; + // created_at: string; + // updated_at: string; } export interface ApiRespPipelines { diff --git a/web_ui/src/app/infra/http/HttpClient.ts b/web_ui/src/app/infra/http/HttpClient.ts index f02bbff2..e8d51237 100644 --- a/web_ui/src/app/infra/http/HttpClient.ts +++ b/web_ui/src/app/infra/http/HttpClient.ts @@ -62,7 +62,7 @@ class HttpClient { // 同步获取Session private getSessionSync() { // NOT IMPLEMENT - return "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoicm9ja2NoaW5xQGdtYWlsLmNvbSIsImlzcyI6IkxhbmdCb3QtY29tbXVuaXR5IiwiZXhwIjoyMzUwNDk1NTQ3fQ.d6r0lNGud1OecOLMM-ADDDwiABmek3hkMIFH7ZBkaX4" + return localStorage.getItem("token") } // 拦截器配置 @@ -323,7 +323,7 @@ class HttpClient { } // ============ User API ============ - public checkIfInited(): Promise { + public checkIfInited(): Promise<{initialized: boolean}> { return this.get('/api/v1/user/init') } @@ -340,4 +340,4 @@ class HttpClient { } } -export const httpClient = new HttpClient() +export const httpClient = new HttpClient("https://version-4.langbot.dev") diff --git a/web_ui/src/app/login/login.module.css b/web_ui/src/app/login/login.module.css index e8d2acbf..b6435980 100644 --- a/web_ui/src/app/login/login.module.css +++ b/web_ui/src/app/login/login.module.css @@ -9,7 +9,7 @@ .login { display: flex; - width: 80%; + width: 30%; height: 80vh; background-color: white; border-radius: 16px; @@ -26,14 +26,6 @@ padding: 2rem; } -.right { - flex: 1.5; - background-color: #f9f9f9; - position: relative; - overflow: hidden; - border-top-right-radius: 16px; - border-bottom-right-radius: 16px; -} .loginForm { width: 100%; @@ -76,6 +68,10 @@ justify-content: space-between; align-items: center; margin-bottom: 1rem; + + .forgetPassword { + margin-right: 1rem; + } } /* 修改Logo样式,调整位置确保正确对齐 */ diff --git a/web_ui/src/app/login/page.tsx b/web_ui/src/app/login/page.tsx index cf225989..c40274ee 100644 --- a/web_ui/src/app/login/page.tsx +++ b/web_ui/src/app/login/page.tsx @@ -1,12 +1,62 @@ 'use client'; import { Button, Input, Form, Checkbox, Divider } from 'antd'; -import { GoogleOutlined, AppleOutlined, LockOutlined, UserOutlined } from '@ant-design/icons'; +import {GoogleOutlined, AppleOutlined, LockOutlined, UserOutlined, QqCircleFilled, QqOutlined} from '@ant-design/icons'; import styles from './login.module.css'; -import { useState } from 'react'; +import {useEffect, useState} from 'react'; + + +import {httpClient} from "@/app/infra/http/HttpClient"; +import '@ant-design/v5-patch-for-react-19'; +import {useRouter} from "next/navigation"; + export default function Home() { - const [form] = Form.useForm(); + const router = useRouter(); + const [form] = Form.useForm(); const [rememberMe, setRememberMe] = useState(false); + const [isRegisterMode, setIsRegisterMode] = useState(false); + const [isInitialized, setIsInitialized] = useState(false) + + useEffect(() => { + getIsInitialized() + }, []) + + + // 检查是否为首次启动项目,只为首次启动的用户提供注册资格 + function getIsInitialized() { + httpClient.checkIfInited().then(res => { + setIsInitialized(res.initialized) + }).catch(err => { + console.log("error at getIsInitialized: ", err) + }) + } + + function handleFormSubmit(formField: LoginField) { + if (isRegisterMode) { + handleRegister(formField.email, formField.password); + } else { + handleLogin(formField.email, formField.password) + } + } + + function handleRegister(username: string, password: string) { + httpClient.initUser(username, password).then(res => { + console.log("init user success: ", res) + }).catch(err => { + console.log("init user error: ", err) + }) + } + + function handleLogin(username: string, password: string) { + httpClient.authUser(username, password).then(res => { + localStorage.setItem("token", res.token) + console.log("login success: ", res) + router.push("/home") + }).catch(err => { + console.log("login error: ", err) + }) + } + return ( // 使用 Ant Design 的组件库,使用 antd 的样式 @@ -18,8 +68,21 @@ export default function Home() { {/* left 为注册的表单,需要填入的内容有:邮箱,密码 */}
-

欢迎回来

-
+ { + isRegisterMode && +

注册 LangBot 账号

+ } + { + !isRegisterMode && +

欢迎回到 LangBot

+ } + { + handleFormSubmit(values) + }} + > 30天内自动登录 - 忘记密码? + + 忘记密码? + { + !isRegisterMode && + { + setIsRegisterMode(true) + event.preventDefault() + }} + >去注册? + } + { + isRegisterMode && + { + setIsRegisterMode(false) + event.preventDefault() + }} + >去登录 + } +
- +
@@ -68,6 +164,7 @@ export default function Home() { className={styles.socialButton} icon={} size="large" + disabled={true} > 使用谷歌账号登录 @@ -76,37 +173,22 @@ export default function Home() {
- {/* right 为左侧布局,显示的是应用截图,测试阶段使用 picsum.photos 代替 */} -
- 应用预览 - {/* 在右上角添加logo */} -
- Logo -
-
); } + +interface LoginField { + email: string; + password: string; +} \ No newline at end of file