浏览代码

删除文件

wangguoyu 6 月之前
父节点
当前提交
a8dface0f1
共有 2 个文件被更改,包括 0 次插入251 次删除
  1. 0 178
      utils/request copy 1.js
  2. 0 73
      utils/request copy.js

+ 0 - 178
utils/request copy 1.js

@@ -1,178 +0,0 @@
-import axios     from 'axios';
-import { Md5 }   from 'ts-md5/dist/md5';
-import config from '@/config'
-let noTimeoutLimitArr = [
-
-];
-
-// create an axios instance
-const service = axios.create({
-                                 baseURL:         config.baseUrl, // url = base url + request url
-                                 withCredentials: false, // send cookies when cross-domain requests
-                                 timeout:         20000, // request timeout
-                             });
-
-export let needLoadingRequestCount = 0;
-export function showFullScreenLoading(config) {
-    if (needLoadingRequestCount === 0) {
-        store.state.isLoading = true
-    }
-    needLoadingRequestCount++;
-}
-
-export function tryHideFullScreenLoading() {
-    if (needLoadingRequestCount <= 0) {
-        return;
-    }
-
-    needLoadingRequestCount--;
-    if (needLoadingRequestCount === 0) {
-        store.state.isLoading = false
-    }
-}
-// request interceptor
-service.interceptors.request.use(
-    config => {
-        // do something before request is sent
-        // console.log(config);
-
-        function setTimeoutunlimit(config) {
-            // if (_.indexOf(noTimeoutLimitArr, config.url) > -1) {
-            //     config.timeout = 9999999999;
-            // }
-        }
-
-        function mixSignAndToken(config) {
-		//	debugger
-            // console.log(config.data, process.env.VUE_APP_BASE_API, process.env.VUE_APP_SECRET_KEY);
-            const checkurl = function (url) {
-                if (url === '/common/active') {
-                    return false;
-                }
-                // 用户端白名单
-                if (url.indexOf('/common') > -1) {
-                    return true;
-                }
-                // 管理端白名单
-                if (url === '/admin/user/auth') {
-                    return true;
-                }
-                // 短信服务白名单
-                if (url === 'sms/sendCode') {
-                    return true;
-                }
-                return false;
-            };
-			
-            if (checkurl(config.url)) {
-                if(config.url.indexOf('/open' >-1)){
-                }else {
-                    config.headers['X-AUTH-SIGN'] = Md5.hashStr(JSON.stringify(config.data) + '123');
-                }
-            } else {
-                if (store.state.auth) {
-                    config.headers['X-AUTH-SIGN'] = Md5.hashStr(JSON.stringify(config.data) + store.state.auth.secret);
-                    config.headers['X-AUTH-TOKEN'] = store.state.auth.token;
-                } else {
-                    // 非登录操作,但没有auth,跳转登录
-                    router.push('/' + store.state.tenantCode + '/login');
-                }
-            }
-
-        }
-        // if (!JSON.stringify(config.data.customLoadingSwitch)) {
-        //     //  如不需要在data中 LoadingSwitch:false
-        //     console.log('有loading');
-        //     showFullScreenLoading(config);
-        // }
-        mixSignAndToken(config);
-        setTimeoutunlimit(config);
-
-        /*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['X-Token'] = getToken();
-        }*/
-        return config;
-    },
-    error => {
-        // do something with request error
-        // console.log(error); // for debug
-        return Promise.reject(error);
-    },
-);
-
-
-
-// response interceptor
-service.interceptors.response.use(
-    /**
-     * If you want to get http information such as headers or status
-     * Please return  response => response
-     */
-
-    /**
-     * Determine the request status by custom code
-     * Here is just an example
-     * You can also judge the status by HTTP Status Code
-     */
-    response => {
-        const res = response.data;
-
-        // if the custom code is not 20000, it is judged as an error.
-        if (res.code !== 0) {
-    
-            // 401:登录超时
-            if (res.code === 401) {
-                setTimeout(function () {
-                    if (window.loading) {
-                        window.loading.close();
-                    }
-                    // console.log(router);
-                    /*if (router.app.$route.path.indexOf('/c/') === 0) {
-                        router.push('/c/' + store.state.tenantCode + '/login');
-                    } else {
-                        router.push('/a/' + store.state.tenantCode + '/login');
-                    }*/
-                    store.state.showBottomNav = true;
-                    router.push('/login');
-                }, 2000);
-            }
-            if (res.code === 405) {
-                setTimeout(function () {
-                    if (window.loading) {
-                        window.loading.close();
-                    }
-                    store.state.showBottomNav = true;
-                    router.push('/login');
-                }, 2000);
-            }
-
-            if (res.code === 502) {
-            //    Toast.fail('bad gateway');
-            }
-            if (res.code === 500 || res.code === 1001|| res.code ===1002) {
-                tryHideFullScreenLoading();
-                return Promise.reject('error' + res.code + '-' + (res.message === undefined ? 'nomessage': res.message));
-            }
-            tryHideFullScreenLoading();
-            return Promise.reject(res.message || 'error');
-        } else {
-            tryHideFullScreenLoading();
-            return res;
-        }
-    },
-    error => {
-
-        if (error == 'Error: Network Error') {
-        //    Toast.fail('网络断开,请检查网络');
-        } else {
-         //   Toast.fail('其他错误,请联系管理员');
-        }
-        tryHideFullScreenLoading();
-        return Promise.reject(error);
-    },
-);
-
-export default service;

