Files
Smart-Farm/uniapp/uni-admin/src/main.js
2025-12-22 17:13:05 +08:00

85 lines
1.8 KiB
JavaScript

/*
* @Descripttion:
* @Author: xiao li
* @Date: 2020-07-06 12:17:06
* @LastEditors: xiao li
* @LastEditTime: 2022-07-19 20:16:14
*/
// 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 i18n from './i18n' // 语言包
import store from './store'
import router from './router'
import {
api
} from './api' // 接口
import routes from './permission'
import util from './utils/public'
import Print from './utils/print'
import {
reg
} from '@/utils/reg'
import './components/basics'
import Nprogress from 'nprogress'
import vuescroll from 'vuescroll'
import '../static/Ueditor/ueditor.config.js'
import '../static/Ueditor/ueditor.all.js'
import '../static/Ueditor/lang/zh-cn/zh-cn.js'
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
Vue.use(vuescroll)
// 全局directive指令
import directives from './directives'
// 注册本页全局指令方法
Object.keys(directives).forEach(key => {
Vue.directive(key, directives[key])
})
Vue.config.productionTip = false
Vue.use(Print)
Vue.prototype.$api = api
Vue.prototype.$util = util
Vue.prototype.$reg = reg
router.beforeEach((to, from, next) => {
Nprogress.start()
if (to.path === '/login') {
window.sessionStorage.removeItem('minitk')
window.sessionStorage.removeItem('ms_username')
next()
} else if (!store.getters.isAuth) {
if (!window.sessionStorage.getItem('minitk')) {
next('/login')
} else {
store.dispatch('getUserPromission', {
to,
next,
routes
})
}
} else {
next()
}
})
router.afterEach(() => {
Nprogress.done()
})
/* eslint-disable no-new */
let vue = new Vue({
el: '#app',
router,
i18n,
store,
components: {
App
},
template: '<App/>'
})
export default vue