From 6d33e0f198185cc51d6d21650ea159044ad5e36f Mon Sep 17 00:00:00 2001 From: lk Date: Fri, 13 Sep 2024 16:46:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=20=E4=BF=AE=E6=94=B9=20=20?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=20=E6=8E=A5=E5=8F=A3=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/use/login/index.tsx | 5 +- src/pages/use/password/retrieve.tsx | 73 ++++++++++-- src/pages/use/register/index.tsx | 225 ++++++++++++++++++------------------ src/request.ts | 7 +- src/service/system.ts | 5 +- src/store/system/user.ts | 42 ++++--- vite.config.ts | 2 +- 7 files changed, 215 insertions(+), 144 deletions(-) diff --git a/src/pages/use/login/index.tsx b/src/pages/use/login/index.tsx index a17945d..c81b165 100644 --- a/src/pages/use/login/index.tsx +++ b/src/pages/use/login/index.tsx @@ -12,6 +12,7 @@ import { upLoginAtom, } from "@/store/system/user.ts"; import React, { memo, useEffect, useLayoutEffect, useState } from "react"; +import systemServ from "@/service/system.ts"; const { Title, Text, Link } = Typography; const { TabPane } = Tabs; @@ -21,7 +22,7 @@ const Login = memo(() => { const [emailform] = Form.useForm(); const [telegramform] = Form.useForm(); const { mutate: upLoginFun } = useAtomValue(upLoginAtom); - const { mutate: emailCodeMutate } = useAtomValue(emailCodeAtom); + const [emailCodeData, setEmailCodeData] = useState({}); const { mutate: emailLoginMutate } = useAtomValue(emailLoginAtom); const { mutate: telegramCodeMutate } = useAtomValue(telegramCodeAtom); const { mutate: telegramLoginMutate } = useAtomValue(telegramLoginAtom); @@ -35,7 +36,7 @@ const Login = memo(() => { const email = emailform.getFieldValue("email"); setCountdown(10); setIsButtonDisabled(true); - emailCodeMutate({ is_register: false, email }); + setEmailCodeData(systemServ.emailCode({ is_register: false, email })); }; const emailhandleSubmit = (values: any) => { emailLoginMutate(values); diff --git a/src/pages/use/password/retrieve.tsx b/src/pages/use/password/retrieve.tsx index 7a6a32a..31a4baa 100644 --- a/src/pages/use/password/retrieve.tsx +++ b/src/pages/use/password/retrieve.tsx @@ -1,32 +1,73 @@ -import { Layout, Input, Button, Typography, Row, Col, Form } from "antd"; +import {Layout, Input, Button, Typography, Row, Col, Form, message, Modal} from "antd"; import { LockOutlined, MailOutlined, SecurityScanOutlined } from "@ant-design/icons"; import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { useAtomValue } from "jotai"; import React, { memo, useEffect, useState } from "react"; import { emailCodeAtom } from "@/store/system/user.ts"; -import {passwordRules} from "@/pages/use/useTools.tsx"; +import { passwordRules } from "@/pages/use/useTools.tsx"; +import { useAtom } from "jotai/index"; +import systemServ from "@/service/system.ts"; +import { setToken } from "@/store/system.ts"; const { Title, Text, Link } = Typography; const PwdRetrieve = memo(() => { const navigate = useNavigate(); const [retrieveForm] = Form.useForm(); - const { mutate: emailCodeMutate } = useAtomValue(emailCodeAtom); + const [emailCodeData, setEmailCodeData] = useState({}); + const [pwdRetrieveData, setPwdRetrieveData] = useState({}); - const handleRetrieveSubmit = (values: any) => { - console.log(values); - // 调用找回密码API + const handleRetrieveSubmit = async (values: any) => { + const param = { + email: values.email, + password: values.password, + code: values.code, + }; + const result = await systemServ.pwdRetrieve(param); + setPwdRetrieveData(result); }; - const handleGetCode = () => { + const handleGetCode = async () => { const email = retrieveForm.getFieldValue("email"); - setCountdown(10); - setIsButtonDisabled(true); - emailCodeMutate({ email }); + const result = await systemServ.emailCode({ is_register: false, email }); + setEmailCodeData(result); }; const [countdown, setCountdown] = useState(0); const [isButtonDisabled, setIsButtonDisabled] = useState(false); + + + const [gotoLoginModalVisible, SetGotoLoginModalVisible] = useState(false); + + const showGotoLoginModal= () => { + SetGotoLoginModalVisible(true); + }; + + const gotoLoginModalHandleOk = () => { + SetGotoLoginModalVisible(false); + navigate({ to: "/login" }); + }; + + // const gotoLoginModalHandleCancel = () => { + // SetGotoLoginModalVisible(false); + // }; + // + + + useEffect(() => { + if ((emailCodeData as any)?.code === 0) { + setCountdown(10); + setIsButtonDisabled(true); + } + }, [emailCodeData]); + + useEffect(() => { + if ((pwdRetrieveData as any)?.code === 0) { + message.success("密码找回成功"); + showGotoLoginModal(); + } + }, [pwdRetrieveData, navigate]); + useEffect(() => { let timer: number; if (countdown > 0) { @@ -124,6 +165,18 @@ const PwdRetrieve = memo(() => { + + 确认 + , + ]} + > +

密码修改成功,返回登录。

+
); }); diff --git a/src/pages/use/register/index.tsx b/src/pages/use/register/index.tsx index 7535355..c8438fa 100644 --- a/src/pages/use/register/index.tsx +++ b/src/pages/use/register/index.tsx @@ -1,39 +1,38 @@ import { Layout, Input, Button, Typography, Row, Col, Form } from "antd"; -import { LockOutlined, MailOutlined, SecurityScanOutlined } from "@ant-design/icons"; +import {LockOutlined, MailOutlined, SecurityScanOutlined, UserOutlined} from "@ant-design/icons"; import { createFileRoute, useNavigate } from "@tanstack/react-router"; -import { useAtom, useAtomValue } from "jotai"; +import { useAtomValue } from "jotai"; import React, { memo, useEffect, useState } from "react"; -import { emailCodeAtom, emailRegisterAtom } from "@/store/system/user.ts"; +import { emailRegisterAtom } from "@/store/system/user.ts"; import { passwordRules } from "@/pages/use/useTools"; +import systemServ from "@/service/system.ts"; const { Title, Text, Link } = Typography; const Register = memo(() => { const navigate = useNavigate(); const [registerForm] = Form.useForm(); const { mutate: emailRegisterMutate } = useAtomValue(emailRegisterAtom); - const { mutateAsync: emailCodeMutate, data: emailData } = useAtomValue(emailCodeAtom); - //const [{ mutate: emailCodeMutate, data: emailData }] = useAtom(emailCodeAtom); - //const [, mutate: emailCodeMutate] = useAtom(emailCodeAtom); + const [countdown, setCountdown] = useState(10); + const [emailCodeData, setEmailCodeData] = useState({}); + const [isButtonDisabled, setIsButtonDisabled] = useState(false); + const getEmailCode = () => { const email = registerForm.getFieldValue("email"); setCountdown(10); setIsButtonDisabled(true); - const data = emailCodeMutate({ is_register: true, email }); - console.log(data); + setEmailCodeData(systemServ.emailCode({ is_register: true, email })); }; + const emailRegisterSubmit = (values: any) => { emailRegisterMutate({ email: values.email, password: values.password, code: values.code }); }; - const [countdown, setCountdown] = useState(0); - const [isButtonDisabled, setIsButtonDisabled] = useState(false); - useEffect(() => { - if ((emailData as any)?.countdown === -1) { + if ((emailCodeData as any)?.countdown === -1) { setCountdown(0); setIsButtonDisabled(false); } - }, [emailData]); + }, [emailCodeData]); useEffect(() => { let timer: number; @@ -53,111 +52,111 @@ const Register = memo(() => { }, []); return ( - - - - - - 向量检索服务免费试用 - 免费试用向量检索服务,玩转大模型生成式检索 -
- 查看详情 > - - -
- - } - addonAfter={ - - } - /> - - - } autoComplete="off" /> - - - } autoComplete="off" /> - - ({ - validator(_, value) { - if (!value || getFieldValue("password") === value) { - return Promise.resolve(); - } - return Promise.reject(new Error("两次输入的密码不一致")); - }, - }), - ]} - > - } autoComplete="off" /> - - -
-
- navigate({ to: "/login" })} + > + + + + + 向量检索服务免费试用 + 免费试用向量检索服务,玩转大模型生成式检索 +
+ 查看详情 > + + +
+ + } + addonAfter={ + + } + /> + + + } autoComplete="off" /> + + + } autoComplete="off" /> + + ({ + validator(_, value) { + if (!value || getFieldValue("password") === value) { + return Promise.resolve(); + } + return Promise.reject(new Error("两次输入的密码不一致")); + }, + }), + ]} + > + } autoComplete="off" /> + + +
+
+ navigate({ to: "/login" })} > 登录 -
- - navigate({ to: "/login" })}>返回登录 - - -
- -
- +
+ + navigate({ to: "/login" })}>返回登录 + + +
+ +
+
); }); diff --git a/src/request.ts b/src/request.ts index 8e282d5..2da99bf 100644 --- a/src/request.ts +++ b/src/request.ts @@ -54,7 +54,12 @@ axiosInstance.interceptors.response.use( case 0: case 200: //login - if (response.config.url?.includes("/sys/login")) { + if ( + response.config.url?.includes("/sys/login") || + response.config.url?.includes("/sys/email/reg") || + response.config.url?.includes("/sys/email/login") || + response.config.url?.includes("/sys/login/telegram") + ) { setToken(result.data.token); const search = new URLSearchParams(window.location.search); // eslint-disable-next-line no-case-declarations diff --git a/src/service/system.ts b/src/service/system.ts index a6b4373..e2f57ca 100644 --- a/src/service/system.ts +++ b/src/service/system.ts @@ -21,7 +21,7 @@ const systemServ = { }, emailLogin: (data: any) => { - return request.post("/sys/login/email", data); + return request.post("/sys/email/login", data); }, emailRegister: (data: any) => { return request.post("/sys/email/reg", data); @@ -35,6 +35,9 @@ const systemServ = { telegramLogin: (data: any) => { return request.post("/sys/login/telegram", data); }, + pwdRetrieve: (data: any) => { + return request.post("/sys/email/pws", data); + }, diff --git a/src/store/system/user.ts b/src/store/system/user.ts index 1726cfa..0898961 100644 --- a/src/store/system/user.ts +++ b/src/store/system/user.ts @@ -40,26 +40,31 @@ export const upLoginAtom = atomWithMutation((get) => ({ }, onSuccess: (res) => { message.success(t("login.success")); - get(userMenuDataAtom).refetch().then(); + // setToken(res.data.token); + // get(userMenuDataAtom).refetch().then(); return res.data; }, retry: false, })); -export const emailCodeAtom = atomWithMutation((get) => ({ - mutationKey: ["emailCode"], - mutationFn: async (params) => { - return await systemServ.emailCode(params); - }, - onSuccess: (res) => { - if(res.data.countdown===-1){ - message.error(res.message); - } - return res.data; - }, - retry: false, -})); +export const emailCodeAtom = (params) =>atomWithQuery(() => { + return { + queryKey: ["emailCode",params], + queryFn: async () => { + return await systemServ.emailCode(params); + }, + select: (data) => { + return data.data; + }, + }; +}); + + + + + + export const emailLoginAtom = atomWithMutation((get) => ({ mutationKey: ["emailLogin"], mutationFn: async (params) => { @@ -67,18 +72,23 @@ export const emailLoginAtom = atomWithMutation((get) => ({ }, onSuccess: (res) => { message.success(t("login.success")); - // console.log('login success', res) return res.data; }, retry: false, })); + + + + + export const emailRegisterAtom = atomWithMutation((get) => ({ mutationKey: ["emailRegister"], mutationFn: async (params) => { return await systemServ.emailRegister(params); }, onSuccess: (res) => { - // console.log('login success', res) + // setToken(res.data.token); + // window.location.href = "/"; return res.data; }, retry: false, diff --git a/vite.config.ts b/vite.config.ts index d23ff6e..d5b5925 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -14,7 +14,7 @@ const proxyMap = { //'/api/v1/certold': 'http://192.168.31.41:8000', "/api/v1/cert": "http://127.0.0.1:8000", //'/api/v1/cert': 'http://192.168.31.41:8000', - "/api/v1/sys": "http://192.168.31.41:8686/", + //"/api/v1/sys": "http://192.168.31.41:8686/", } as Record; const proxyConfig = Object.keys(proxyMap).reduce(