main.js 2.5 KB

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