first commit
This commit is contained in:
111
src/api/all/index.ts
Normal file
111
src/api/all/index.ts
Normal file
@ -0,0 +1,111 @@
|
||||
import Http from '@/api';
|
||||
|
||||
// 导出一个函数,用于获取行业树
|
||||
export const fetchIndustriesTree = (params = {}) => {
|
||||
// 发送GET请求,获取行业树
|
||||
return Http.get('/v1/industries/tree', params);
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取菜单树
|
||||
export const fetchMenusTree = (params = {}) => {
|
||||
// 使用Http.get方法,发送GET请求,获取菜单树
|
||||
return Http.get('/v1/menus/tree', params);
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取行业话题列表
|
||||
export const fetchIndustryTopics = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/industry-topics/list', params);
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取行业话题详情
|
||||
export const fetchIndustryTopicDetail = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/industry-topics/' + params, {});
|
||||
};
|
||||
|
||||
export const fetchindustryTerms = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/industry-terms/list', params);
|
||||
};
|
||||
|
||||
|
||||
// 导出一个函数fetchKeywordTrendsList,用于获取行业话题列表
|
||||
export const fetchKeywordTrendsList = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/industry-keyword-trends/list', params);
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取行业话题列表
|
||||
export const fetchIndustryEmotions = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/industry-emotions', params);
|
||||
};
|
||||
|
||||
export const fetchNewKeywordList = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/industry-new-keywords/list', params);
|
||||
};
|
||||
|
||||
// 导出一个函数fetchUserPainPointsList,用于获取用户痛点列表
|
||||
export const fetchUserPainPointsList = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/user-pain-points/list', params);
|
||||
};
|
||||
|
||||
|
||||
// 导出一个函数fetchUserPainPointsDetail,用于获取用户痛点详情
|
||||
export const fetchUserPainPointsDetail = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/user-pain-points/' + params, {});
|
||||
};
|
||||
|
||||
|
||||
|
||||
// 导出一个函数fetchFocusBrandsList,用于获取行业话题列表
|
||||
export const fetchFocusBrandsList = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/focus-brands/list', params);
|
||||
};
|
||||
|
||||
// 导出一个函数fetchFocusBrandsList,用于获取行业话题列表
|
||||
// 导出一个函数,用于获取行业话题列表
|
||||
export const fetchEventDynamicsList = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取行业话题列表
|
||||
return Http.get('/v1/event-dynamics/list', params);
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取年龄分布列表
|
||||
export const fetchAgeDistributionsList = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取年龄分布列表
|
||||
return Http.get('/v1/age-distributions/list', params);
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取地理分布列表
|
||||
export const fetchGeoDistributionsList = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取地理分布列表
|
||||
return Http.get('/v1/geo-distributions/list', params);
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取性别分布列表
|
||||
export const fetchGenderDistributionsList = (params: any) => {
|
||||
// 使用Http.get方法,发送GET请求,获取性别分布列表
|
||||
return Http.get('/v1/gender-distributions/list', params);
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取产品列表
|
||||
export const fetchProductList = () => {
|
||||
// 使用Http.get方法,发送GET请求,获取产品列表
|
||||
return Http.get('/v1/products/list', {}, { headers: { 'enterprise-id': 1 } });
|
||||
};
|
||||
|
||||
// 导出一个函数,用于获取成功案例列表
|
||||
export const fetchSuccessCaseList = () => {
|
||||
// 使用Http.get方法,发送GET请求,获取成功案例列表
|
||||
return Http.get('/v1/success-cases/list');
|
||||
};
|
||||
|
||||
// 试用产品
|
||||
export const trialProduct = (id: number) => {
|
||||
return Http.post(`/v1/products/${id}/try`, {}, { headers: { 'enterprise-id': 1 } });
|
||||
};
|
||||
36
src/api/apiCodes.ts
Normal file
36
src/api/apiCodes.ts
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* @Author: 田鑫
|
||||
* @Date: 2023-02-17 11:15:23
|
||||
* @LastEditors: 田鑫
|
||||
* @LastEditTime: 2023-02-21 16:25:32
|
||||
* @Description: API状态码
|
||||
*/
|
||||
|
||||
export enum API_STATUS_CODE {
|
||||
/** 正常响应 */
|
||||
SUCCESS = 200,
|
||||
/** 会话失效,请重新登录 */
|
||||
SESSION_FAILUIRE = 1000,
|
||||
/** 认证失败,无法访问系统资源 */
|
||||
AUTH_FAILED = 1001,
|
||||
/** 未授权,无法访问系统资源 */
|
||||
RESOURCE_FORBIDDEN = 1002,
|
||||
/** 黑名单用户 */
|
||||
BLACK_LIST_USER = 1003,
|
||||
/** 非法IP地址 */
|
||||
ILLEGAL_IP = 1004,
|
||||
/** 网关访问受限 */
|
||||
GATEWAY_FORBIDDEN = 1005,
|
||||
/** 网关访问异常,请稍后重试 */
|
||||
GATEWAY_ERROR = 1006,
|
||||
/** 流控异常 */
|
||||
TRAFFIC_CONTROL_ERROR = 1007,
|
||||
/** 资源找不到服务 */
|
||||
RESOURCE_NOT_FOUND = 1008,
|
||||
/** 资源请求超时 */
|
||||
FETCH_TIMEOUT = 1009,
|
||||
/** 资源响应异常 */
|
||||
RESOURCE_RESPONSE_ERROR = 1010,
|
||||
/** 请求路径不符合规范 */
|
||||
ILLEGAL_PATH = 1011,
|
||||
}
|
||||
32
src/api/axiosHandler.ts
Normal file
32
src/api/axiosHandler.ts
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* @Author: 田鑫
|
||||
* @Date: 2023-02-21 16:34:47
|
||||
* @LastEditors: 田鑫
|
||||
* @LastEditTime: 2023-02-21 16:59:10
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
import router from '@/router';
|
||||
import { clearToken } from '@/utils/auth';
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
|
||||
/**
|
||||
* 处理业务逻辑定义的错误code
|
||||
* @param errStatus
|
||||
*/
|
||||
export const handleCodeError = (error: any) => {
|
||||
let errMessage = '未知错误';
|
||||
console.log(error);
|
||||
errMessage = error.msg;
|
||||
switch (error.code) {
|
||||
case 1000:
|
||||
router.replace({
|
||||
name: '/login/password',
|
||||
});
|
||||
clearToken();
|
||||
break;
|
||||
default:
|
||||
errMessage = error.msg || `未知错误-${error.code}`;
|
||||
}
|
||||
Message.error(errMessage);
|
||||
};
|
||||
24
src/api/example/index.ts
Normal file
24
src/api/example/index.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* @Author: 田鑫
|
||||
* @Date: 2023-03-05 18:42:52
|
||||
* @LastEditors: 田鑫
|
||||
* @LastEditTime: 2023-03-05 19:06:13
|
||||
* @Description: 示例api
|
||||
*/
|
||||
|
||||
import Http from '@/api';
|
||||
|
||||
export declare namespace IExample {
|
||||
interface ITableResponse {
|
||||
id: string;
|
||||
column1: string;
|
||||
column2: string;
|
||||
column3: string;
|
||||
column4: string;
|
||||
column5: string;
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchTableData = (params = {}) => {
|
||||
return Http.get<IExample.ITableResponse[]>('/api/example-table', params);
|
||||
};
|
||||
83
src/api/index.ts
Normal file
83
src/api/index.ts
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* @Author: 田鑫
|
||||
* @Date: 2023-02-17 11:58:44
|
||||
* @LastEditors: 田鑫
|
||||
* @LastEditTime: 2023-03-05 19:17:29
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
import axios from 'axios';
|
||||
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
//* 导出Request类,可以用来自定义传递配置来创建实例
|
||||
export class Request {
|
||||
//* axios 实例
|
||||
private instance: AxiosInstance;
|
||||
//* 基础配置
|
||||
private baseConfig: AxiosRequestConfig = { baseURL: import.meta.env.EO_API_URL, timeout: 60000 };
|
||||
|
||||
public constructor(config: AxiosRequestConfig) {
|
||||
this.instance = axios.create(Object.assign(this.baseConfig, config));
|
||||
|
||||
this.instance.interceptors.request.use(
|
||||
(config: AxiosRequestConfig) => {
|
||||
const token = localStorage.getItem('token') as string;
|
||||
if (token) {
|
||||
config.headers!.Authorization = token;
|
||||
} else {
|
||||
config.headers!.satoken = '123';
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(err: any) => {
|
||||
return Promise.reject(err);
|
||||
},
|
||||
);
|
||||
|
||||
this.instance.interceptors.response.use(
|
||||
(res: AxiosResponse) => {
|
||||
//* http请求成功
|
||||
//* 存入通用response header
|
||||
let tenanttype = localStorage.getItem('tenanttype') as string;
|
||||
if (!tenanttype) {
|
||||
tenanttype = res.headers!.tenanttype;
|
||||
localStorage.setItem('tenanttype', tenanttype);
|
||||
}
|
||||
if (res.data.code === 200) {
|
||||
return res.data.data;
|
||||
}
|
||||
AMessage.error(res.data!.msg);
|
||||
return Promise.reject(res.data);
|
||||
},
|
||||
(err: any) => {
|
||||
// AMessage.error(err.message);
|
||||
// 这里用来处理http常见错误,进行全局提示
|
||||
return Promise.reject(err.response);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
//* 定义请求方法
|
||||
public request<T = any>(config: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.request(config);
|
||||
}
|
||||
|
||||
public get<T = any>(url: string, params?: any, config?: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.get(url, { params, ...config });
|
||||
}
|
||||
|
||||
public post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.post(url, data, config);
|
||||
}
|
||||
|
||||
public put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.put(url, data, config);
|
||||
}
|
||||
|
||||
public delete<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> {
|
||||
return this.instance.delete(url, config);
|
||||
}
|
||||
}
|
||||
|
||||
//* 默认导出Request实例
|
||||
export default new Request({});
|
||||
19
src/api/types.d.ts
vendored
Normal file
19
src/api/types.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* @Author: 田鑫
|
||||
* @Date: 2023-02-19 21:52:10
|
||||
* @LastEditors: 田鑫
|
||||
* @LastEditTime: 2023-02-21 16:59:27
|
||||
* @Description:
|
||||
*/
|
||||
import 'axios';
|
||||
|
||||
import { API_STATUS_CODE } from './apiCodes';
|
||||
declare module 'axios' {
|
||||
export interface IWygResponse<T> {
|
||||
success: boolean;
|
||||
msg: string;
|
||||
code: API_STATUS_CODE;
|
||||
data: T;
|
||||
timestamp: number;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user