init
This commit is contained in:
17
src/api/common/index.ts
Normal file
17
src/api/common/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 通用接口
|
||||
*/
|
||||
import type { SendCodeParams, SendCodeResult, UploadImageResult } from './types';
|
||||
import { post, upload } from '@/utils/request';
|
||||
|
||||
enum URL {
|
||||
upload = '/common/upload',
|
||||
sendCode = '/sendCode',
|
||||
}
|
||||
|
||||
// 图片上传
|
||||
export const uploadImage = (imagePath: string) =>
|
||||
upload<UploadImageResult>({ url: URL.upload, filePath: imagePath, name: 'file' });
|
||||
|
||||
// 发送验证码
|
||||
export const sendCode = (data: SendCodeParams) => post<SendCodeResult>({ url: URL.sendCode, data });
|
13
src/api/common/types.ts
Normal file
13
src/api/common/types.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface UploadImageResult {
|
||||
file: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface SendCodeParams {
|
||||
phone: number;
|
||||
code: number;
|
||||
}
|
||||
|
||||
export interface SendCodeResult {
|
||||
code: number;
|
||||
}
|
4
src/api/index.ts
Normal file
4
src/api/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import * as CommonApi from './common';
|
||||
import * as UserApi from './user';
|
||||
|
||||
export { CommonApi, UserApi };
|
18
src/api/user/index.ts
Normal file
18
src/api/user/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 用户信息相关接口
|
||||
*/
|
||||
import type { LoginByCodeParams, LoginParams, LoginResult } from './types';
|
||||
import { get, post } from '@/utils/request';
|
||||
import type { UserState } from '@/store/modules/user/types';
|
||||
|
||||
enum URL {
|
||||
login = '/user/login',
|
||||
loginByCode = '/user/loginByCode',
|
||||
logout = '/user/logout',
|
||||
profile = '/user/profile',
|
||||
}
|
||||
|
||||
export const getUserProfile = () => get<UserState>({ url: URL.profile });
|
||||
export const login = (data: LoginParams) => post<LoginResult>({ url: URL.login, data });
|
||||
export const loginByCode = (data: LoginByCodeParams) => post<any>({ url: URL.loginByCode, data });
|
||||
export const logout = () => post<any>({ url: URL.logout });
|
15
src/api/user/types.ts
Normal file
15
src/api/user/types.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export interface LoginParams {
|
||||
phone: string;
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface LoginByCodeParams {
|
||||
code: string;
|
||||
}
|
||||
|
||||
export interface LoginResult {
|
||||
token: string;
|
||||
user_id: number;
|
||||
user_name: string;
|
||||
avatar: string;
|
||||
}
|
Reference in New Issue
Block a user