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