main.js 3.7 KB

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