// import 'babel-polyfill'
|
import 'fetch-detector'
|
import 'fetch-ie8'
|
|
import Vue from 'vue'
|
import App from './App'
|
import router from './router'
|
import BootstrapVue from 'bootstrap-vue'
|
import Notifications from 'vue-notification'
|
import moment from 'moment'
|
import sweetalert from 'sweetalert'
|
import globals from './globals'
|
import Popper from 'popper.js'
|
import store from './store'
|
import qs from 'qs'
|
import {
|
httpImg,
|
noData,
|
fButton,
|
vLoading
|
} from '@/components/common'
|
import Toast from '@/components/common/toasted'
|
// import httpAxios from '@/server/common/httpAxios'
|
import {
|
httpGET,
|
httpPOST,
|
httpPUT,
|
httpDEL
|
} from '@/server/common/httpFetch'
|
|
import { getLoginUserData } from '@/server/login.js'
|
// Required to enable animations on dropdowns/tooltips/popovers
|
Popper.Defaults.modifiers.computeStyle.gpuAcceleration = false
|
|
Vue.config.productionTip = false
|
// Vue.prototype.$httpAxios = httpAxios
|
|
Vue.prototype.$httpGET = httpGET
|
Vue.prototype.$httpPOST = httpPOST
|
Vue.prototype.$httpPUT = httpPUT
|
Vue.prototype.$httpDEL = httpDEL
|
|
Vue.prototype.$moment = moment
|
Vue.prototype.$swal = sweetalert
|
Vue.prototype.$toast = Toast
|
Vue.use(BootstrapVue)
|
Vue.use(qs)
|
Vue.use(httpImg)
|
Vue.use(noData)
|
Vue.use(fButton)
|
Vue.use(vLoading)
|
Vue.use(Notifications)
|
// Global RTL flag
|
Vue.mixin({
|
data: globals
|
})
|
// 全局导航钩子
|
router.beforeEach((to, from, next) => {
|
// 判断URL中的登陆数据
|
let urlLoginInfo = to.query
|
if (
|
urlLoginInfo &&
|
urlLoginInfo.expires_in &&
|
urlLoginInfo.expires_in !== '' &&
|
urlLoginInfo.loginedInfo &&
|
urlLoginInfo.loginedInfo !== ''
|
) {
|
sessionStorage.setItem('expires_in', urlLoginInfo.expires_in)
|
sessionStorage.setItem('loginedInfo', urlLoginInfo.loginedInfo)
|
}
|
store.commit('GET_USER_INFO')
|
// 判断该路由是否需要登录权限
|
if (to.meta.requireAuth) {
|
// 通过vuex state获取当前的token是否存在
|
let token = sessionStorage.getItem('loginedInfo') && JSON.parse(sessionStorage.getItem('loginedInfo')).access_token
|
if (token && token !== '') {
|
// 判断用户登陆信息 并存储
|
if (
|
sessionStorage.getItem('userInfo') &&
|
sessionStorage.getItem('userInfo') !== ''
|
) {
|
next()
|
} else {
|
/* 获取用户数据 后跳转 */
|
getLoginUserData().then((result) => {
|
store.commit('GET_USER_INFO')
|
// next()
|
router.replace(to.path)
|
})
|
}
|
} else {
|
next({
|
path: '/login',
|
query: {
|
redirect: to.fullPath
|
} // 将跳转的路由path作为参数,登录成功后跳转到该路由
|
})
|
}
|
} else {
|
next()
|
}
|
})
|
/* eslint-disable no-new */
|
new Vue({
|
el: '#app',
|
router,
|
store,
|
template: '<App/>',
|
components: { App }
|
})
|