1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import * as VueRouter from 'vue-router'
- import NProgress from 'nprogress';
- import 'nprogress/nprogress.css'
- import store from '@/store';
-
- const routes = [
- { path: '/', name: 'index', component: () => import('@/pages/index.vue') },
- { path: '/invoice/fill', name: 'invoice.fill', component: () => import('@/pages/invoice/fill.vue') },
- { path: '/invoice/history', name: 'invoice.history', component: () => import('@/pages/invoice/history.vue') },
- { path: '/publicity/list', name: 'publicity.list', component: () => import('@/pages/publicity/list.vue') },
- { path: '/login', name: 'login', component: () => import('@/pages/login.vue') },
- ];
-
- const router = VueRouter.createRouter({
- // history: VueRouter.createWebHistory(import.meta.env.BASE_URL),
- history: VueRouter.createWebHashHistory(),
- routes,
- })
-
- router.beforeEach((to, from, next) => {
- NProgress.start();
-
- if (to.name === 'login') {
- NProgress.done();
- return next();
- }
-
- const { user, getCurrent } = store.getState('user');
- if (!user || !user.personId) {
- getCurrent().then(() => {
- NProgress.done();
- next();
- }).catch((err) => {
- console.error(err)
- NProgress.done();
- next({ name: 'login', query: { from: encodeURIComponent(to.fullPath) } });
- })
- } else {
- next();
- NProgress.done();
- }
- })
-
- export default router;
|