icx-meum-vue-common-module
Version:
icx-meum-vue-common-module
88 lines (82 loc) • 2.67 kB
JavaScript
// 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 VuexRouterSync from 'vuex-router-sync'
import router from './router'
import store from './store'
import veeConfig from './config/validate/vee-validate'
import VeeValidate from 'vee-validate'
import './config/rem'
import './config/baseUri'
import './config/js-bridge'
import * as CONST from './icx/const'
import { UPDATE_DIRECTION, CHANGE_LOADING_STATE, CHANGE_CURRENT_PERSON_ID } from './store/mutation-types'
VuexRouterSync.sync(store, router)
Vue.use(VeeValidate, veeConfig)
// simple history management
const history = window.sessionStorage
history.clear()
let historyCount = history.getItem('count') * 1 || 0
history.setItem('/', 0)
router.beforeEach(function (to, from, next) {
const toIndex = history.getItem(to.path)
const fromIndex = history.getItem(from.path)
// set router direction
if (toIndex) {
if (toIndex > fromIndex || !fromIndex || (toIndex === '0' && fromIndex === '0')) {
store.commit(UPDATE_DIRECTION, {direction: 'forward'})
} else {
store.commit(UPDATE_DIRECTION, {direction: 'reverse'})
}
// init page loading state
if (to.meta && to.meta.keepAlive) {
store.commit(CHANGE_LOADING_STATE, {state: CONST.INT_LOADING_SUCCESS})
}
} else {
++historyCount
history.setItem('count', historyCount)
to.path !== '/' && history.setItem(to.path, historyCount)
store.commit(UPDATE_DIRECTION, {direction: 'forward'})
}
if (to.meta && to.meta.changePerson) {
store.commit(CHANGE_CURRENT_PERSON_ID, to.params.pId || '')
}
// set page title
to.meta.title ? (document.title = to.meta.title) : ''
// 判断该路由是否需要登录权限
if (to.meta.requireAuth) {
// 判断账户信息是否为空
let _authInfo = store.getters.personInfo || localStorage.personInfo
if (_authInfo) {
if (/\/http/.test(to.path)) {
let url = to.path.split('http')[1]
window.location.href = `http${url}`
} else {
next()
}
next()
} else {
next({
path: '/login',
query: {redirect: to.fullPath} // 将跳转的路由path作为参数,登录成功后跳转到该路由
})
}
} else {
next()
}
})
const FastClick = require('fastclick')
if ('addEventListener' in document) {
document.addEventListener('DOMContentLoaded', function () {
FastClick.attach(document.body)
}, false)
}
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
store,
template: '<App/>',
components: { App }
})