forked from huge/frontEnd/hugeDyh2.0

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
/*
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-02-16 11:28:12
 * @LastEditTime: 2022-02-17 11:18:51
 * @LastEditors: ldh
 * @Version: 1.0.0
 * @Description: axios处理方法
 */
import axios from 'axios';
import appUrl from './appUrl';
 
export const ax = axios;
 
export function request(value = {}) {
    let local = localStorage.getItem('operationToken');
 
    let token = !local ? null : JSON.parse(local);
 
  // 无token时
    if (!token) {
        return {};
    }
 
    axios.defaults.baseURL = appUrl.web;
 
    axios.defaults.headers.common['Authorization'] = token;
 
    if (value.type == 'get') {
        return ax
            .get(value.url, { params: value.data })
            .then((response) => {
                return response;
            })
            .catch(() => {
                return {};
            });
    } else {
        return ax
            .post(value.url, value.data)
            .then((response) => {
                return response;
            })
            .catch(() => {
                return {};
            });
    }
}