main.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. import Viewer from 'v-viewer'
  16. import 'viewerjs/dist/viewer.css'
  17. import Clipboard from "clipboard";
  18. import hevueImgPreview from 'hevue-img-preview'
  19. const echarts = require('echarts');
  20. //
  21. Vue.use(VideoPlayer).use(VueCookies).use(Viewer).use(hevueImgPreview)
  22. Vue.config.productionTip = false
  23. Vue.prototype.$store = store; // 将store实例挂在vue原型上
  24. Vue.prototype.ajax = ajax
  25. Vue.prototype.Clipboard = Clipboard
  26. Vue.prototype.$message = Message
  27. Vue.prototype.$loading = Loading
  28. Vue.prototype.$echarts = echarts
  29. Vue.prototype.openLoading = function(target) {
  30. const loading = this.$loading.service({ // 声明一个loading对象
  31. lock: true, // 是否锁屏
  32. background: 'rgba(255, 255, 255, 0.7)', // 背景颜色
  33. target: target ? target : document.body, // 需要遮罩的区域
  34. body: true,
  35. })
  36. return loading;
  37. }
  38. Vue.prototype.$qs = qs
  39. Viewer.setDefaults({
  40. 'inline': false, //启用inline模式
  41. 'button': false, //显示右上角关闭按钮
  42. 'navbar': false, //显示缩略图导航
  43. 'title': false, //显示当前图片的标题
  44. 'toolbar': true, //显示工具栏
  45. 'tooltip': true, //显示缩略百分比
  46. 'movable': true, //图片是否可移动
  47. 'zoomable': true, //图片是否可缩放
  48. 'rotatable': true, //图片是否可旋转
  49. 'scalable': true, //图片是否可反转
  50. 'transition': true, //使用css3过度
  51. 'fullscreen': false, //播放时是否全屏
  52. 'keyboard': true, //
  53. })
  54. /* eslint-disable no-new */
  55. new Vue({
  56. el: '#app',
  57. router,
  58. components: { App },
  59. template: '<App/>'
  60. })
  61. VueCookies.config('30d')
  62. router.beforeEach((to, from, next) => {
  63. if (to.meta.title) {
  64. document.title = to.meta.title
  65. }
  66. const requireAuth = to.meta.requireAuth
  67. // 判断该路由是否需要登录权限
  68. if (requireAuth) {
  69. var isLogin = VueCookies.get('tlogin')
  70. if (isLogin == "1") {
  71. var userinfo = VueCookies.get('teacherInfo')
  72. store.commit("update", ["isLogin", true]);
  73. // var info = JSON.parse(window.sessionStorage.getItem("userInfo"))
  74. store.commit("update", ["userInfo", userinfo]);
  75. store.state.luyou = store.state.luyou + 1
  76. store.commit("update", ["luyou", store.state.luyou]);
  77. next()
  78. } else {
  79. const loading = Loading.service({
  80. background: "rgba(255, 255, 255)",
  81. target: document.querySelector("body"),
  82. });
  83. store.commit("update", ["isLogin", false]);
  84. Message({
  85. message: '未登录,请登录',
  86. type: 'warning'
  87. });
  88. setTimeout(() => {
  89. loading.close();
  90. next('/login')
  91. }, 2000);
  92. }
  93. } else {
  94. next() // 确保一定要有next()被调用
  95. }
  96. })