feat: 登录页面

This commit is contained in:
renxiaodong
2025-06-20 06:10:15 -04:00
parent 1641320847
commit 54f620d92f
12 changed files with 328 additions and 287 deletions

View File

@ -1,20 +1,16 @@
import Http from '@/api';
// 导出一个函数,用于获取登录验证码
export const fetchLoginCaptCha = (params = {}) => {
return Http.post('/v1/sms/login-captcha', params);
};
// 导出一个函数,用于获取验证码
export const fetchAuthorizationsCaptcha = (params = {}) => {
// 使用Http.post方法发送POST请求请求地址为'/v1/authorizations/captcha'请求参数为params
return Http.post('/v1/authorizations/captcha', params);
};
// 导出一个函数,用于获取授权信息
export const fetchAuthorizations = (params = {}) => {
// 使用Http.put方法向服务器发送PUT请求获取授权信息
@ -27,22 +23,18 @@ export const fetchLogOut = (params = {}) => {
return Http.put('/v1/authorizations', params);
};
// 导出一个名为fetchProfileInfo的函数用于获取用户信息
export const fetchProfileInfo = (params = {}) => {
// 使用Http.put方法向/v1/me接口发送put请求并将params作为参数传递
return Http.put('/v1/me', params);
};
// 导出一个函数,用于获取编辑手机号的验证码
export const fetchEditPhoneCaptcha = (params = {}) => {
// 使用Http.put方法向服务器发送PUT请求获取编辑手机号的验证码
return Http.put('/v1/sms/update-mobile-captcha', params);
};
export const fetchBindPhone = (params = {}) => {
return Http.put('/v1/me/mobile', params);
};

View File

@ -1,32 +1,46 @@
/*
* @Author: 田鑫
* @Date: 2023-02-17 11:58:44
* @LastEditors: 田鑫
* @LastEditTime: 2023-03-05 19:17:29
* @LastEditors: Please set LastEditors
* @LastEditTime: 2025-06-20 06:00:54
* @Description:
*/
import axios from 'axios';
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { handleUserLogout } from '@/utils/user';
const contentType = 'application/json';
const requestTimeout = 30000;
const HttpStatusCode = {
OK: 200,
BadRequest: 400, // 请求参数错误
Unauthorized: 401, // token 无效或过期
NotFound: 404,
InternalServerError: 500,
};
//* 导出Request类可以用来自定义传递配置来创建实例
export class Request {
//* axios 实例
private instance: AxiosInstance;
//* 基础配置
private baseConfig: AxiosRequestConfig = { baseURL: import.meta.env.EO_API_URL, timeout: 60000 };
private baseConfig: AxiosRequestConfig = {
baseURL: import.meta.env.EO_API_URL,
timeout: requestTimeout,
headers: {
'Content-Type': contentType,
},
};
public constructor(config: AxiosRequestConfig) {
this.instance = axios.create(Object.assign(this.baseConfig, config));
this.instance.interceptors.request.use(
(config: AxiosRequestConfig) => {
const token = localStorage.getItem('token') as string;
if (token) {
config.headers!.Authorization = token;
} else {
config.headers!.satoken = '123';
}
const token = localStorage.getItem('accessToken') as string;
config.headers!.Authorization = token;
return config;
},
(err: any) => {
@ -36,21 +50,17 @@ export class Request {
this.instance.interceptors.response.use(
(res: AxiosResponse) => {
//* http请求成功
//* 存入通用response header
let tenanttype = localStorage.getItem('tenanttype') as string;
if (!tenanttype) {
tenanttype = res.headers!.tenanttype;
localStorage.setItem('tenanttype', tenanttype);
const { data } = res;
switch (data.code) {
case HttpStatusCode.OK:
return data;
default:
return Promise.reject(data);
}
if (res.data.code === 200) {
return res.data.data;
}
AMessage.error(res.data!.msg);
return Promise.reject(res.data);
},
(err: any) => {
// AMessage.error(err.message);
const message = err.response?.data?.message ?? err.message;
AMessage.error(message);
// 这里用来处理http常见错误进行全局提示
return Promise.reject(err.response);
},