1
jhzh
2026-01-25 ff5a72344a1e6f762331521342aac691b8d1c905
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*!
 * @author atongmu <zhounianlai@teacher.com.cn>
 * date 11/07/2019
 * description Axios request instantiation.
 */
 
import AxiosReques from "./axios";
import qs from "qs";
import { BASE_URL, BASE_URL2 } from "@/config";
import { getSessionStorage } from "@/utils/utis";
 
let baseUrl = BASE_URL;
let baseUrl2 = BASE_URL2;
if (getSessionStorage("tzlj")) {
  baseUrl = getSessionStorage("tzlj");
}
/**
 * @description Create axios.
 * @param {String} baseUrl Request base url map.
 * @param {Object} headers Request headers config.
 * @param {Boolean} isLoading Request loading switch.
 * @returns axios request instance.
 */
const createAxiosRequest = (baseUrl, headers, isLoading) => {
  return new AxiosReques(baseUrl, headers, isLoading);
};
 
/**
 * @description Axios request params format is JSON.
 * @param {Boolean} isLoading Request loading switch.
 */
const axiosJson = (isLoading) => {
  return createAxiosRequest(
    baseUrl,
    {
      "Content-Type": "application/json;charset=UTF-8",
    },
    isLoading
  );
};
/**
 * @description Axios request params format is JSON.
 * @param {Boolean} isLoading Request loading switch.
 */
const axiosJson2 = (isLoading) => {
  return createAxiosRequest(
    baseUrl2,
    {
      "Content-Type": "application/json;charset=UTF-8",
    },
    isLoading
  );
};
 
/**
 * @description Axios request params format is FromData.
 * @param {Boolean} isLoading Request loading switch.
 */
const axiosForm = (isLoading) => {
  return createAxiosRequest(
    baseUrl,
    {
      "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    },
    isLoading
  );
};
/**
 * @description Axios request params format is multipart.
 * @param {Boolean} isLoading Request loading switch.
 */
const axiosMultipart = (isLoading) => {
  return createAxiosRequest(
    baseUrl,
    {
      "Content-Type": "multipart/form-data;",
    },
    isLoading
  );
};
/**
 * @description Create axios request function.
 * @param {String} axiosType Request function type name, "axiosForm": FormData, "axiosJson": JSON.
 * @param {String} url Request url.
 * @param {String} method Request method type.
 * @param {Boolean} isLoading Request loading whether show.
 * @param {Object} param Request params.
 */
const createAxios = (axiosType, { url, method, isLoading }, params) => {
  const axios = axiosType(isLoading);
  if (method.toLocaleLowerCase() === "get") {
    // var token;
    // if(local.get('token')){
    //     token=local.get('token')
    //     console.log('token',token)
    // }
    return axios.request({
      url,
      params: params ? params : {},
      method,
    });
  } else {
    return axios.request({
      url,
      data: params ? params : {},
      method,
    });
  }
};
 
/**
 * @description Request method of params format is JSON.
 * @param {String} url Request url.
 * @param {String} method Request method type.
 * @param {Boolean} isLoading Request loading whether show.
 * @param {Object} param Request params.
 */
export const httpJson = ({ url, method, isLoading }, params) => {
  return createAxios(axiosJson, { url, method, isLoading }, params);
};
 
/**
 * @description Request method of params format is JSON.
 * @param {String} url Request url.
 * @param {String} method Request method type.
 * @param {Boolean} isLoading Request loading whether show.
 * @param {Object} param Request params.
 */
export const httpJson2 = ({ url, method, isLoading }, params) => {
  return createAxios(axiosJson2, { url, method, isLoading }, params);
};
 
/**
 * @description Request method of params format is FormData.
 * @param {String} url Request url.
 * @param {String} method Request method type.
 * @param {Boolean} isLoading Request loading whether show.
 * @param {Object} param Request params.
 */
export const httpForm = ({ url, method, isLoading }, params) => {
  const resParams =
    method.toLocaleLowerCase() === "get" ? params : qs.stringify(params);
  return createAxios(axiosForm, { url, method, isLoading }, resParams);
};
/**
 * @description Request method of params format is multipart.指定传输数据为二进制数据,主要用于图片、mp3、文件等上传;
 * @param {String} url Request url.
 * @param {String} method Request method type.
 * @param {Boolean} isLoading Request loading whether show.
 * @param {Object} param Request params.
 */
export const httpMultipart = ({ url, method, isLoading }, params) => {
  return createAxios(axiosMultipart, { url, method, isLoading }, params);
};