feat: 本次提交更新内容如下
新项目模板初始化
This commit is contained in:
22
nkebao/src/api/module/auth.ts
Normal file
22
nkebao/src/api/module/auth.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { request } from '@/api/request';
|
||||
|
||||
export const list = (data?: any) =>
|
||||
request('/cw/companyUser/list', data, 'GET');
|
||||
|
||||
export const joinAudit = (data: any) =>
|
||||
request('/cw/companyUser/joinAudit', data, 'PUT');
|
||||
|
||||
export const listJoinAudit = (data?: any) =>
|
||||
request('/cw/companyUser/listJoinAudit', data, 'GET');
|
||||
|
||||
export const CwCompanyUserApplyAdd = (data: any) =>
|
||||
request('/cw/CwCompanyUserApply/add', data, 'PUT');
|
||||
|
||||
export const CwCompanyUserApplyAdminList = (data?: any) =>
|
||||
request('/cw/CwCompanyUserApply/adminList', data, 'GET');
|
||||
|
||||
export const CwCompanyUserApplyAudit = (data: any) =>
|
||||
request('/cw/CwCompanyUserApply/audit', data, 'POST');
|
||||
|
||||
export const CwCompanyUserApplyUserList = (data?: any) =>
|
||||
request('/cw/CwCompanyUserApply/userList', data, 'GET');
|
||||
64
nkebao/src/api/request.ts
Normal file
64
nkebao/src/api/request.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, Method, AxiosResponse } from 'axios';
|
||||
|
||||
const DEBOUNCE_GAP = 1000;
|
||||
const debounceMap = new Map<string, number>();
|
||||
|
||||
const instance: AxiosInstance = axios.create({
|
||||
baseURL: (import.meta as any).env?.VITE_API_BASE_URL || '/api',
|
||||
timeout: 10000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
instance.interceptors.request.use(config => {
|
||||
const token = localStorage.getItem('token');
|
||||
if (token) {
|
||||
config.headers = config.headers || {};
|
||||
config.headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
instance.interceptors.response.use(
|
||||
(res: AxiosResponse) => {
|
||||
if (res.data && (res.data.code === 200 || res.data.success)) {
|
||||
return res.data.data ?? res.data;
|
||||
}
|
||||
window?.alert?.(res.data?.msg || '接口错误');
|
||||
return Promise.reject(res.data?.msg || '接口错误');
|
||||
},
|
||||
err => {
|
||||
window?.alert?.(err.message || '网络异常');
|
||||
return Promise.reject(err);
|
||||
}
|
||||
);
|
||||
|
||||
export function request(
|
||||
url: string,
|
||||
data?: any,
|
||||
method: Method = 'GET',
|
||||
config?: AxiosRequestConfig
|
||||
): Promise<any> {
|
||||
const key = `${method}_${url}_${JSON.stringify(data)}`;
|
||||
const now = Date.now();
|
||||
const last = debounceMap.get(key) || 0;
|
||||
if (now - last < DEBOUNCE_GAP) {
|
||||
return Promise.reject('请求过于频繁,请稍后再试');
|
||||
}
|
||||
debounceMap.set(key, now);
|
||||
|
||||
const axiosConfig: AxiosRequestConfig = {
|
||||
url,
|
||||
method,
|
||||
...config,
|
||||
};
|
||||
if (method.toUpperCase() === 'GET') {
|
||||
axiosConfig.params = data;
|
||||
} else {
|
||||
axiosConfig.data = data;
|
||||
}
|
||||
return instance(axiosConfig);
|
||||
}
|
||||
|
||||
export default request;
|
||||
Reference in New Issue
Block a user