main.js 2.5 KB

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