+ 0 - 73
utils/request copy.js

@@ -1,73 +0,0 @@
-import store from '@/store'
-import config from '@/config'
-import { getToken } from '@/utils/auth'
-import errorCode from '@/utils/errorCode'
-import { toast, showConfirm, tansParams } from '@/utils/common'
-
-let timeout = 10000
-const baseUrl = config.baseUrl
-
-const request = config => {
-  // 是否需要设置 token
-  const isToken = (config.headers || {}).isToken === false
-  config.header = config.header || {}
-  if (getToken() && !isToken) {
-    config.header['Authorization'] = 'Bearer ' + getToken()
-  }
-  // get请求映射params参数
-  if (config.params) {
-    let url = config.url + '?' + tansParams(config.params)
-    url = url.slice(0, -1)
-    config.url = url
-  }
-  return new Promise((resolve, reject) => {
-    uni.request({
-        method: config.method || 'get',
-        timeout: config.timeout ||  timeout,
-        url: config.baseUrl || baseUrl + config.url,
-        data: config.data,
-        header: config.header,
-        dataType: 'json'
-      }).then(response => {
-        let [error, res] = response
-        if (error) {
-          toast('后端接口连接异常')
-          reject('后端接口连接异常')
-          return
-        }
-        const code = res.data.code || 200
-        const msg = errorCode[code] || res.data.msg || errorCode['default']
-        if (code === 401) {
-          showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
-            if (res.confirm) {
-              store.dispatch('LogOut').then(res => {
-                uni.reLaunch({ url: '/pages/login' })
-              })
-            }
-          })
-          reject('无效的会话,或者会话已过期,请重新登录。')
-        } else if (code === 500) {
-          toast(msg)
-          reject('500')
-        } else if (code !== 200) {
-          toast(msg)
-          reject(code)
-        }
-        resolve(res.data)
-      })
-      .catch(error => {
-        let { message } = error
-        if (message === 'Network Error') {
-          message = '后端接口连接异常'
-        } else if (message.includes('timeout')) {
-          message = '系统接口请求超时'
-        } else if (message.includes('Request failed with status code')) {
-          message = '系统接口' + message.substr(message.length - 3) + '异常'
-        }
-        toast(message)
-        reject(error)
-      })
-  })
-}
-
-export default request