feat(app): 初始化项目配置和页面结构
- 添加 .dockerignore 和 .env.example 配置文件 - 添加 .gitignore 忽略规则配置 - 创建服务端代理API路由(_file、_modules、_server) - 集成 Ant Design Vue 组件库并配置SSR样式提取 - 定义API响应类型封装 - 创建基础布局组件(blank、console) - 实现应用中心页面和组件(AppsCenter) - 添加文章列表测试页面 - 配置控制台导航菜单结构 - 实现控制台头部组件 - 创建联系页面表单
This commit is contained in:
117
app/api/passport/login/index.ts
Normal file
117
app/api/passport/login/index.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import request from '@/utils/request';
|
||||
import { setToken } from '@/utils/token-util';
|
||||
import type { ApiResult } from '@/api';
|
||||
import type {
|
||||
LoginParam,
|
||||
LoginResult,
|
||||
CaptchaResult,
|
||||
SmsCaptchaResult
|
||||
} from './model';
|
||||
import type { User } from '@/api/system/user/model';
|
||||
import { SERVER_API_URL } from '@/config/setting';
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
export async function login(data: LoginParam) {
|
||||
const res = await request.post<ApiResult<LoginResult>>(
|
||||
SERVER_API_URL + '/login',
|
||||
data
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
setToken(res.data.data?.access_token, data.remember);
|
||||
if (res.data.data?.user) {
|
||||
const user = res.data.data?.user;
|
||||
localStorage.setItem('TenantId', String(user.tenantId));
|
||||
localStorage.setItem('UserId', String(user.userId));
|
||||
}
|
||||
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
export async function getCaptcha() {
|
||||
const res = await request.get<ApiResult<CaptchaResult>>(
|
||||
SERVER_API_URL + '/captcha'
|
||||
);
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
export async function loginBySms(data: LoginParam) {
|
||||
const res = await request.post<ApiResult<LoginResult>>(
|
||||
SERVER_API_URL + '/loginBySms',
|
||||
data
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
setToken(res.data.data?.access_token, data.remember);
|
||||
if (res.data.data?.user) {
|
||||
const user = res.data.data?.user;
|
||||
localStorage.setItem('TenantId', String(user.tenantId));
|
||||
localStorage.setItem('UserId', String(user.userId));
|
||||
}
|
||||
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
*/
|
||||
export async function sendSmsCaptcha(data: LoginParam) {
|
||||
const res = await request.post<ApiResult<SmsCaptchaResult>>(
|
||||
SERVER_API_URL + '/sendSmsCaptcha',
|
||||
data
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
export async function remoteLogin(data: LoginParam) {
|
||||
const res = await request.post<ApiResult<LoginResult>>(
|
||||
'https://open.gxwebsoft.com/api/login',
|
||||
data
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
setToken(res.data.data?.access_token, data.remember);
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业微信登录链接
|
||||
*/
|
||||
export async function getWxWorkQrConnect(data) {
|
||||
const res = await request.post<ApiResult<unknown>>(
|
||||
SERVER_API_URL + '/wx-work',
|
||||
data
|
||||
);
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
export async function registerUser(data: User) {
|
||||
const res = await request.post<ApiResult<unknown>>(
|
||||
SERVER_API_URL + '/register',
|
||||
data
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
46
app/api/passport/login/model/index.ts
Normal file
46
app/api/passport/login/model/index.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import type { User } from '@/api/system/user/model';
|
||||
/**
|
||||
* 登录参数
|
||||
*/
|
||||
export interface LoginParam {
|
||||
// 账号
|
||||
username?: string;
|
||||
// 密码
|
||||
password?: string;
|
||||
// 租户id
|
||||
tenantId?: number;
|
||||
// 是否记住密码
|
||||
remember?: boolean;
|
||||
// 手机号码
|
||||
phone?: string;
|
||||
// 短信验证码
|
||||
code?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录返回结果
|
||||
*/
|
||||
export interface LoginResult {
|
||||
// token
|
||||
access_token?: string;
|
||||
// 用户信息
|
||||
user?: User;
|
||||
}
|
||||
|
||||
/**
|
||||
* 图形验证码返回结果
|
||||
*/
|
||||
export interface CaptchaResult {
|
||||
// 图形验证码base64数据
|
||||
base64: string;
|
||||
// 验证码文本
|
||||
text: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信验证码返回结果
|
||||
*/
|
||||
export interface SmsCaptchaResult {
|
||||
// 验证码文本
|
||||
text: string;
|
||||
}
|
||||
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