// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import App from './App' import router from './router' import store from './config/config' import { Loading } from 'element-ui'; // Message, import { myMessage } from './components/tools/message'; import ajax from './common/axios.config' import qs from 'qs' import './common/player.css' import VideoPlayer from 'vue-video-player' const echarts = require('echarts'); import 'video.js/dist/video-js.css' //videoJs的样式 import 'vue-video-player/src/custom-theme.css' //vue-video-player的样式 import VueCookies from 'vue-cookies' import hevueImgPreview from './components/tools/hevue-img-preview' import drag from './components/directive/el-drag-dialog'; import VueAudio from 'vue-audio-better' import './assets/css/markdownCss.css' Vue.use(VideoPlayer).use(VueAudio).use(VueCookies).use(hevueImgPreview, { clickMaskCLose: true }).use(drag) Vue.prototype.$echarts = echarts Vue.prototype.$equipment=function(){ 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); return flag; } Vue.config.productionTip = false Vue.prototype.$store = store; // 将store实例挂在vue原型上 Vue.prototype.ajax = ajax // Vue.prototype.$message = Message Vue.prototype.$message = myMessage Vue.prototype.$loading = Loading Vue.prototype.openLoading = function(target) { const loading = this.$loading.service({ // 声明一个loading对象 lock: true, // 是否锁屏 background: 'rgba(255, 255, 255, 0.7)', // 背景颜色 target: target ? target : document.body, // 需要遮罩的区域 body: true, }) return loading; } Vue.prototype.$qs = qs /* eslint-disable no-new */ new Vue({ el: '#app', router, components: { App }, template: '' }) VueCookies.config('30d') router.beforeEach((to, from, next) => { if (to.meta.title) { document.title = to.meta.title } const requireAuth = to.meta.requireAuth // 判断该路由是否需要登录权限 if (requireAuth) { var isLogin = VueCookies.get('tlogin') if (isLogin == "1") { var userinfo = VueCookies.get('studentInfo') store.commit("update", ["isLogin", true]); // var info = JSON.parse(window.sessionStorage.getItem("userInfo")) store.commit("update", ["userInfo", userinfo]); store.state.luyou = store.state.luyou + 1 store.commit("update", ["luyou", store.state.luyou]); next() } else { const loading = Loading.service({ background: "rgba(255, 255, 255)", target: document.querySelector("body"), }); store.commit("update", ["isLogin", false]); Message({ message: '未登录,请登录', type: 'warning' }); setTimeout(() => { loading.close(); next('/login') }, 2000); } } else { next() // 确保一定要有next()被调用 } })