10.10综合交易所原始源码-管理后台
1
admin
2026-01-27 779dcd060d1f4e15f65fc43022ac9f7b009fc9ef
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import Vue from "vue";
import axios from "axios";
import router from "@/router";
import qs from "qs";
import merge from "lodash/merge";
import MyDialog from "@/components/ipPop/ip-update.vue"; // 导入外部组件
import { clearLoginInfo } from "@/utils";
import { Message } from "element-ui";
import { signatureGenerate } from '@/utils/crypto'
// import store from "@/store";
let dialogInstance = null;
const http = axios.create({
  timeout: 1000 * 30,
  withCredentials: true,
  headers: {
    "Content-Type": "application/json; charset=utf-8",
  },
});
 
/**
 * 请求拦截
 */
http.interceptors.request.use(
  (config) => {
    config.headers["Authorization"] = Vue.cookie.get("Authorization"); // 请求头带上token
 
    const signature = signatureGenerate();
    config.headers["Sign"] = signature.signature;
    config.headers["Systemrandom"] = signature.systemRandom;
    config.headers["Tissuepaper"] = signature.timestamp;
  
    // console.log("config => " + JSON.stringify(config));
 
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);
 
/**
 * 响应拦截
 */
http.interceptors.response.use(
  (response) => {
    if (
      response.data.code == "403" ||
      response.data.code == "401" 
    ) {
      Message({
        message: response.data.msg,
        type: "error",
        duration: 1500,
        customClass: "element-error-message-zindex",
      });
     
      clearLoginInfo();
      router.push({ name: "login" });
      return Promise.reject(response);
    }
    console.log(response.data);
    if (response.data.code == "1001") {
      // 在这里触发弹窗组件
      if (dialogInstance) {
        return false;
      }
      //console.log(3);
      //console.log(store.user);
      // 获取当前路由信息
      const currentRoute = router.currentRoute;
      //console.log(currentRoute);
      if (currentRoute.path == "/") {
        //console.log("qqq");
        document.body.removeChild(dialogInstance.$el);
        return false;
      }
      const DialogConstructor = Vue.extend(MyDialog);
      dialogInstance = new DialogConstructor();
      dialogInstance.$mount();
      // 监听弹窗关闭事件
      // dialogInstance.$on("close", () => {
      //   console.log("qqq");
      //   document.body.removeChild(dialogInstance.$el);
      // });
 
      // 将弹窗组件实例挂载到页面中
      document.body.appendChild(dialogInstance.$el);
      return Promise.reject(error);
    }
    return response;
  },
  (error) => {
    if (!error.response) {
      console.log("error = " + JSON.stringify(error));
    }
    switch (error.response.status) {
      case 400:
        Message({
          message: error.response.data,
          type: "error",
          duration: 1500,
          customClass: "element-error-message-zindex",
        });
        break;
      case 401:
        clearLoginInfo();
        router.push({ name: "login" });
        console.log(1);
        if (dialogInstance) {
          console.log(2);
          document.body.removeChild(dialogInstance.$el);
        }
        break;
      case 405:
        Message({
          message: "http请求方式有误",
          type: "error",
          duration: 1500,
          customClass: "element-error-message-zindex",
        });
        break;
      case 500:
        Message({
          message: "服务器出了点小差,请稍后再试",
          type: "error",
          duration: 1500,
          customClass: "element-error-message-zindex",
        });
        break;
      case 501:
        Message({
          message: "服务器不支持当前请求所需要的某个功能",
          type: "error",
          duration: 1500,
          customClass: "element-error-message-zindex",
        });
        break;
    }
    return Promise.reject(error);
  }
);
 
/**
 * 请求地址处理
 * @param {*} actionName action方法名称
 */
http.adornUrl = (actionName) => {
  // 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
  return (process.env.NODE_ENV !== 'production' && process.env.OPEN_PROXY ? '/proxyApi' : process.env.VUE_APP_BASE_API) + actionName
}
 
/**
 * get请求参数处理
 * @param {*} params 参数对象
 * @param {*} openDefultParams 是否开启默认参数?
 */
http.adornParams = (params = {}, openDefultParams = true) => {
  var defaults = {
    t: new Date().getTime(),
  };
  return openDefultParams ? merge(defaults, params) : params;
};
 
/**
 * post请求数据处理
 * @param {*} data 数据对象
 * @param {*} openDefultdata 是否开启默认数据?
 * @param {*} contentType 数据格式
 *  json: 'application/json; charset=utf-8'
 *  form: 'application/x-www-form-urlencoded; charset=utf-8'
 */
http.adornData = (data = {}, openDefultdata = true, contentType = "json") => {
  var defaults = {
    t: new Date().getTime(),
  };
  data = openDefultdata ? merge(defaults, data) : data;
  return contentType === "json" ? JSON.stringify(data) : qs.stringify(data);
};
 
export default http;