main.js 4.1 KB

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