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('@mobile/views/error/404.vue'), meta: { ignoreAuth: true, }, }, { path: '/boot', name: 'boot', component: () => import('../views/boot/index.vue'), meta: { ignoreAuth: true, }, }, { path: '/register', component: Page, children: [ { path: '', name: 'register', component: () => import('@mobile/views/user/register/home.vue'), meta: { ignoreAuth: true, }, props: { showYhkhfxgzs: false, insetStyle: false } } ] }, { 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: 'spot', name: 'home-spot', component: () => import('../views/spot/goods/list/index.vue'), }, { path: 'contract', name: 'home-contract', component: () => import('../views/contract/goods/list/index.vue'), }, { path: 'wallet', name: 'home-wallet', component: () => import('../views/wallet/index.vue'), }, ] } ], }, { path: '/spot', component: Page, children: [ { path: 'detail', name: 'spot-detail', component: () => import('../views/spot/detail/index.vue'), }, { path: 'goods/detail', name: 'spot-goods-detail', component: () => import('../views/spot/goods/detail/index.vue'), }, { path: 'goods/chart', name: 'spot-goods-chart', component: () => import('../views/spot/goods/chart/index.vue'), }, ] }, { path: '/contract', component: Page, children: [ { path: 'detail', name: 'contract-detail', component: () => import('../views/contract/detail/index.vue'), }, { path: 'goods/detail', name: 'contract-goods-detail', component: () => import('../views/contract/goods/detail/index.vue'), }, { path: 'goods/chart', name: 'contract-goods-chart', component: () => import('../views/contract/goods/chart/index.vue'), }, ] }, { path: '/wallet', component: Page, children: [ { path: 'transfer', name: 'wallet-transfer', component: () => import('../views/wallet/transfer/index.vue'), }, { path: 'deposit', name: 'wallet-deposit', component: () => import('../views/wallet/deposit/index.vue'), }, { path: 'deposit', name: 'wallet-withdraw', component: () => import('../views/wallet/withdraw/index.vue'), }, ] }, { path: '/setting', component: Page, children: [ { path: '', name: 'setting', component: () => import('../views/setting/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, }, props: { showYhkhfxgzs: false, insetStyle: false } }, { path: 'forget', name: 'user-forget', component: () => import('@mobile/views/user/forget/Index.vue'), meta: { ignoreAuth: true, }, props: { insetStyle: false } }, { 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: '/report', component: Page, children: [ { path: '', name: 'report', component: () => import('@mobile/views/report/index.vue'), } ] }, { path: '/account', component: Page, children: [ { path: 'certification', name: 'account-certification', component: () => import('@mobile/views/account/certification/Index.vue'), }, { path: 'authresult', name: 'account-authresult', component: () => import('@mobile/views/account/authresult/Index.vue'), }, { path: 'protocol', name: 'account-protocol', component: () => import('../../sbyj/views/account/protocol/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: '/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'), props: { showBackButton: true } }, { path: 'delivery', name: 'order-delivery', component: () => import('../views/order/delivery/index.vue'), } ] }, { path: '/points', component: Page, children: [ { path: 'account', name: 'points-account', component: () => import('@mobile/views/points/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: '/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 { 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') { next() } else { next({ name: 'boot', query: { redirect: to.fullPath }, }) } } }) export default router