main.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import Vue from 'vue'
  4. import App from './App'
  5. import router from './router'
  6. import store from '@/store'
  7. import ElementUI from 'element-ui';
  8. import 'element-ui/lib/theme-chalk/index.css';
  9. import axios from 'axios'
  10. import './assets/css/common.css'
  11. import httpApi from '@/api/index'
  12. import moment from 'moment'// 导入moment
  13. // 引入v-charts
  14. import VCharts from 'v-charts'
  15. Vue.use(VCharts)
  16. import echarts from 'echarts'
  17. Vue.prototype.$echarts = echarts
  18. import VueLazyload from 'vue-lazyload'
  19. Vue.use(VueLazyload,{
  20. preLoad: 1.3,
  21. error: '/static/image/error.png',
  22. loading: '/static/image/loading.gif',
  23. attempt: 1
  24. })
  25. Vue.prototype.moment = moment
  26. Vue.use(ElementUI);
  27. Vue.config.productionTip = false
  28. Vue.prototype.axios = axios
  29. Vue.prototype.$httpApi = httpApi
  30. import VideoPlayer from 'vue-video-player'
  31. window.videojs = VideoPlayer.videojs
  32. require('vue-video-player/src/custom-theme.css')
  33. require('video.js/dist/video-js.min.css')
  34. require('video.js/dist/lang/zh-CN.js')
  35. Vue.use(VideoPlayer)
  36. import {playVideo, goBack} from '@/api/common'
  37. Vue.prototype.playVideo = playVideo
  38. Vue.prototype.goBack = goBack
  39. axios.interceptors.request.use(function (config) {
  40. let token = localStorage.getItem('token')
  41. config.headers.Platform = 'educationStudent'
  42. if (token) {
  43. // 这里将token设置到headers中,header的key是token,这个key值根据你的需要进行修改即可
  44. config.headers.Authorization = token
  45. //config.headers.httpType = 'student-product'
  46. }
  47. return config
  48. }, function (error) {
  49. // 对请求错误做些什么
  50. return Promise.reject(error)
  51. })
  52. // 添加全局响应拦截器
  53. axios.interceptors.response.use(function (response) {
  54. let authorization = response.data.authorization
  55. if (authorization) {
  56. localStorage.setItem('token', token)
  57. }
  58. if (response.data.code !== 1) {
  59. // 对响应数据做点什么
  60. if (response.data.code === 401) {
  61. localStorage.clear()
  62. sessionStorage.clear()
  63. ElementUI.Message.error('会话已过期,请重新登录')
  64. router.push('/login')
  65. } else if (response.data.code === 0) {
  66. ElementUI.Message.error(response.data.message)
  67. return false
  68. }
  69. }
  70. return response
  71. }, function (error) {
  72. return Promise.reject(error)
  73. })
  74. /* eslint-disable no-new */
  75. new Vue({
  76. el: '#app',
  77. router,
  78. store,
  79. components: { App },
  80. template: '<App/>'
  81. })