App-Android(使用App+htnl5框架,解决消息推送兼容SignalR问题)
loulijun2021
2022-09-18 e5d34f5c51e4a852e67d24709ec7e7b708846066
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
 
/** axios封装
 * 请求拦截、相应拦截、错误统一处理
 */
const httprequest = axios.create({
  baseURL: "http://121.196.36.24:8001/api/",
  //timeout: 1000,
  headers: {
    token: "",
  },
});
 
// 请求拦截器
httprequest.interceptors.request.use(
  function (config) {
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);
 
//响应拦截
httprequest.interceptors.response.use(
// 全局拦截   当code为某数值时 进行拦截
  function (response) {
    const res = response.data;
    //跳转到登录页
    if (res.code === 401) {
      window.location = `${window.logoutUrl}?url=${window.location.origin}`;
    }
    
    if (res.code === '302') {
        // console.log('123')
    }
    
    return response;
  },
  function (error) {
    return Promise.reject(error);
  }
);
 
function get(url, params) {
  return new Promise((resolve, reject) => {
    httprequest
      .get(url, { params: params })
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err.data);
      });
  });
}
// qs.stringify(data)
function post(url, data) {
  return new Promise((resolve, reject) => {
    httprequest
      .post(url, data)
      .then((res) => {
        resolve(res.data);
      })
      .catch((err) => {
        reject(err.data);
      });
  });
}