|  | @@ -1,45 +1,48 @@
 | 
	
		
			
				|  |  | -import ElementUI from 'element-ui'
 | 
	
		
			
				|  |  | -import axios from 'axios'
 | 
	
		
			
				|  |  | -import { Message } from 'element-ui'
 | 
	
		
			
				|  |  | -import store from '@/store'
 | 
	
		
			
				|  |  | -import qs from 'querystring'
 | 
	
		
			
				|  |  | -import { getToken,removeToken } from '@/utils/auth'
 | 
	
		
			
				|  |  | -import cleanDeep from 'clean-deep'
 | 
	
		
			
				|  |  | +import ElementUI from "element-ui";
 | 
	
		
			
				|  |  | +import axios from "axios";
 | 
	
		
			
				|  |  | +import { Message } from "element-ui";
 | 
	
		
			
				|  |  | +import store from "@/store";
 | 
	
		
			
				|  |  | +import qs from "querystring";
 | 
	
		
			
				|  |  | +import { getToken, removeToken } from "@/utils/auth";
 | 
	
		
			
				|  |  | +import cleanDeep from "clean-deep";
 | 
	
		
			
				|  |  |  // import { Loading } from 'element-ui'
 | 
	
		
			
				|  |  | -import { showFullScreenLoading, tryHideFullScreenLoading } from './request-loading'
 | 
	
		
			
				|  |  | -import router from '@/router/index'
 | 
	
		
			
				|  |  | -import Vue from 'vue'
 | 
	
		
			
				|  |  | -const showMessage = Symbol('showMessage')
 | 
	
		
			
				|  |  | +import {
 | 
	
		
			
				|  |  | +  showFullScreenLoading,
 | 
	
		
			
				|  |  | +  tryHideFullScreenLoading
 | 
	
		
			
				|  |  | +} from "./request-loading";
 | 
	
		
			
				|  |  | +import router from "@/router/index";
 | 
	
		
			
				|  |  | +import Vue from "vue";
 | 
	
		
			
				|  |  | +const showMessage = Symbol("showMessage");
 | 
	
		
			
				|  |  |  class DonMessage {
 | 
	
		
			
				|  |  | -  success (options, single = true) {
 | 
	
		
			
				|  |  | -    this[showMessage]('success', options, single)
 | 
	
		
			
				|  |  | +  success(options, single = true) {
 | 
	
		
			
				|  |  | +    this[showMessage]("success", options, single);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  warning (options, single = true) {
 | 
	
		
			
				|  |  | -    this[showMessage]('warning', options, single)
 | 
	
		
			
				|  |  | +  warning(options, single = true) {
 | 
	
		
			
				|  |  | +    this[showMessage]("warning", options, single);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  info (options, single = true) {
 | 
	
		
			
				|  |  | -    this[showMessage]('info', options, single)
 | 
	
		
			
				|  |  | +  info(options, single = true) {
 | 
	
		
			
				|  |  | +    this[showMessage]("info", options, single);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  error (options, single = true) {
 | 
	
		
			
				|  |  | -    this[showMessage]('error', options, single)
 | 
	
		
			
				|  |  | +  error(options, single = true) {
 | 
	
		
			
				|  |  | +    this[showMessage]("error", options, single);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  [showMessage] (type, options, single) {
 | 
	
		
			
				|  |  | +  [showMessage](type, options, single) {
 | 
	
		
			
				|  |  |      if (single) {
 | 
	
		
			
				|  |  |        // 判断是否已存在Message
 | 
	
		
			
				|  |  | -      if (document.getElementsByClassName('el-message').length === 0) {
 | 
	
		
			
				|  |  | -        Message[type](options)
 | 
	
		
			
				|  |  | +      if (document.getElementsByClassName("el-message").length === 0) {
 | 
	
		
			
				|  |  | +        Message[type](options);
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      } else {
 | 
	
		
			
				|  |  | -      Message[type](options)
 | 
	
		
			
				|  |  | +      Message[type](options);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -Vue.use(ElementUI)
 | 
	
		
			
				|  |  | +Vue.use(ElementUI);
 | 
	
		
			
				|  |  |  // 命名根据需要,DonMessage只是在文章中使用
 | 
	
		
			
				|  |  | -Vue.prototype.$message = new DonMessage()
 | 
	
		
			
				|  |  | +Vue.prototype.$message = new DonMessage();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -let vue = new Vue()
 | 
	
		
			
				|  |  | +let vue = new Vue();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // let loading        //定义loading变量
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -59,63 +62,62 @@ let vue = new Vue()
 | 
	
		
			
				|  |  |  //声明一个变量 needLoadingRequestCount,每次调用showFullScreenLoading方法 needLoadingRequestCount + 1。
 | 
	
		
			
				|  |  |  //调用tryHideFullScreenLoading()方法,needLoadingRequestCount - 1。needLoadingRequestCount为 0 时,结束 loading。
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  // axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  // create an axios instance
 | 
	
		
			
				|  |  |  const service = axios.create({
 | 
	
		
			
				|  |  | -  baseURL: '', // url = base url + request url
 | 
	
		
			
				|  |  | +  baseURL: "", // url = base url + request url
 | 
	
		
			
				|  |  |    // withCredentials: true, // send cookies when cross-domain requests
 | 
	
		
			
				|  |  | -  timeout: 180000, // request timeout
 | 
	
		
			
				|  |  | -})
 | 
	
		
			
				|  |  | +  timeout: 180000 // request timeout
 | 
	
		
			
				|  |  | +});
 | 
	
		
			
				|  |  |  // { fullscreen: true, text: '努力加载中', spinner: 'el-icon-loading' }
 | 
	
		
			
				|  |  |  // request interceptor
 | 
	
		
			
				|  |  |  service.interceptors.request.use(
 | 
	
		
			
				|  |  | - async config => {
 | 
	
		
			
				|  |  | +  async config => {
 | 
	
		
			
				|  |  |      // do something before request is sent
 | 
	
		
			
				|  |  | -    let hideLoading = config.hideLoading || false
 | 
	
		
			
				|  |  | -    if(!hideLoading) {
 | 
	
		
			
				|  |  | -      await showFullScreenLoading(store)
 | 
	
		
			
				|  |  | +    let hideLoading = config.hideLoading || false;
 | 
	
		
			
				|  |  | +    if (!hideLoading) {
 | 
	
		
			
				|  |  | +      await showFullScreenLoading(store);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      if (store.getters.token) {
 | 
	
		
			
				|  |  |        // let each request carry token
 | 
	
		
			
				|  |  |        // ['X-Token'] is a custom headers key
 | 
	
		
			
				|  |  |        // please modify it according to the actual situation
 | 
	
		
			
				|  |  | -      config.headers['Authorization'] = getToken()
 | 
	
		
			
				|  |  | +      config.headers["Authorization"] = getToken();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      // const tenantStatus = config.data?.tenantStatus || config.params?.tenantStatus || null
 | 
	
		
			
				|  |  | -    let tenantConfig = sessionStorage.getItem('tenantConfig')
 | 
	
		
			
				|  |  | -    tenantConfig = tenantConfig ? JSON.parse(tenantConfig) : {}
 | 
	
		
			
				|  |  | -    if(tenantConfig.tenantId && tenantConfig.tenantId != 'undefined') {
 | 
	
		
			
				|  |  | -      config.headers['tenantId'] = tenantConfig.tenantId
 | 
	
		
			
				|  |  | +    let tenantConfig = sessionStorage.getItem("tenantConfig");
 | 
	
		
			
				|  |  | +    tenantConfig = tenantConfig ? JSON.parse(tenantConfig) : {};
 | 
	
		
			
				|  |  | +    if (tenantConfig.tenantId && tenantConfig.tenantId != "undefined") {
 | 
	
		
			
				|  |  | +      config.headers["tenantId"] = tenantConfig.tenantId;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      // 是否进行数据过滤
 | 
	
		
			
				|  |  | -    const noCleanDeep = config.noCleanDeep || false
 | 
	
		
			
				|  |  | -    if (config.requestType === 'form') {
 | 
	
		
			
				|  |  | -      config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
 | 
	
		
			
				|  |  | -      config.data = qs.stringify(noCleanDeep ? config.data : cleanDeep(config.data))
 | 
	
		
			
				|  |  | +    const noCleanDeep = config.noCleanDeep || false;
 | 
	
		
			
				|  |  | +    if (config.requestType === "form") {
 | 
	
		
			
				|  |  | +      config.headers["Content-Type"] = "application/x-www-form-urlencoded";
 | 
	
		
			
				|  |  | +      config.data = qs.stringify(
 | 
	
		
			
				|  |  | +        noCleanDeep ? config.data : cleanDeep(config.data)
 | 
	
		
			
				|  |  | +      );
 | 
	
		
			
				|  |  |      } else {
 | 
	
		
			
				|  |  | -      config.data = noCleanDeep ? config.data : cleanDeep(config.data)
 | 
	
		
			
				|  |  | +      config.data = noCleanDeep ? config.data : cleanDeep(config.data);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    config.params = noCleanDeep ? config.data : cleanDeep(config.params)
 | 
	
		
			
				|  |  | -    return config
 | 
	
		
			
				|  |  | +    config.params = noCleanDeep ? config.data : cleanDeep(config.params);
 | 
	
		
			
				|  |  | +    return config;
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  | -async  error => {
 | 
	
		
			
				|  |  | +  async error => {
 | 
	
		
			
				|  |  |      // do something with request error
 | 
	
		
			
				|  |  | -  await  tryHideFullScreenLoading(store)
 | 
	
		
			
				|  |  | -    return Promise.reject(error)
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    await tryHideFullScreenLoading(store);
 | 
	
		
			
				|  |  | +    return Promise.reject(error);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -)
 | 
	
		
			
				|  |  | +);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  // response interceptor
 | 
	
		
			
				|  |  |  service.interceptors.response.use(
 | 
	
		
			
				|  |  | -async  res => {
 | 
	
		
			
				|  |  | +  async res => {
 | 
	
		
			
				|  |  |      //res.code !== 200
 | 
	
		
			
				|  |  | -  await  tryHideFullScreenLoading(store)
 | 
	
		
			
				|  |  | +    await tryHideFullScreenLoading(store);
 | 
	
		
			
				|  |  |      if (res.data.code) {
 | 
	
		
			
				|  |  | -      let data = JSON.parse(JSON.stringify(res.data))
 | 
	
		
			
				|  |  | +      let data = JSON.parse(JSON.stringify(res.data));
 | 
	
		
			
				|  |  |        // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
 | 
	
		
			
				|  |  |        if (data.code == 401 || data.code == 403) {
 | 
	
		
			
				|  |  |          // Message({
 | 
	
	
		
			
				|  | @@ -124,49 +126,51 @@ async  res => {
 | 
	
		
			
				|  |  |          //   duration: 5 * 1000
 | 
	
		
			
				|  |  |          // })
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        vue.$message.error(`登录过期,请重新登录!`)
 | 
	
		
			
				|  |  | -        setToken('')
 | 
	
		
			
				|  |  | -        removeToken()
 | 
	
		
			
				|  |  | -        setTimeout(() => {
 | 
	
		
			
				|  |  | +        vue.$message.error(`登录过期,请重新登录!`);
 | 
	
		
			
				|  |  | +        setToken("");
 | 
	
		
			
				|  |  | +        removeToken();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        store.dispatch("user/resetToken").then(() => {
 | 
	
		
			
				|  |  | +          setTimeout(() => {
 | 
	
		
			
				|  |  | +            location.reload();
 | 
	
		
			
				|  |  | +          }, 1000);
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -          store.dispatch('user/resetToken').then(() => {
 | 
	
		
			
				|  |  | -            location.reload()
 | 
	
		
			
				|  |  | -          })
 | 
	
		
			
				|  |  | -        }, 1000);
 | 
	
		
			
				|  |  |          return;
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |        if (data.code == 404) {
 | 
	
		
			
				|  |  | -        router.push('/404')
 | 
	
		
			
				|  |  | +        router.push("/404");
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  | -      if (data.code < 200&&data.code != 100||data.code >= 300&&data.code != 100) {
 | 
	
		
			
				|  |  | +      if (
 | 
	
		
			
				|  |  | +        (data.code < 200 && data.code != 100) ||
 | 
	
		
			
				|  |  | +        (data.code >= 300 && data.code != 100)
 | 
	
		
			
				|  |  | +      ) {
 | 
	
		
			
				|  |  |          // Message({
 | 
	
		
			
				|  |  |          //   message: data.msg || `请求失败code码为${ data.code }`,
 | 
	
		
			
				|  |  |          //   type: 'error',
 | 
	
		
			
				|  |  |          //   duration: 5 * 1000
 | 
	
		
			
				|  |  |          // })
 | 
	
		
			
				|  |  | -        let str = data.msg || `请求失败code码为${data.code}`
 | 
	
		
			
				|  |  | +        let str = data.msg || `请求失败code码为${data.code}`;
 | 
	
		
			
				|  |  |          if (res.config.hint !== true) {
 | 
	
		
			
				|  |  | -          vue.$message.error(str)
 | 
	
		
			
				|  |  | +          vue.$message.error(str);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        return Promise.reject(data)
 | 
	
		
			
				|  |  | +        return Promise.reject(data);
 | 
	
		
			
				|  |  |        } else {
 | 
	
		
			
				|  |  | -        return data
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +        return data;
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      } else {
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -      return Promise.reject()
 | 
	
		
			
				|  |  | +      return Promise.reject();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  | - async error => {
 | 
	
		
			
				|  |  | -    if (error.message == 'Network Error') {
 | 
	
		
			
				|  |  | -      vue.$message.error('网络异常,请检查网络连接')
 | 
	
		
			
				|  |  | +  async error => {
 | 
	
		
			
				|  |  | +    if (error.message == "Network Error") {
 | 
	
		
			
				|  |  | +      vue.$message.error("网络异常,请检查网络连接");
 | 
	
		
			
				|  |  |      } else {
 | 
	
		
			
				|  |  | -      vue.$message.error(error.message)
 | 
	
		
			
				|  |  | +      vue.$message.error(error.message);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -   await tryHideFullScreenLoading(store)
 | 
	
		
			
				|  |  | -    return Promise.reject(error)
 | 
	
		
			
				|  |  | +    await tryHideFullScreenLoading(store);
 | 
	
		
			
				|  |  | +    return Promise.reject(error);
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -)
 | 
	
		
			
				|  |  | -export default service
 | 
	
		
			
				|  |  | +);
 | 
	
		
			
				|  |  | +export default service;
 |