feat: 本次提交更新内容如下

登录页面新样式
This commit is contained in:
2025-07-18 15:56:12 +08:00
parent c611cb9e0c
commit a336d1173b
9 changed files with 1018 additions and 103 deletions

54
nkebao/src/api/auth.ts Normal file
View File

@@ -0,0 +1,54 @@
import request from './request';
export interface LoginParams {
phone: string;
password?: string;
verificationCode?: string;
}
export interface LoginResponse {
code: number;
msg: string;
data: {
token: string;
token_expired: string;
member: {
id: string;
name: string;
phone: string;
s2_accountId: string;
avatar?: string;
email?: string;
};
};
}
export interface SendCodeResponse {
code: number;
msg: string;
}
// 密码登录
export function loginWithPassword(phone: string, password: string) {
return request<LoginResponse>('/v1/auth/login', { phone, password }, 'POST');
}
// 验证码登录
export function loginWithCode(phone: string, verificationCode: string) {
return request<LoginResponse>('/v1/auth/login-code', { phone, verificationCode }, 'POST');
}
// 发送验证码
export function sendVerificationCode(phone: string) {
return request<SendCodeResponse>('/v1/auth/send-code', { phone }, 'POST');
}
// 退出登录
export function logout() {
return request('/v1/auth/logout', {}, 'POST');
}
// 获取用户信息
export function getUserInfo() {
return request('/v1/auth/user-info', {}, 'GET');
}

View File

@@ -27,33 +27,24 @@ instance.interceptors.response.use(
if (code === 200 || success) {
return res.data.data ?? res.data;
}
// 业务错误统一提示
Toast.show({ content: msg || '接口错误', position: 'top' });
// 分类处理
if (code === 401) {
// 未登录或登录失效
localStorage.removeItem('token');
} else if (code === 403) {
// 无权限
} else if (code === 500) {
// 服务端异常
const currentPath = window.location.pathname + window.location.search;
if (currentPath === '/login') {
window.location.href = '/login';
} else {
window.location.href = `/login?redirect=${encodeURIComponent(currentPath)}`;
}
}
return Promise.reject(msg || '接口错误');
},
err => {
// 网络错误、超时等
Toast.show({ content: err.message || '网络异常', position: 'top' });
return Promise.reject(err);
}
);
/**
* @param url 接口地址
* @param data 请求参数
* @param method 请求方法
* @param config axios 配置
* @param debounceGap 防抖时间(毫秒),不传则用默认值
*/
export function request(
url: string,
data?: any,
@@ -84,4 +75,4 @@ export function request(
return instance(axiosConfig);
}
export default request;
export default request;