1234567891011121314151617181920212223242526272829303132333435363738 |
- import {httpApi} from "@/common/js/baseUrl";
- import {handleHttpError, handleNormalResponse} from "@/utils/fetch/responseHandler";
- import handleReqLoading from "@/utils/fetch/handleReqLoading";
- import {handleRequest} from "@/utils/fetch/requestHandler";
- /**
- * 封装请求
- * @param url 请求地址
- * @param type 请求方式
- * @param data 请求参数
- * @param dataType 请求数据类型
- */
- export const myFetch = async (url, type = "get", data = {}, dataType) => {
- const reqConfig = {
- url: httpApi + url,
- method: type,
- data: data,
- dataType: dataType,
- timeout: 60000,
- header: {
- 'content-type': 'application/json',
- Token: '1',
- appId:'2002407848',
- },
- }
- try {
- handleReqLoading(true,dataType);
- const response = await handleRequest(reqConfig);
- const responseData = handleNormalResponse(response);
- handleReqLoading(false,dataType);
- //返回一个promise对象
- return responseData;
- }catch (err) {
- handleReqLoading(false,dataType);
- return handleHttpError(err);
- }
- }
|