main.js 3.0 KB

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