import { createWebHashHistory, RouteRecordRaw } from 'vue-router' import { useLoginStore } from '@/stores' import { clearPending } from '@/services/http/pending' import service from '@/services' import Page from '@mobile/components/layouts/page/index.vue' import animateRouter from '@mobile/router/animateRouter' const loginStore = useLoginStore() const routes: Array = [ { path: '/:pathMatch(.*)*', name: 'error', component: () => import('../views/error/404.vue'), meta: { ignoreAuth: true, }, }, { path: '/boot', name: 'boot', component: () => import('../views/boot/Index.vue'), meta: { ignoreAuth: true, }, }, { path: '/', component: Page, children: [ { path: '', name: 'home', component: () => import('../views/home/Index.vue'), children: [ { path: '', name: 'home-index', component: () => import('../views/home/main/Index.vue'), meta: { ignoreAuth: true, }, }, { path: '50101', name: 'home-50101', component: () => import('@mobile/views/goods/list/Index.vue'), props: { marketId: 50101 } }, { path: 'mine', name: 'home-mine', component: () => import('../views/mine/Index.vue'), } ] }, ], }, { path: '/user', component: Page, children: [ { path: 'login', name: 'user-login', component: () => import('../views/user/login/Index.vue'), meta: { ignoreAuth: true, }, }, { path: 'register', name: 'user-register', component: () => import('@mobile/views/user/register/Index.vue'), meta: { ignoreAuth: true, }, }, { path: 'forget', name: 'user-forget', component: () => import('@mobile/views/user/forget/Index.vue'), meta: { ignoreAuth: true, }, }, { path: 'cancel', name: 'user-cancel', component: () => import('@mobile/views/user/cancel/Index.vue'), }, { path: 'password', name: 'user-password', component: () => import('@mobile/views/user/password/Index.vue'), }, { path: 'avatar', name: 'user-avatar', component: () => import('@mobile/views/user/avatar/Index.vue'), }, ], }, { path: '/account', component: Page, children: [ { path: 'certification', name: 'account-certification', component: () => import('../views/account/certification/Index.vue'), }, ], }, { path: '/news', component: Page, children: [ { path: '', name: 'news-list', component: () => import('@mobile/views/news/list/Index.vue'), meta: { ignoreAuth: true, }, }, { path: 'detail', name: 'news-detail', component: () => import('@mobile/views/news/detail/Index.vue'), meta: { ignoreAuth: true, }, }, ], }, { path: '/goods', component: Page, children: [ { path: 'detail', name: 'goods-detail', component: () => import('@mobile/views/goods/detail/Index.vue'), }, { path: 'trade', name: 'goods-trade', component: () => import('@mobile/views/goods/trade/index.vue'), }, ], }, { path: '/bank', component: Page, children: [ { path: 'wallet', name: 'bank-wallet', component: () => import('@mobile/views/bank/wallet/Index.vue'), }, { path: 'sign', name: 'bank-sign', component: () => import('@mobile/views/bank/sign/Index.vue'), }, { path: 'statement', name: 'bank-statement', component: () => import('@mobile/views/bank/statement/Index.vue'), }, { path: 'statement/history', name: 'bank-statement-history', component: () => import('@mobile/views/bank/statement/history/Index.vue'), }, ], }, { path: '/order', component: Page, children: [ { path: 'list', name: 'order-list', component: () => import('../views/order/list/Index.vue'), }, { path: 'position', name: 'order-position', component: () => import('../views/order/position/Index.vue'), }, ], }, { path: '/mine', component: Page, children: [ { path: 'address', name: 'mine-address', component: () => import('@mobile/views/mine/address/Index.vue'), }, { path: 'invoice', name: 'mine-invoice', component: () => import('@mobile/views/mine/invoice/Index.vue'), }, { path: 'profile', name: 'mine-profile', component: () => import('@mobile/views/mine/profile/Index.vue'), }, { path: 'setting', name: 'mine-setting', component: () => import('@mobile/views/mine/setting/Index.vue'), }, ], }, { path: '/notice', component: Page, children: [ { path: '', name: 'notice-list', component: () => import('@mobile/views/notice/list/index.vue'), }, ], }, { path: '/rules', component: Page, children: [ { path: "zcxy", name: "rules-zcxy", component: () => import("@mobile/views/rules/zcxy/Index.vue"), meta: { ignoreAuth: true, }, }, { path: "yhkhfxgzs", name: "rules-yhkhfxgzs", component: () => import("@mobile/views/rules/fxgzs/Index.vue"), meta: { ignoreAuth: true, }, }, { path: "yszc", name: "rules-yszc", component: () => import("@mobile/views/rules/yszc/Index.vue"), meta: { ignoreAuth: true, }, }, { path: "gywm", name: "rules-gywm", component: () => import("@mobile/views/rules/gywm/Index.vue"), meta: { ignoreAuth: true, }, }, { path: "fwrx", name: "rules-fwrx", component: () => import("@mobile/views/rules/fwrx/Index.vue"), meta: { ignoreAuth: true, }, }, ] } ] const router = animateRouter.create({ history: createWebHashHistory(), routes, }) // 路由跳转拦截 router.beforeEach((to, from, next) => { clearPending() // 判断服务是否加载完成 if (service.isReady) { if (to.meta.ignoreAuth || loginStore.token) { next() } else { next({ name: 'user-login', query: { redirect: to.fullPath }, }) } } else { if (to.name === 'boot' || to.name === 'user-login') { next() } else { next({ name: 'boot', query: { redirect: to.fullPath }, }) } } }) export default router