From 51cb4a47cc6dfed5d1d6acfcf9c5820374de4bfb Mon Sep 17 00:00:00 2001 From: 1708-huayu <57060237+1708-huayu@users.noreply.github.com> Date: Thu, 21 Nov 2024 22:48:47 +0800 Subject: [PATCH] feat:login --- .env.development | 4 +++ .env.production | 1 + src/app/login/page.tsx | 56 ++++++++++++++++++++--------------- src/lib/login/definitions.ts | 6 ++++ src/lib/placeholder-data.js | 14 --------- src/lib/task/project/data.tsx | 24 +++++++-------- src/utils/axiosReq.ts | 18 +++++++++++ 7 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 .env.development create mode 100644 .env.production create mode 100644 src/lib/login/definitions.ts delete mode 100644 src/lib/placeholder-data.js create mode 100644 src/utils/axiosReq.ts diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..4ea0c46 --- /dev/null +++ b/.env.development @@ -0,0 +1,4 @@ +# 前缀为NEXT_PUBLIC_才可以被浏览器使用 +NEXT_PUBLIC_TODO_REQUEST_URL=http://localhost:8090 +NEXT_PUBLIC_SECURITY_REQUEST_URL=http://localhost:8091 +NEXT_PUBLIC_PRIVATE_KEY= \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..4691b0d --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +NEXT_PUBLIC_TODO_REQUEST_URL=http://taskmanagerserver.com:8090 \ No newline at end of file diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 32d863d..47475de 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -14,9 +14,11 @@ import { ProFormCheckbox, ProFormText, } from '@ant-design/pro-components'; -import { Button, Divider, Space, Tabs, message, theme } from 'antd'; -import type { CSSProperties } from 'react'; -import { useState } from 'react'; +import {Button, Divider, Space, Tabs, message, theme} from 'antd'; +import type {CSSProperties} from 'react'; +import {useState} from 'react'; +import {LoginObject} from "@/lib/login/definitions"; +import {httpReq} from "@/utils/axiosReq"; type LoginType = 'phone' | 'account'; @@ -29,7 +31,7 @@ const iconStyles: CSSProperties = { const Page = () => { const [loginType, setLoginType] = useState('phone'); - const { token } = theme.useToken(); + const {token} = theme.useToken(); return (
{ // title: '活动标题,可配置图片', // subTitle: '活动介绍说明文字', // action: ( + // action: ( // // ), }} + onFinish={(formData:LoginObject)=>{ + console.log("登录信息:"+formData.username+";"+formData.password) + httpReq.post(process.env.NEXT_PUBLIC_SECURITY_REQUEST_URL+"/stateless/login/username",{ + username: formData.username, + password: formData.password + }).then(response=>{ + console.log(response) + response.status; + response.data; + }) + }} actions={ -
+ flexDirection: 'column',}}> - - 其他登录方式 - + + 其他登录方式 +
{ borderRadius: '50%', }} > - +
{ borderRadius: '50%', }} > - +
{ borderRadius: '50%', }} > - +
@@ -143,8 +151,8 @@ const Page = () => { activeKey={loginType} onChange={(activeKey) => setLoginType(activeKey as LoginType)} > - - + + {loginType === 'account' && ( <> @@ -278,7 +286,7 @@ const Page = () => { export default () => { return ( - + ); }; \ No newline at end of file diff --git a/src/lib/login/definitions.ts b/src/lib/login/definitions.ts new file mode 100644 index 0000000..2166160 --- /dev/null +++ b/src/lib/login/definitions.ts @@ -0,0 +1,6 @@ +export type LoginObject={ + username:string; + password:string; + mobile:string; + captcha:string; +} \ No newline at end of file diff --git a/src/lib/placeholder-data.js b/src/lib/placeholder-data.js deleted file mode 100644 index d70e728..0000000 --- a/src/lib/placeholder-data.js +++ /dev/null @@ -1,14 +0,0 @@ -const invoices = [ - { - customer_id: customers[0].id, - amount: 15795, - status: 'pending', - date: '2022-12-06', - }, - { - customer_id: customers[1].id, - amount: 20348, - status: 'pending', - date: '2022-11-14', - }, -]; \ No newline at end of file diff --git a/src/lib/task/project/data.tsx b/src/lib/task/project/data.tsx index 59b68da..a757137 100644 --- a/src/lib/task/project/data.tsx +++ b/src/lib/task/project/data.tsx @@ -1,13 +1,13 @@ import {unstable_noStore as noStore} from 'next/cache'; -import axios, {AxiosResponse} from "axios"; +import {AxiosResponse} from "axios"; +import {httpReq} from "@/utils/axiosReq"; import {DataType, DictType, ResponseVO, ResultPage} from "@/lib/definitions"; export async function getTaskTreeResult(requestParam:string): Promise>> { noStore(); try { - // 使用 Axios 发送 POST 请求获取数据 - const response: AxiosResponse>> = await axios.get( - 'http://taskmanagerserver.com:8090/search/task_message_tree?search='+encodeURIComponent(requestParam)); + const response: AxiosResponse>> = await httpReq.get( + process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/search/task_message_tree?search='+encodeURIComponent(requestParam)); // 从响应中提取数据并返回 console.log("response.data",response.data) return response.data; @@ -22,8 +22,8 @@ export async function commonUpdate(requestParam:any): Promise noStore(); try { // 使用 Axios 发送 PUT 请求获取数据 - const response: AxiosResponse> = await axios.put( - 'http://taskmanagerserver.com:8090/search/task_message_tree',requestParam); + const response: AxiosResponse> = await httpReq.put( + process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/search/task_message_tree',requestParam); // 从响应中提取数据并返回 return response.data; } catch (error) { @@ -37,8 +37,8 @@ export async function commonUpdate(requestParam:any): Promise export async function taskTreeResult(): Promise>> { noStore(); try { - // 使用 Axios 发送 POST 请求获取数据 - const response: AxiosResponse>> = await axios.post('http://taskmanagerserver.com:8090/task/tree', { + // 使用 httpReq 发送 POST 请求获取数据 + const response: AxiosResponse>> = await httpReq.post(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task/tree', { pageSize: 10, pageNumber: 1 }); @@ -55,7 +55,7 @@ export async function getTask(id:number): Promise> { noStore(); try { // 使用 Axios 发送 GET 请求获取数据 - const response: AxiosResponse> = await axios.get('http://taskmanagerserver.com:8090/task/'+id); + const response: AxiosResponse> = await httpReq.get(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task/'+id); // 从响应中提取数据并返回 return response.data; } catch (error) { @@ -70,7 +70,7 @@ export async function addTask(task:DataType): Promise> { noStore(); try { // 使用 Axios 发送 POST 请求添加数据 - const response: AxiosResponse> = await axios.post('http://taskmanagerserver.com:8090/task', task); + const response: AxiosResponse> = await httpReq.post(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task', task); // 从响应中提取数据并返回 return response.data; } catch (error) { @@ -84,7 +84,7 @@ export async function updateTask(task:DataType): Promise> { noStore(); try { // 使用 Axios 发送 PUT 请求修改数据 - const response: AxiosResponse> = await axios.put('http://taskmanagerserver.com:8090/task', task); + const response: AxiosResponse> = await httpReq.put(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task', task); // 从响应中提取数据并返回 return response.data; } catch (error) { @@ -98,7 +98,7 @@ export async function deleteTask(id:number): Promise> { noStore(); try { // 使用 Axios 发送 DELETE 删除数据 - const response: AxiosResponse> = await axios.delete('http://taskmanagerserver.com:8090/task/'+id); + const response: AxiosResponse> = await httpReq.delete(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task/'+id); // 从响应中提取数据并返回 return response.data; } catch (error) { diff --git a/src/utils/axiosReq.ts b/src/utils/axiosReq.ts new file mode 100644 index 0000000..93e3562 --- /dev/null +++ b/src/utils/axiosReq.ts @@ -0,0 +1,18 @@ +import axios, {Canceler, CancelToken, CancelTokenSource} from "axios"; + + +export const httpReq = axios.create({ + // cancelToken: new CancelToken(function (cancel:Canceler) { + // },), + // validateStatus: function (status) { + // return status >= 200 && status < 300; // default + // }, + withCredentials: false, +}) +// 从cookie获取token + +// 创建一个取消令牌 +const cancelTokenSource: CancelTokenSource = axios.CancelToken.source(); + +httpReq.defaults.headers.common['Accept'] = 'application/json'; +httpReq.interceptors.request.use() \ No newline at end of file