Browse Source

修改环境

Rorschach 6 years ago
parent
commit
2b0ebe3b50
2 changed files with 133 additions and 1 deletions
  1. 132 0
      .history/src/utils/http_20190327105041.js
  2. 1 1
      src/utils/http.js

+ 132 - 0
.history/src/utils/http_20190327105041.js

@@ -0,0 +1,132 @@
+import axios from 'axios';
+// import Cookies from "js-cookie";
+import {
+    Message
+} from 'element-ui';
+
+axios.defaults.timeout = 5000;
+axios.defaults.baseURL = 'http://manage.ai160.com/';
+
+/*** 
+ * 
+ * 复制于 https://www.cnblogs.com/ldlx-mars/p/7908950.html
+ * 
+*/
+
+//http request 拦截器
+axios.interceptors.request.use(
+    config => {
+        // const token = Cookies('token'); //注意使用的时候需要引入cookie方法,推荐js-cookie
+        config.data = JSON.stringify(config.data);
+        const uid = sessionStorage.getItem('uid') ? sessionStorage.getItem('uid') : '';
+        config.headers = {
+            'Content-Type': 'application/json',
+            'uid': uid,
+        }
+        // if(token){
+        //   config.params = {'X-Token':token}
+        // }
+        return config;
+    },
+    error => {
+        return Promise.reject(err);
+    }
+);
+
+//http response 拦截器 暂时不用
+axios.interceptors.response.use(
+    response => {
+        if (response.data.code == 402) {
+            // router.push({
+            //     path: "/login",
+            //     // querry: {
+            //     //     redirect: Router.currentRoute.fullPath
+            //     // } //从哪个页面跳转
+            // })
+            Message.warning({
+                message: '请登录',
+                type: 'warning'
+              });
+            window.location.href = '/manageWeb/'
+        }
+        return response;
+    },
+    error => {
+        return Promise.reject(error)
+    }
+)
+
+/**
+ * 封装get方法
+ * @param url
+ * @param data
+ * @returns {Promise}
+ */
+
+export function fetch(url, params = {}) {
+    return new Promise((resolve, reject) => {
+        axios.get(url, {
+                params: params
+            })
+            .then(response => {
+                resolve(response.data);
+            })
+            .catch(err => {
+                reject(err)
+            })
+    })
+}
+
+/**
+ * 封装post请求
+ * @param url
+ * @param data
+ * @returns {Promise}
+ */
+
+export function post(url, data = {}) {
+    return new Promise((resolve, reject) => {
+        axios.post(url, data)
+            .then(response => {
+                resolve(response.data);
+            }, err => {
+                reject(err)
+            })
+    })
+}
+
+/**
+ * 封装patch请求
+ * @param url
+ * @param data
+ * @returns {Promise}
+ */
+
+export function patch(url, data = {}) {
+    return new Promise((resolve, reject) => {
+        axios.patch(url, data)
+            .then(response => {
+                resolve(response.data);
+            }, err => {
+                reject(err)
+            })
+    })
+}
+
+/**
+ * 封装put请求
+ * @param url
+ * @param data
+ * @returns {Promise}
+ */
+
+export function put(url, data = {}) {
+    return new Promise((resolve, reject) => {
+        axios.put(url, data)
+            .then(response => {
+                resolve(response.data);
+            }, err => {
+                reject(err)
+            })
+    })
+}

+ 1 - 1
src/utils/http.js

@@ -5,7 +5,7 @@ import {
 } from 'element-ui';
 
 axios.defaults.timeout = 5000;
-axios.defaults.baseURL = 'http://whiteboardtest.ai160.com/';
+axios.defaults.baseURL = 'http://manage.ai160.com/';
 
 /*** 
  *