gyf vor 3 Monaten
Ursprung
Commit
795f38a694
4 geänderte Dateien mit 266 neuen und 0 gelöschten Zeilen
  1. 2 0
      src/api/qc.js
  2. 103 0
      src/utils/request_api.js
  3. 103 0
      src/utils/request_bazb.js
  4. 58 0
      src/utils/scroll-to.js

+ 2 - 0
src/api/qc.js

@@ -1,4 +1,6 @@
 import request from '@/utils/request'
+import request2 from '@/utils/request_bazb'
+import request3 from '@/utils/request_api'
 import store from '@/store';
 
 // 病案室-质控列表

+ 103 - 0
src/utils/request_api.js

@@ -0,0 +1,103 @@
+import axios from 'axios'
+import { Message } from 'element-ui'
+import { getToken, removeToken } from '@/utils/auth'
+import router, { resetRouter } from '@/router'
+
+// create an axios instance
+const service = axios.create({
+  baseURL: process.env.VUE_APP_BASE_API3, // url = base url + request url
+  timeout: 60000 // request timeout
+  // transformRequest: [function(data) { // 转换数据
+  //   const form = new FormData()
+  //   if (!data) {
+  //     return form
+  //   }
+  //   Object.keys(data).forEach(k => {
+  //     const v = (data[k] !== 0 && !data[k] || data[k] === null ? '' : data[k])
+  //     if (Array.isArray(v) && v !== null) {
+  //       Object.keys(v).forEach(key => {
+  //         const vv = (!v[key] || v[key] === null ? '' : v[key])
+  //         form.append(`${k}[${key}]`, vv)
+  //       })
+  //     } else {
+  //       form.append(k, v)
+  //     }
+  //   })
+  //   return form
+  // }],
+  // headers: {
+  //   'Content-Type': 'application/x-www-form-urlencoded'
+  // }
+})
+
+// request interceptor
+service.interceptors.request.use(
+  config => {
+    // do something before request is sent
+
+    if (getToken()) {
+      // console.log(config, getToken())
+      // let each request carry token
+      // ['X-Token'] is a custom headers key
+      // please modify it according to the actual situation
+      config.headers['token'] = getToken()
+    }
+    // 在请求发送之前做一些处理
+    const jsonStr = config.data
+    const data = jsonStr
+    config.data = data
+    return config
+  },
+  error => {
+    // 发送失败
+    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 dataAxios = response.data
+    const { code } = dataAxios
+    // 根据 code 进行判断}
+    if (code === 200) {
+      // 如果没有 code 代表这不是项目后端开发的接口 比如可能是 VXAdmin 请求最新版本
+      return dataAxios
+    } else {
+      if (code === -1) {
+        Message({
+          message: `${dataAxios.msg}`,
+          type: 'error',
+          duration: 3 * 1000
+        })
+        removeToken()
+        resetRouter()
+        router.push(`/login`)
+        return
+      }
+      return Promise.reject(dataAxios.data)
+      //   //  发送的接口为response.config.url,进行报错处理
+    }
+  },
+  error => {
+    console.log('err' + error) // for debug
+    Message({
+      message: error.message,
+      type: 'error',
+      duration: 5 * 1000
+    })
+    return Promise.reject(error)
+  }
+)
+
+export default service

+ 103 - 0
src/utils/request_bazb.js

@@ -0,0 +1,103 @@
+import axios from 'axios'
+import { Message } from 'element-ui'
+import { getToken, removeToken } from '@/utils/auth'
+import router, { resetRouter } from '@/router'
+
+// create an axios instance
+const service = axios.create({
+  baseURL: process.env.VUE_APP_BASE_API2, // url = base url + request url
+  timeout: 60000 // request timeout
+  // transformRequest: [function(data) { // 转换数据
+  //   const form = new FormData()
+  //   if (!data) {
+  //     return form
+  //   }
+  //   Object.keys(data).forEach(k => {
+  //     const v = (data[k] !== 0 && !data[k] || data[k] === null ? '' : data[k])
+  //     if (Array.isArray(v) && v !== null) {
+  //       Object.keys(v).forEach(key => {
+  //         const vv = (!v[key] || v[key] === null ? '' : v[key])
+  //         form.append(`${k}[${key}]`, vv)
+  //       })
+  //     } else {
+  //       form.append(k, v)
+  //     }
+  //   })
+  //   return form
+  // }],
+  // headers: {
+  //   'Content-Type': 'application/x-www-form-urlencoded'
+  // }
+})
+
+// request interceptor
+service.interceptors.request.use(
+  config => {
+    // do something before request is sent
+
+    if (getToken()) {
+      // console.log(config, getToken())
+      // let each request carry token
+      // ['X-Token'] is a custom headers key
+      // please modify it according to the actual situation
+      config.headers['token'] = getToken()
+    }
+    // 在请求发送之前做一些处理
+    const jsonStr = config.data
+    const data = jsonStr
+    config.data = data
+    return config
+  },
+  error => {
+    // 发送失败
+    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 dataAxios = response.data
+    const { code } = dataAxios
+    // 根据 code 进行判断}
+    if (code === 200) {
+      // 如果没有 code 代表这不是项目后端开发的接口 比如可能是 VXAdmin 请求最新版本
+      return dataAxios
+    } else {
+      if (code === -1) {
+        Message({
+          message: `${dataAxios.msg}`,
+          type: 'error',
+          duration: 3 * 1000
+        })
+        removeToken()
+        resetRouter()
+        router.push(`/login`)
+        return
+      }
+      return Promise.reject(dataAxios.data)
+      //   //  发送的接口为response.config.url,进行报错处理
+    }
+  },
+  error => {
+    console.log('err' + error) // for debug
+    Message({
+      message: error.message,
+      type: 'error',
+      duration: 5 * 1000
+    })
+    return Promise.reject(error)
+  }
+)
+
+export default service

+ 58 - 0
src/utils/scroll-to.js

@@ -0,0 +1,58 @@
+Math.easeInOutQuad = function(t, b, c, d) {
+  t /= d / 2
+  if (t < 1) {
+    return c / 2 * t * t + b
+  }
+  t--
+  return -c / 2 * (t * (t - 2) - 1) + b
+}
+
+// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
+var requestAnimFrame = (function() {
+  return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 60) }
+})()
+
+/**
+ * Because it's so fucking difficult to detect the scrolling element, just move them all
+ * @param {number} amount
+ */
+function move(amount) {
+  document.documentElement.scrollTop = amount
+  document.body.parentNode.scrollTop = amount
+  document.body.scrollTop = amount
+}
+
+function position() {
+  return document.documentElement.scrollTop || document.body.parentNode.scrollTop || document.body.scrollTop
+}
+
+/**
+ * @param {number} to
+ * @param {number} duration
+ * @param {Function} callback
+ */
+export function scrollTo(to, duration, callback) {
+  const start = position()
+  const change = to - start
+  const increment = 20
+  let currentTime = 0
+  duration = (typeof (duration) === 'undefined') ? 500 : duration
+  var animateScroll = function() {
+    // increment the time
+    currentTime += increment
+    // find the value with the quadratic in-out easing function
+    var val = Math.easeInOutQuad(currentTime, start, change, duration)
+    // move the document.body
+    move(val)
+    // do the animation unless its over
+    if (currentTime < duration) {
+      requestAnimFrame(animateScroll)
+    } else {
+      if (callback && typeof (callback) === 'function') {
+        // the animation is done so lets callback
+        callback()
+      }
+    }
+  }
+  animateScroll()
+}