main.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 './config/config'
  7. import { Message, Loading } from 'element-ui';
  8. import ajax from './common/axios.config'
  9. import qs from 'qs'
  10. import './common/player.css'
  11. import VideoPlayer from 'vue-video-player'
  12. const echarts = require('echarts');
  13. import 'video.js/dist/video-js.css' //videoJs的样式
  14. import 'vue-video-player/src/custom-theme.css' //vue-video-player的样式
  15. import VueCookies from 'vue-cookies'
  16. import hevueImgPreview from 'hevue-img-preview'
  17. Vue.use(VideoPlayer).use(VueCookies).use(hevueImgPreview, {
  18. clickMaskCLose: true
  19. })
  20. Vue.prototype.$echarts = echarts
  21. Vue.config.productionTip = false
  22. Vue.prototype.$store = store; // 将store实例挂在vue原型上
  23. Vue.prototype.ajax = ajax
  24. Vue.prototype.$message = Message
  25. Vue.prototype.$loading = Loading
  26. Vue.prototype.openLoading = function(target) {
  27. const loading = this.$loading.service({ // 声明一个loading对象
  28. lock: true, // 是否锁屏
  29. background: 'rgba(255, 255, 255, 0.7)', // 背景颜色
  30. target: target ? target : document.body, // 需要遮罩的区域
  31. body: true,
  32. })
  33. return loading;
  34. }
  35. Vue.prototype.$qs = qs
  36. /* eslint-disable no-new */
  37. new Vue({
  38. el: '#app',
  39. router,
  40. components: { App },
  41. template: '<App/>'
  42. })
  43. VueCookies.config('30d')
  44. router.beforeEach((to, from, next) => {
  45. if (to.meta.title) {
  46. document.title = to.meta.title
  47. }
  48. const requireAuth = to.meta.requireAuth
  49. // 判断该路由是否需要登录权限
  50. if (requireAuth) {
  51. var isLogin = VueCookies.get('tlogin')
  52. if (isLogin == "1") {
  53. var userinfo = VueCookies.get('studentInfo')
  54. store.commit("update", ["isLogin", true]);
  55. // var info = JSON.parse(window.sessionStorage.getItem("userInfo"))
  56. store.commit("update", ["userInfo", userinfo]);
  57. store.state.luyou = store.state.luyou + 1
  58. store.commit("update", ["luyou", store.state.luyou]);
  59. next()
  60. } else {
  61. const loading = Loading.service({
  62. background: "rgba(255, 255, 255)",
  63. target: document.querySelector("body"),
  64. });
  65. store.commit("update", ["isLogin", false]);
  66. Message({
  67. message: '未登录,请登录',
  68. type: 'warning'
  69. });
  70. setTimeout(() => {
  71. loading.close();
  72. next('/login')
  73. }, 2000);
  74. }
  75. } else {
  76. next() // 确保一定要有next()被调用
  77. }
  78. })