main.js 4.4 KB

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