- 添加Docker相关配置文件(.dockerignore, .env.example, .gitignore) - 实现服务端API代理功能,支持文件、模块和服务器API转发 - 创建文章详情页、栏目文章列表页和单页内容展示页面 - 集成Ant Design Vue组件库并实现SSR样式提取功能 - 定义API响应数据结构类型和应用布局组件 - 开发开发者应用中心和文章管理页面 - 实现CMS导航菜单获取和多租户切换功能
112 lines
3.0 KiB
TypeScript
112 lines
3.0 KiB
TypeScript
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 || '微信小程序登录确认失败'));
|
|
}
|