feat(app): 初始化项目配置和页面结构
- 添加 .dockerignore 和 .env.example 配置文件 - 添加 .gitignore 忽略规则配置 - 创建服务端代理API路由(_file、_modules、_server) - 集成 Ant Design Vue 组件库并配置SSR样式提取 - 定义API响应类型封装 - 创建基础布局组件(blank、console) - 实现应用中心页面和组件(AppsCenter) - 添加文章列表测试页面 - 配置控制台导航菜单结构 - 实现控制台头部组件 - 创建联系页面表单
This commit is contained in:
111
app/api/passport/qrLogin/index.ts
Normal file
111
app/api/passport/qrLogin/index.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import request from '@/utils/request';
|
||||
import type { ApiResult } from '@/api';
|
||||
import { SERVER_API_URL } from '@/config/setting';
|
||||
|
||||
/**
|
||||
* 二维码生成响应数据
|
||||
*/
|
||||
export interface QrCodeResponse {
|
||||
token: string; // 二维码唯一标识token
|
||||
qrCode: string; // 二维码内容
|
||||
expiresIn: number; // 过期时间(秒)
|
||||
}
|
||||
|
||||
/**
|
||||
* 二维码状态响应
|
||||
*/
|
||||
export interface QrCodeStatusResponse {
|
||||
status: 'pending' | 'scanned' | 'confirmed' | 'expired';
|
||||
accessToken?: string; // 登录成功时返回的JWT token
|
||||
access_token?: string; // 兼容后端下划线命名
|
||||
userInfo?: any; // 用户信息
|
||||
expiresIn?: number; // 剩余过期时间(秒)
|
||||
tenantId?: string; // 租户ID
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认登录请求参数
|
||||
*/
|
||||
export interface QrLoginConfirmRequest {
|
||||
token: string; // 二维码token
|
||||
userId?: number; // 用户ID
|
||||
platform?: string; // 登录平台
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成登录二维码
|
||||
*/
|
||||
export async function generateQrCode(): Promise<QrCodeResponse> {
|
||||
const res = await request.post<ApiResult<QrCodeResponse>>(
|
||||
SERVER_API_URL + '/qr-login/generate',
|
||||
{}
|
||||
);
|
||||
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(res.data.message || '生成二维码失败'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查二维码状态
|
||||
*/
|
||||
export async function checkQrCodeStatus(token: string): Promise<QrCodeStatusResponse> {
|
||||
const res = await request.get<ApiResult<QrCodeStatusResponse>>(
|
||||
SERVER_API_URL + `/qr-login/status/${token}`
|
||||
);
|
||||
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(res.data.message || '检查二维码状态失败'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码确认登录(移动端调用)
|
||||
*/
|
||||
export async function confirmQrLogin(requestData: QrLoginConfirmRequest): Promise<QrCodeStatusResponse> {
|
||||
const res = await request.post<ApiResult<QrCodeStatusResponse>>(
|
||||
SERVER_API_URL + '/qr-login/confirm',
|
||||
requestData
|
||||
);
|
||||
console.log(res,'>>>89898989')
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(res.data.message || '确认登录失败'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码标记(移动端扫码时调用)
|
||||
*/
|
||||
export async function scanQrCode(token: string): Promise<boolean> {
|
||||
const res = await request.post<ApiResult<boolean>>(
|
||||
SERVER_API_URL + `/qr-login/scan/${token}`
|
||||
);
|
||||
|
||||
if (res.data.code === 0) {
|
||||
return res.data.data || true;
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(res.data.message || '扫码失败'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信小程序扫码登录确认
|
||||
*/
|
||||
export async function wechatMiniProgramConfirm(requestData: QrLoginConfirmRequest): Promise<QrCodeStatusResponse> {
|
||||
const res = await request.post<ApiResult<QrCodeStatusResponse>>(
|
||||
SERVER_API_URL + '/qr-login/wechat-confirm',
|
||||
requestData
|
||||
);
|
||||
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
|
||||
return Promise.reject(new Error(res.data.message || '微信小程序登录确认失败'));
|
||||
}
|
||||
Reference in New Issue
Block a user