import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router'; import {useUserStore} from "@/store/modules/user"; import {domainStoreWidthOut} from "@/store/modules/domain"; import {getDomainList} from "@/api/login"; import { i18n } from '@/lang'; const { t } = i18n.global export const constantRouter: Array = [ { path: '/', name: 'Root', redirect: '/home', meta: { title: 'Root', }, }, { path: '/', name: 'index', component: () => import('@/views/index/index.vue'), meta: { title: t('router.home'), }, children: [ { path: '/home', name: 'Home', component: () => import('@/views/index/home/index.vue'), meta: { title: t('router.home'), showBar: false }, }, { path: '/serveList', name: 'serveList', component: () => import('@/views/index/serveList/index.vue'), meta: { isPermissions: true, title: t('router.serveList'), showBar: false }, }, { path: '/message', name: 'message', component: () => import('@/views/index/message/index.vue'), meta: { isPermissions: true, title: t('router.message'), showBar: false }, }, { path: '/my', name: 'my', component: () => import('@/views/index/my/index.vue'), meta: { isPermissions: true, title: t('router.my'), showBar: false }, } ] }, { path: '/userInfo', name: 'userInfo', component: () => import('@/views/my/userInfo/index.vue'), meta: { title: t('router.userInfo'), isPermissions: true, showBar: true }, }, { path: '/userInfo1', name: 'userInfo1', component: () => import('@/views/my/userInfo1/index.vue'), meta: { title: t('router.userInfo1'), isPermissions: true, showBar: true }, }, { path: '/signature', name: 'signature', component: () => import('@/views/my/signature/index.vue'), meta: { title: t('router.signature'), isPermissions: true, showBar: true }, }, { path: '/contract', name: 'contract', component: () => import('@/views/my/contract/index.vue'), meta: { title: t('router.contract'), isPermissions: true, showBar: true }, }, { path: '/userInfo2', name: 'userInfo2', component: () => import('@/views/my/userInfo2/index.vue'), meta: { title: t('router.userInfo2'), isPermissions: true, showBar: true }, }, { path: '/userInfo3', name: 'userInfo3', component: () => import('@/views/my/userInfo3/index.vue'), meta: { title: t('router.userInfo3'), isPermissions: true, showBar: true }, }, { path: '/loansInfo', name: 'loansInfo', component: () => import('@/views/loans/info/index.vue'), meta: { title: t('router.loansInfo'), isPermissions: true, showBar: true }, }, { path: '/loansInfo1', name: 'loansInfo1', component: () => import('@/views/loans/info1/index.vue'), meta: { title: t('router.loansInfo1'), isPermissions: true, showBar: true }, }, { path: '/myLoan', name: 'myLoan', component: () => import('@/views/my/myLoan/index.vue'), meta: { title: t('router.myLoan'), isPermissions: true, showBar: true }, }, { path: '/myRepayment', name: 'myRepayment', component: () => import('@/views/my/myRepayment/index.vue'), meta: { title: t('router.myRepayment'), isPermissions: true, showBar: true }, }, { path: '/borrowInfo', name: 'borrowInfo', component: () => import('@/views/borrowInfo/index.vue'), meta: { title: t('router.borrowInfo'), isPermissions: true, showBar: true }, }, { path: '/uploadPassword', name: 'uploadPassword', component: () => import('@/views/uploadPassword/index.vue'), meta: { title: t('router.uploadPassword'), isPermissions: true, showBar: true }, }, { path: '/login', name: 'login', component: () => import('@/views/login/index.vue'), meta: { title: t('router.login'), showBar: false }, }, { path: '/register', name: 'register', component: () => import('@/views/register/index.vue'), meta: { title: t('router.register'), showBar: true }, }, { path: '/forget', name: 'forget', component: () => import('@/views/forget/index.vue'), meta: { title: t('router.forget'), showBar: true }, }, { path: '/agreement', name: 'agreement', component: () => import('@/views/agreement/agreement.vue'), meta: { title: t('router.agreement'), showBar: true }, } ]; //需要验证权限 //普通路由 无需验证权限 const router = createRouter({ history: createWebHashHistory(''), routes: constantRouter, strict: true, scrollBehavior: () => ({ left: 0, top: 0 }), }); // @ts-ignore router.beforeEach(async (to, from, next) => { const dsw = domainStoreWidthOut() if (!dsw.getDomain || dsw.getDomain.length == 0) { const response = await getDomainList() if (response && response.data) { const domain = response.data.split(',') dsw.setDomain(domain) } } // if (to.meta.titleI18n) { // 判断是否有标题 // console.log('sssssss', to.meta.titleI18n) // // document.title = to.meta.title as string; // document.title = t(to.meta.titleI18n as string); // } if (to.meta.isPermissions) { const userStore = useUserStore() if (!userStore.getToken) { next({ path: '/login' }) return } } next() }) export default router;