import { createWebHashHistory, RouteRecordRaw } from 'vue-router' import { useLoginStore } from '@/stores' import { clearPending } from '@/services/http/pending' import { homeRoutes, pageRoutes } from '@mobile/router/section' 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('@mobile/views/home/Index.vue'), props: { iosUpdateUrl: 'https://itunes.apple.com/lookup?id=6459789608' }, children: [ { path: '', name: 'home-index', component: () => import('@mobile/views/home/main/Index.vue'), meta: { ignoreAuth: true, }, }, { path: 'mine', name: 'home-mine', component: () => import('../views/mine/Index.vue'), }, ...homeRoutes ] } ] }, { 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('@mobile/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: '/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: 'capital', name: 'bank-capital', component: () => import('@mobile/views/bank/capital/index.vue'), } ] }, { path: '/holdbank', component: Page, children: [ { path: 'holdsign', name: 'hold-sign', component: () => import('../views/holdbank/holdsign/Index.vue'), }, { path: 'holddeposit', name: 'hold-deposit', component: () => import('../views/holdbank/holddeposit/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: 'delivery', name: 'order-delivery', component: () => import('../views/order/delivery/Index.vue'), }, { path: 'performance', name: 'order-performance', component: () => import('@mobile/views/order/performance/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: 'wechat', name: 'mine-wechat', component: () => import('@mobile/views/mine/wechat/Index.vue'), }, { path: 'email', name: 'mine-email', component: () => import('@mobile/views/mine/email/Index.vue'), } ], }, { path: '/notice', component: Page, children: [ { path: '', name: 'notice-list', component: () => import('@mobile/views/notice/list/index.vue'), }, ], }, { path: '/report', component: Page, children: [ { path: '', name: 'report', component: () => import('@mobile//views/report/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, }, }, ] }, ...pageRoutes ] const router = animateRouter.create({ history: createWebHashHistory(), routes, }) // 路由跳转拦截 router.beforeEach((to, from, next) => { clearPending() // 判断服务是否加载完成 if (service.isReady) { if (to.meta.ignoreAuth || loginStore.token) { next() } else { if (to.matched.some((e) => e.name === 'home')) { // 如果是主页导航页面,强制跳转到首页 next({ name: 'home-index', replace: true, }) } 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