- 新增优惠券卡片对齐修复文档 - 新增优惠券状态显示调试文档 - 新增优惠券组件警告修复文档- 更新用ShopInfo Hook字段迁移文档 - 更新Arguments关键字修复文档
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import request from '@/utils/request-legacy';
|
|
import type { ApiResult } from '@/api';
|
|
import type {
|
|
LoginParam,
|
|
LoginResult,
|
|
CaptchaResult,
|
|
SmsCaptchaResult
|
|
} from './model';
|
|
import {saveStorageByLoginUser, SERVER_API_URL} from "@/utils/server";
|
|
|
|
/**
|
|
* 登录
|
|
*/
|
|
export async function login(data: LoginParam) {
|
|
const res = await request.post<ApiResult<LoginResult>>(
|
|
SERVER_API_URL + '/login',
|
|
data
|
|
);
|
|
if (res.code === 0) {
|
|
// setToken(res.data.data?.access_token, data.remember);
|
|
if (res.data?.user) {
|
|
const user = res.data?.user;
|
|
localStorage.setItem('TenantId', String(user.tenantId));
|
|
localStorage.setItem('UserId', String(user.userId));
|
|
}
|
|
|
|
return res.message;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 获取验证码
|
|
*/
|
|
export async function getCaptcha() {
|
|
const res = await request.get<ApiResult<CaptchaResult>>(
|
|
SERVER_API_URL + '/captcha',
|
|
{}
|
|
);
|
|
if (res.code === 0 && res.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
export async function loginBySms(data: LoginParam) {
|
|
const res = await request.post<ApiResult<LoginResult>>(
|
|
SERVER_API_URL + '/loginBySms',
|
|
data
|
|
);
|
|
if (res.code === 0) {
|
|
if(res.data?.user){
|
|
saveStorageByLoginUser(`${res.data?.access_token}`, res.data?.user)
|
|
}
|
|
return res.message;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 发送短信验证码
|
|
*/
|
|
export async function sendSmsCaptcha(data: LoginParam) {
|
|
const res = await request.post<ApiResult<SmsCaptchaResult>>(
|
|
SERVER_API_URL + '/sendSmsCaptcha',
|
|
data
|
|
);
|
|
if (res.code === 0) {
|
|
return res.message;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|