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
| import axios from "axios";
| import { globalState } from '../config.js'
|
| const instance = axios.create({
| baseURL: '',
| timeout: 120000,
| })
|
| export const get = async (url, params) => {
| if (params?.condition != null && params?.condition != undefined && params?.condition != "") {
| params.current = 1
| }
| if (params?._param != null && params?._param != undefined && hasNonEmptyProperty(params?._param)) {
| data.current = 1
| }
|
| return instance({
| url: url,
| method: 'get',
| params: params,
| headers: {
| Authorization: globalState.token
| }
| })
| }
|
| function hasNonEmptyProperty(obj) {
| return Object.values(obj).some(value => {
| // 定义何为"不为空" - 根据需求调整
| return value !== null && value !== undefined && value !== '';
| });
| }
|
| export const post = async (url, data) => {
| if (data?.condition != null && data?.condition != undefined && data?.condition != "") {
| data.current = 1
| }
| if (data._param != null && data._param != undefined && hasNonEmptyProperty(data?._param)) {
| data.current = 1
| }
| return instance({
| url: url,
| method: 'post',
| data: data,
| headers: {
| Authorization: globalState.token
| }
| })
| }
|
| export const postBlob = async (url, data) => {
| return instance({
| url: url,
| method: 'post',
| data: data,
| headers: {
| Authorization: globalState.token
| },
| responseType: 'blob'
| })
| }
|
| export const postForm = async (url, params) => {
| return instance({
| url: url,
| method: 'post',
| data: params,
| headers: {
| Authorization: globalState.token,
| 'Content-Type': 'multipart/form-data'
| }
| })
| }
|
| export default instance;
|
|