feat:login

This commit is contained in:
1708-huayu 2024-11-21 22:48:47 +08:00
parent e0c32ad9bc
commit 51cb4a47cc
7 changed files with 73 additions and 50 deletions

4
.env.development Normal file
View File

@ -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=

1
.env.production Normal file
View File

@ -0,0 +1 @@
NEXT_PUBLIC_TODO_REQUEST_URL=http://taskmanagerserver.com:8090

View File

@ -14,9 +14,11 @@ import {
ProFormCheckbox, ProFormCheckbox,
ProFormText, ProFormText,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { Button, Divider, Space, Tabs, message, theme } from 'antd'; import {Button, Divider, Space, Tabs, message, theme} from 'antd';
import type { CSSProperties } from 'react'; import type {CSSProperties} from 'react';
import { useState } from 'react'; import {useState} from 'react';
import {LoginObject} from "@/lib/login/definitions";
import {httpReq} from "@/utils/axiosReq";
type LoginType = 'phone' | 'account'; type LoginType = 'phone' | 'account';
@ -29,7 +31,7 @@ const iconStyles: CSSProperties = {
const Page = () => { const Page = () => {
const [loginType, setLoginType] = useState<LoginType>('phone'); const [loginType, setLoginType] = useState<LoginType>('phone');
const { token } = theme.useToken(); const {token} = theme.useToken();
return ( return (
<div <div
style={{ style={{
@ -58,6 +60,7 @@ const Page = () => {
// title: '活动标题,可配置图片', // title: '活动标题,可配置图片',
// subTitle: '活动介绍说明文字', // subTitle: '活动介绍说明文字',
// action: ( // action: (
// action: (
// <Button // <Button
// size="large" // size="large"
// style={{ // style={{
@ -71,23 +74,28 @@ const Page = () => {
// </Button> // </Button>
// ), // ),
}} }}
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={ actions={
<div <div style={{
style={{
display: 'flex', display: 'flex',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
flexDirection: 'column', flexDirection: 'column',}}>
}}
>
<Divider plain> <Divider plain>
<span <span style={{
style={{
color: token.colorTextPlaceholder, color: token.colorTextPlaceholder,
fontWeight: 'normal', fontWeight: 'normal',
fontSize: 14, fontSize: 14,}}>
}}
>
</span> </span>
</Divider> </Divider>
@ -104,7 +112,7 @@ const Page = () => {
borderRadius: '50%', borderRadius: '50%',
}} }}
> >
<AlipayOutlined style={{ ...iconStyles, color: '#1677FF' }} /> <AlipayOutlined style={{...iconStyles, color: '#1677FF'}}/>
</div> </div>
<div <div
style={{ style={{
@ -118,7 +126,7 @@ const Page = () => {
borderRadius: '50%', borderRadius: '50%',
}} }}
> >
<TaobaoOutlined style={{ ...iconStyles, color: '#FF6A10' }} /> <TaobaoOutlined style={{...iconStyles, color: '#FF6A10'}}/>
</div> </div>
<div <div
style={{ style={{
@ -132,7 +140,7 @@ const Page = () => {
borderRadius: '50%', borderRadius: '50%',
}} }}
> >
<WeiboOutlined style={{ ...iconStyles, color: '#1890ff' }} /> <WeiboOutlined style={{...iconStyles, color: '#1890ff'}}/>
</div> </div>
</Space> </Space>
</div> </div>
@ -143,8 +151,8 @@ const Page = () => {
activeKey={loginType} activeKey={loginType}
onChange={(activeKey) => setLoginType(activeKey as LoginType)} onChange={(activeKey) => setLoginType(activeKey as LoginType)}
> >
<Tabs.TabPane key={'account'} tab={'账号密码登录'} /> <Tabs.TabPane key={'account'} tab={'账号密码登录'}/>
<Tabs.TabPane key={'phone'} tab={'手机号登录'} /> <Tabs.TabPane key={'phone'} tab={'手机号登录'}/>
</Tabs> </Tabs>
{loginType === 'account' && ( {loginType === 'account' && (
<> <>
@ -278,7 +286,7 @@ const Page = () => {
export default () => { export default () => {
return ( return (
<ProConfigProvider dark> <ProConfigProvider dark>
<Page /> <Page/>
</ProConfigProvider> </ProConfigProvider>
); );
}; };

View File

@ -0,0 +1,6 @@
export type LoginObject={
username:string;
password:string;
mobile:string;
captcha:string;
}

View File

@ -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',
},
];

View File

@ -1,13 +1,13 @@
import {unstable_noStore as noStore} from 'next/cache'; 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"; import {DataType, DictType, ResponseVO, ResultPage} from "@/lib/definitions";
export async function getTaskTreeResult(requestParam:string): Promise<ResponseVO<ResultPage<DataType>>> { export async function getTaskTreeResult(requestParam:string): Promise<ResponseVO<ResultPage<DataType>>> {
noStore(); noStore();
try { try {
// 使用 Axios 发送 POST 请求获取数据 // 使用 Axios 发送 POST 请求获取数据
const response: AxiosResponse<ResponseVO<ResultPage<DataType>>> = await axios.get( const response: AxiosResponse<ResponseVO<ResultPage<DataType>>> = await httpReq.get(
'http://taskmanagerserver.com:8090/search/task_message_tree?search='+encodeURIComponent(requestParam)); process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/search/task_message_tree?search='+encodeURIComponent(requestParam));
// 从响应中提取数据并返回 // 从响应中提取数据并返回
console.log("response.data",response.data) console.log("response.data",response.data)
return response.data; return response.data;
@ -22,8 +22,8 @@ export async function commonUpdate(requestParam:any): Promise<ResponseVO<string>
noStore(); noStore();
try { try {
// 使用 Axios 发送 PUT 请求获取数据 // 使用 Axios 发送 PUT 请求获取数据
const response: AxiosResponse<ResponseVO<string>> = await axios.put( const response: AxiosResponse<ResponseVO<string>> = await httpReq.put(
'http://taskmanagerserver.com:8090/search/task_message_tree',requestParam); process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/search/task_message_tree',requestParam);
// 从响应中提取数据并返回 // 从响应中提取数据并返回
return response.data; return response.data;
} catch (error) { } catch (error) {
@ -37,8 +37,8 @@ export async function commonUpdate(requestParam:any): Promise<ResponseVO<string>
export async function taskTreeResult(): Promise<ResponseVO<ResultPage<DataType>>> { export async function taskTreeResult(): Promise<ResponseVO<ResultPage<DataType>>> {
noStore(); noStore();
try { try {
// 使用 Axios 发送 POST 请求获取数据 // 使用 httpReq 发送 POST 请求获取数据
const response: AxiosResponse<ResponseVO<ResultPage<DataType>>> = await axios.post('http://taskmanagerserver.com:8090/task/tree', { const response: AxiosResponse<ResponseVO<ResultPage<DataType>>> = await httpReq.post(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task/tree', {
pageSize: 10, pageSize: 10,
pageNumber: 1 pageNumber: 1
}); });
@ -55,7 +55,7 @@ export async function getTask(id:number): Promise<ResponseVO<DataType>> {
noStore(); noStore();
try { try {
// 使用 Axios 发送 GET 请求获取数据 // 使用 Axios 发送 GET 请求获取数据
const response: AxiosResponse<ResponseVO<DataType>> = await axios.get('http://taskmanagerserver.com:8090/task/'+id); const response: AxiosResponse<ResponseVO<DataType>> = await httpReq.get(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task/'+id);
// 从响应中提取数据并返回 // 从响应中提取数据并返回
return response.data; return response.data;
} catch (error) { } catch (error) {
@ -70,7 +70,7 @@ export async function addTask(task:DataType): Promise<ResponseVO<string>> {
noStore(); noStore();
try { try {
// 使用 Axios 发送 POST 请求添加数据 // 使用 Axios 发送 POST 请求添加数据
const response: AxiosResponse<ResponseVO<string>> = await axios.post('http://taskmanagerserver.com:8090/task', task); const response: AxiosResponse<ResponseVO<string>> = await httpReq.post(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task', task);
// 从响应中提取数据并返回 // 从响应中提取数据并返回
return response.data; return response.data;
} catch (error) { } catch (error) {
@ -84,7 +84,7 @@ export async function updateTask(task:DataType): Promise<ResponseVO<string>> {
noStore(); noStore();
try { try {
// 使用 Axios 发送 PUT 请求修改数据 // 使用 Axios 发送 PUT 请求修改数据
const response: AxiosResponse<ResponseVO<string>> = await axios.put('http://taskmanagerserver.com:8090/task', task); const response: AxiosResponse<ResponseVO<string>> = await httpReq.put(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task', task);
// 从响应中提取数据并返回 // 从响应中提取数据并返回
return response.data; return response.data;
} catch (error) { } catch (error) {
@ -98,7 +98,7 @@ export async function deleteTask(id:number): Promise<ResponseVO<string>> {
noStore(); noStore();
try { try {
// 使用 Axios 发送 DELETE 删除数据 // 使用 Axios 发送 DELETE 删除数据
const response: AxiosResponse<ResponseVO<string>> = await axios.delete('http://taskmanagerserver.com:8090/task/'+id); const response: AxiosResponse<ResponseVO<string>> = await httpReq.delete(process.env.NEXT_PUBLIC_TODO_REQUEST_URL+'/task/'+id);
// 从响应中提取数据并返回 // 从响应中提取数据并返回
return response.data; return response.data;
} catch (error) { } catch (error) {

18
src/utils/axiosReq.ts Normal file
View File

@ -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()