mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 12:29:19 +08:00
初始化项目
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import { baseRequestClient, requestClient } from '#/api/request';
|
||||
|
||||
export namespace AuthApi {
|
||||
/** 登录接口参数 */
|
||||
export interface LoginParams {
|
||||
account: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
/** 注册接口参数 */
|
||||
export interface RegisterParams {
|
||||
loginCode?: string;
|
||||
phone?: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
/** 登录接口返回值 */
|
||||
export interface LoginResult {
|
||||
token: string;
|
||||
user: UserInfo;
|
||||
}
|
||||
|
||||
/** 用户信息 */
|
||||
export interface UserInfo {
|
||||
id: number;
|
||||
companyId?: number;
|
||||
departmentId?: number;
|
||||
positionId?: number;
|
||||
loginCode: string;
|
||||
phone?: string;
|
||||
realName: string;
|
||||
avatar?: string;
|
||||
role: string;
|
||||
pwdSecurityLevel?: number;
|
||||
pwdUpdateTime?: string;
|
||||
lastLoginIp?: string;
|
||||
lastLoginDate?: string;
|
||||
freezeDate?: string;
|
||||
freezeCause?: string;
|
||||
status: number;
|
||||
remark?: string;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
}
|
||||
|
||||
export interface RefreshTokenResult {
|
||||
data: string;
|
||||
status: number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户注册
|
||||
*/
|
||||
export async function registerApi(data: AuthApi.RegisterParams) {
|
||||
return requestClient.post<AuthApi.LoginResult>('/auth/register', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
*/
|
||||
export async function loginApi(data: AuthApi.LoginParams) {
|
||||
return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新accessToken
|
||||
*/
|
||||
export async function refreshTokenApi() {
|
||||
return baseRequestClient.post<AuthApi.RefreshTokenResult>('/auth/refresh', {
|
||||
withCredentials: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
export async function logoutApi() {
|
||||
return baseRequestClient.post('/auth/logout', {
|
||||
withCredentials: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限码
|
||||
*/
|
||||
export async function getAccessCodesApi() {
|
||||
return requestClient.get<string[]>('/auth/codes');
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
export * from './auth';
|
||||
export * from './menu';
|
||||
export * from './organization';
|
||||
export * from './user';
|
||||
@@ -0,0 +1,97 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace MenuApi {
|
||||
/** 菜单信息 */
|
||||
export interface MenuInfo {
|
||||
id: number;
|
||||
parentId?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
children?: MenuInfo[];
|
||||
}
|
||||
|
||||
/** 创建菜单参数 */
|
||||
export interface CreateMenuParams {
|
||||
parentId?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
}
|
||||
|
||||
/** 更新菜单参数 */
|
||||
export interface UpdateMenuParams {
|
||||
parentId?: number;
|
||||
name: string;
|
||||
title?: string;
|
||||
path?: string;
|
||||
component?: string;
|
||||
redirect?: string;
|
||||
icon?: string;
|
||||
order?: number;
|
||||
type: string;
|
||||
visible?: number;
|
||||
status?: number;
|
||||
keepAlive?: number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单树
|
||||
*/
|
||||
export async function getMenuTreeApi() {
|
||||
return requestClient.get<MenuApi.MenuInfo[]>('/menu/tree');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有菜单
|
||||
*/
|
||||
export async function getAllMenusApi() {
|
||||
return requestClient.get<MenuApi.MenuInfo[]>('/menu/list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单详情
|
||||
*/
|
||||
export async function getMenuDetailApi(id: number) {
|
||||
return requestClient.get<MenuApi.MenuInfo>(`/menu/detail/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单
|
||||
*/
|
||||
export async function createMenuApi(data: MenuApi.CreateMenuParams) {
|
||||
return requestClient.post<MenuApi.MenuInfo>('/menu/create', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
*/
|
||||
export async function updateMenuApi(id: number, data: MenuApi.UpdateMenuParams) {
|
||||
return requestClient.put<MenuApi.MenuInfo>(`/menu/update/${id}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*/
|
||||
export async function deleteMenuApi(id: number) {
|
||||
return requestClient.delete<void>(`/menu/delete/${id}`);
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
// 分页查询参数
|
||||
export interface PageQuery {
|
||||
page: number;
|
||||
size: number;
|
||||
filter?: any;
|
||||
}
|
||||
|
||||
// 分页结果
|
||||
export interface PageResult<T> {
|
||||
records: T[];
|
||||
total: number;
|
||||
size: number;
|
||||
current: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
export namespace CompanyApi {
|
||||
/** 公司信息 */
|
||||
export interface CompanyInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
expiration?: string;
|
||||
address?: string;
|
||||
contactPerson?: string;
|
||||
contactPhone?: string;
|
||||
email?: string;
|
||||
logo?: string;
|
||||
status: number;
|
||||
expireTime?: string;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
expired?: boolean;
|
||||
}
|
||||
|
||||
/** 创建公司参数 */
|
||||
export interface CreateCompanyParams {
|
||||
name: string;
|
||||
address?: string;
|
||||
contactPerson?: string;
|
||||
contactPhone?: string;
|
||||
email?: string;
|
||||
logo?: string;
|
||||
status?: number;
|
||||
expireTime?: string;
|
||||
}
|
||||
|
||||
/** 更新公司参数 */
|
||||
export interface UpdateCompanyParams {
|
||||
name: string;
|
||||
address?: string;
|
||||
contactPerson?: string;
|
||||
contactPhone?: string;
|
||||
email?: string;
|
||||
logo?: string;
|
||||
status?: number;
|
||||
expireTime?: string;
|
||||
}
|
||||
|
||||
/** 公司过滤条件 */
|
||||
export interface CompanyFilter {
|
||||
name?: string;
|
||||
status?: number;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace DepartmentApi {
|
||||
/** 部门信息 */
|
||||
export interface DepartmentInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
parentId?: number;
|
||||
companyId: number;
|
||||
remark?: string;
|
||||
status: number;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
createBy?: number;
|
||||
updateBy?: number;
|
||||
children?: DepartmentInfo[];
|
||||
}
|
||||
|
||||
/** 创建部门参数 */
|
||||
export interface CreateDepartmentParams {
|
||||
name: string;
|
||||
parentId?: number;
|
||||
remark?: string;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
/** 更新部门参数 */
|
||||
export interface UpdateDepartmentParams {
|
||||
name: string;
|
||||
parentId?: number;
|
||||
remark?: string;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
/** 部门过滤条件 */
|
||||
export interface DepartmentFilter {
|
||||
name?: string;
|
||||
companyId?: number;
|
||||
status?: number;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace PositionApi {
|
||||
/** 岗位信息 */
|
||||
export interface PositionInfo {
|
||||
id: number;
|
||||
name: string;
|
||||
code?: string;
|
||||
departmentId?: number;
|
||||
remark?: string;
|
||||
status: number;
|
||||
companyId: number;
|
||||
createTime: string;
|
||||
updateTime: string;
|
||||
createBy?: number;
|
||||
updateBy?: number;
|
||||
}
|
||||
|
||||
/** 创建岗位参数 */
|
||||
export interface CreatePositionParams {
|
||||
name: string;
|
||||
code?: string;
|
||||
departmentId?: number;
|
||||
remark?: string;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
/** 更新岗位参数 */
|
||||
export interface UpdatePositionParams {
|
||||
name: string;
|
||||
code?: string;
|
||||
departmentId?: number;
|
||||
remark?: string;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
/** 岗位过滤条件 */
|
||||
export interface PositionFilter {
|
||||
name?: string;
|
||||
companyId?: number;
|
||||
departmentId?: number;
|
||||
status?: number;
|
||||
}
|
||||
}
|
||||
|
||||
// 公司管理API
|
||||
export async function getCompanyPageApi(params: PageQuery & { filter?: CompanyApi.CompanyFilter }) {
|
||||
return requestClient.post<PageResult<CompanyApi.CompanyInfo>>('/company/page', params);
|
||||
}
|
||||
|
||||
export async function createCompanyApi(data: CompanyApi.CreateCompanyParams) {
|
||||
return requestClient.post<CompanyApi.CompanyInfo>('/company/create', data);
|
||||
}
|
||||
|
||||
export async function updateCompanyApi(id: number, data: CompanyApi.UpdateCompanyParams) {
|
||||
return requestClient.put<CompanyApi.CompanyInfo>(`/company/update/${id}`, data);
|
||||
}
|
||||
|
||||
export async function deleteCompanyApi(id: number) {
|
||||
return requestClient.delete<void>(`/company/delete/${id}`);
|
||||
}
|
||||
|
||||
// 部门管理API
|
||||
export async function getDepartmentPageApi(params: PageQuery & { filter?: DepartmentApi.DepartmentFilter }) {
|
||||
return requestClient.post<PageResult<DepartmentApi.DepartmentInfo>>('/department/page', params);
|
||||
}
|
||||
|
||||
export async function createDepartmentApi(data: DepartmentApi.CreateDepartmentParams) {
|
||||
return requestClient.post<DepartmentApi.DepartmentInfo>('/department/create', data);
|
||||
}
|
||||
|
||||
export async function updateDepartmentApi(id: number, data: DepartmentApi.UpdateDepartmentParams) {
|
||||
return requestClient.put<DepartmentApi.DepartmentInfo>(`/department/update/${id}`, data);
|
||||
}
|
||||
|
||||
export async function deleteDepartmentApi(id: number) {
|
||||
return requestClient.delete<void>(`/department/delete/${id}`);
|
||||
}
|
||||
|
||||
// 岗位管理API
|
||||
export async function getPositionPageApi(params: PageQuery & { filter?: PositionApi.PositionFilter }) {
|
||||
return requestClient.post<PageResult<PositionApi.PositionInfo>>('/position/page', params);
|
||||
}
|
||||
|
||||
export async function createPositionApi(data: PositionApi.CreatePositionParams) {
|
||||
return requestClient.post<PositionApi.PositionInfo>('/position/create', data);
|
||||
}
|
||||
|
||||
export async function updatePositionApi(id: number, data: PositionApi.UpdatePositionParams) {
|
||||
return requestClient.put<PositionApi.PositionInfo>(`/position/update/${id}`, data);
|
||||
}
|
||||
|
||||
export async function deletePositionApi(id: number) {
|
||||
return requestClient.delete<void>(`/position/delete/${id}`);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import type { UserInfo } from '@vben/types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
export async function getUserInfoApi() {
|
||||
return requestClient.get<UserInfo>('/user/info');
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './core';
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* 该文件可自行根据业务逻辑进行调整
|
||||
*/
|
||||
import type { RequestClientOptions } from '@vben/request';
|
||||
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
import { preferences } from '@vben/preferences';
|
||||
import {
|
||||
authenticateResponseInterceptor,
|
||||
defaultResponseInterceptor,
|
||||
errorMessageResponseInterceptor,
|
||||
RequestClient,
|
||||
} from '@vben/request';
|
||||
import { useAccessStore } from '@vben/stores';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
import { refreshTokenApi } from './core';
|
||||
|
||||
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
|
||||
|
||||
function createRequestClient(baseURL: string, options?: RequestClientOptions) {
|
||||
const client = new RequestClient({
|
||||
...options,
|
||||
baseURL,
|
||||
});
|
||||
|
||||
/**
|
||||
* 重新认证逻辑
|
||||
*/
|
||||
async function doReAuthenticate() {
|
||||
console.warn('Access token or refresh token is invalid or expired. ');
|
||||
const accessStore = useAccessStore();
|
||||
const authStore = useAuthStore();
|
||||
accessStore.setAccessToken(null);
|
||||
if (
|
||||
preferences.app.loginExpiredMode === 'modal' &&
|
||||
accessStore.isAccessChecked
|
||||
) {
|
||||
accessStore.setLoginExpired(true);
|
||||
} else {
|
||||
await authStore.logout();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新token逻辑
|
||||
*/
|
||||
async function doRefreshToken() {
|
||||
const accessStore = useAccessStore();
|
||||
const resp = await refreshTokenApi();
|
||||
const newToken = resp.data;
|
||||
accessStore.setAccessToken(newToken);
|
||||
return newToken;
|
||||
}
|
||||
|
||||
function formatToken(token: null | string) {
|
||||
return token ? `Bearer ${token}` : null;
|
||||
}
|
||||
|
||||
// 请求头处理
|
||||
client.addRequestInterceptor({
|
||||
fulfilled: async (config) => {
|
||||
const accessStore = useAccessStore();
|
||||
|
||||
config.headers.Authorization = formatToken(accessStore.accessToken);
|
||||
config.headers['Accept-Language'] = preferences.app.locale;
|
||||
return config;
|
||||
},
|
||||
});
|
||||
|
||||
// 处理返回的响应数据格式
|
||||
client.addResponseInterceptor(
|
||||
defaultResponseInterceptor({
|
||||
codeField: 'code',
|
||||
dataField: 'data',
|
||||
successCode: 0,
|
||||
}),
|
||||
);
|
||||
|
||||
// token过期的处理
|
||||
client.addResponseInterceptor(
|
||||
authenticateResponseInterceptor({
|
||||
client,
|
||||
doReAuthenticate,
|
||||
doRefreshToken,
|
||||
enableRefreshToken: preferences.app.enableRefreshToken,
|
||||
formatToken,
|
||||
}),
|
||||
);
|
||||
|
||||
// 通用的错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
|
||||
client.addResponseInterceptor(
|
||||
errorMessageResponseInterceptor((msg: string, error) => {
|
||||
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
|
||||
// 当前mock接口返回的错误字段是 error 或者 message
|
||||
const responseData = error?.response?.data ?? {};
|
||||
const errorMessage = responseData?.error ?? responseData?.message ?? '';
|
||||
// 如果没有错误信息,则会根据状态码进行提示
|
||||
message.error(errorMessage || msg);
|
||||
}),
|
||||
);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
export const requestClient = createRequestClient(apiURL, {
|
||||
responseReturn: 'data',
|
||||
});
|
||||
|
||||
export const baseRequestClient = new RequestClient({ baseURL: apiURL });
|
||||
Reference in New Issue
Block a user