main.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. const echarts = require('echarts');
  15. import 'video.js/dist/video-js.css' //videoJs的样式
  16. import 'vue-video-player/src/custom-theme.css' //vue-video-player的样式
  17. import VueCookies from 'vue-cookies'
  18. import hevueImgPreview from './components/tools/hevue-img-preview'
  19. import drag from './components/directive/el-drag-dialog';
  20. import VueAudio from 'vue-audio-better'
  21. import './assets/css/markdownCss.css'
  22. Vue.use(VideoPlayer).use(VueAudio).use(VueCookies).use(hevueImgPreview, {
  23. clickMaskCLose: true
  24. }).use(drag)
  25. Vue.prototype.$echarts = echarts
  26. Vue.prototype.$equipment=function(){
  27. let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
  28. return flag;
  29. }
  30. Vue.config.productionTip = false
  31. Vue.prototype.$store = store; // 将store实例挂在vue原型上
  32. Vue.prototype.ajax = ajax
  33. // Vue.prototype.$message = Message
  34. Vue.prototype.$message = myMessage
  35. Vue.prototype.$loading = Loading
  36. Vue.prototype.openLoading = function(target) {
  37. const loading = this.$loading.service({ // 声明一个loading对象
  38. lock: true, // 是否锁屏
  39. background: 'rgba(255, 255, 255, 0.7)', // 背景颜色
  40. target: target ? target : document.body, // 需要遮罩的区域
  41. body: true,
  42. })
  43. return loading;
  44. }
  45. Vue.prototype.$qs = qs
  46. /* eslint-disable no-new */
  47. new Vue({
  48. el: '#app',
  49. router,
  50. components: { App },
  51. template: '<App/>'
  52. })
  53. VueCookies.config('30d')
  54. router.beforeEach((to, from, next) => {
  55. if (to.meta.title) {
  56. document.title = to.meta.title
  57. }
  58. const requireAuth = to.meta.requireAuth
  59. // 判断该路由是否需要登录权限
  60. if (requireAuth) {
  61. var isLogin = VueCookies.get('tlogin')
  62. if (isLogin == "1") {
  63. var userinfo = VueCookies.get('studentInfo')
  64. store.commit("update", ["isLogin", true]);
  65. // var info = JSON.parse(window.sessionStorage.getItem("userInfo"))
  66. store.commit("update", ["userInfo", userinfo]);
  67. store.state.luyou = store.state.luyou + 1
  68. store.commit("update", ["luyou", store.state.luyou]);
  69. next()
  70. } else {
  71. const loading = Loading.service({
  72. background: "rgba(255, 255, 255)",
  73. target: document.querySelector("body"),
  74. });
  75. store.commit("update", ["isLogin", false]);
  76. Message({
  77. message: '未登录,请登录',
  78. type: 'warning'
  79. });
  80. setTimeout(() => {
  81. loading.close();
  82. next('/login')
  83. }, 2000);
  84. }
  85. } else {
  86. next() // 确保一定要有next()被调用
  87. }
  88. })