main.js 3.1 KB

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