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('@mobile/views/error/404.vue'), meta: { ignoreAuth: true, }, }, { path: '/boot', name: 'boot', component: () => import('../../sbyj/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: 'market', name: 'home-market', component: () => import('../../sbyj/views/market/list/index.vue'), meta: { ignoreAuth: true, }, }, { path: 'news', name: 'home-news', component: () => import('../../sjgj/views/news/list/Index.vue'), meta: { ignoreAuth: true, }, props: { showBackButton: false, columnid: 2, title: '研报' } }, { path: 'mine', name: 'home-mine', component: () => import('../../sbyj/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('../../sbyj/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('../../sjgj/views/news/list/Index.vue'), meta: { ignoreAuth: true, }, props: { title: '业务公告', columnid: 1 } }, { path: 'detail', name: 'news-detail', component: () => import('@mobile/views/news/detail/Index.vue'), meta: { ignoreAuth: true, }, }, ], }, { path: '/market', component: Page, children: [ { path: '', name: 'market-list', component: () => import('../../sbyj/views/market/list/index.vue'), meta: { ignoreAuth: true, }, }, { path: 'detail', name: 'market-detail', component: () => import('../../sbyj/views/market/detail/index.vue'), }, { path: 'chart', name: 'market-chart', component: () => import('@mobile/views/market/detail/Index.vue'), }, ], }, { path: '/bank', component: Page, children: [ { path: 'wallet', name: 'bank-wallet', component: () => import('../../sbyj/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: '', name: 'order-list', component: () => import('../../sbyj/views/order/list/index.vue'), }, { path: 'history', name: 'history-list', component: () => import('../../sbyj/views/order/history/index.vue'), }, { path: 'close', name: 'close-list', component: () => import('../../sbyj/views/order/close/index.vue'), } ] }, { path: '/delivery', component: Page, children: [ { path: '', name: 'delivery-list', component: () => import('../../sbyj/views/delivery/index.vue'), props: { title: '交料订单', buyorsell: 1 } } ] }, { path: '/inventory', component: Page, children: [ { path: '', name: 'inventory-list', component: () => import('../../sbyj/views/inventory/index.vue'), props: { title: '我的库存' } } ] }, { path: '/pickup', component: Page, children: [ { path: '', name: 'pickup-list', component: () => import('../../sbyj/views/delivery/index.vue'), props: { title: '提料订单', buyorsell: 0 } } ] }, { 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-market', 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