ch-tgr/src/router.js
2026-05-21 09:09:54 +08:00

359 lines
8.3 KiB
JavaScript

import { createRouter, createWebHashHistory } from 'vue-router'
import { useUserStore } from './stores/user'
const routes = [
{
path: '/',
name: 'Index',
component: () => import('./views/Index.vue'),
redirect: '/Home',
children: [
{
path: '/Home',
name: 'Home',
component: () => import('./views/Tabbars/Home.vue'),
meta: { title: '主页', cache: true }
},
{
path: '/Gift',
name: 'Gift',
component: () => import('./views/Tabbars/Gift.vue'),
meta: { title: '礼品区', cache: true }
},
{
path: '/Mall',
name: 'Mall',
component: () => import('./views/Tabbars/Mall.vue'),
meta: { title: '商城', cache: true }
},
{
path: '/My',
name: 'My',
component: () => import('./views/User/My.vue'),
meta: { title: '我的' }
},
],
meta: { noLogin: true }
},
{
path: '/Login',
name: 'Login',
component: () => import('./views/Account/Login.vue'),
meta: {
title: '登录',
noLogin: true,
noRefresh: true,
}
},
{
path: '/ResetPwd',
name: 'ResetPwd',
component: () => import('./views/Account/ResetPwd.vue'),
meta: {
title: '找回密码',
noLogin: true,
}
},
{
path: '/Balance',
name: 'Balance',
component: () => import('./views/User/Wallet/Balance.vue'),
meta: {
title: '余额',
}
},
{
path: '/CV',
name: 'CV',
component: () => import('./views/User/Wallet/CV.vue'),
meta: {
title: '会员卡额度',
}
},
{
path: '/Point',
name: 'Point',
component: () => import('./views/User/Wallet/Point.vue'),
meta: {
title: '积分',
}
},
{
path: '/Allow',
name: 'Allow',
component: () => import('./views/User/Wallet/Allow.vue'),
meta: {
title: '业绩统计',
}
},
{
path: '/Certificate',
name: 'Certificate',
component: () => import('./views/User/Wallet/Certificate.vue'),
meta: {
title: '礼品券',
}
},
{
path: '/Transfer',
name: 'Transfer',
component: () => import('./views/User/Wallet/Transfer.vue'),
meta: {
title: '互转',
}
},
{
path: '/CashoutRecord',
name: 'CashoutRecord',
component: () => import('./views/Cashout/CashoutRecord.vue'),
meta: {
title: '提现记录',
}
},
{
path: '/Cashout',
name: 'Cashout',
component: () => import('./views/Cashout/Cashout.vue'),
meta: {
title: '提现',
}
},
{
path: '/Service',
name: 'Service',
component: () => import('./views/User/Service.vue'),
meta: { title: '客服中心' }
},
{
path: '/Address',
name: 'Address',
component: () => import('./views/User/Address.vue'),
meta: { title: '收货地址' }
},
{
path: '/Invite',
name: 'Invite',
component: () => import('./views/User/Invite.vue'),
meta: { title: '邀请码' }
},
{
path: '/Team',
name: 'Team',
component: () => import('./views/User/Team.vue'),
meta: { title: '我的好友' }
},
{
path: '/CashoutAccount',
name: 'CashoutAccount',
component: () => import('./views/Cashout/CashoutAccount.vue'),
meta: { title: '提现账号' }
},
{
path: '/TradeConfirm',
name: 'TradeConfirm',
component: () => import('./views/Trade/TradeConfirm.vue'),
meta: { title: '确认订单' }
},
{
path: '/TradeDetail',
name: 'TradeDetail',
component: () => import('./views/Trade/TradeDetail.vue'),
meta: { title: '订单详情' }
},
{
path: '/TradeList',
name: 'TradeList',
component: () => import('./views/Trade/TradeList.vue'),
meta: { title: '订单列表' }
},
{
path: '/Pay',
name: 'Pay',
component: () => import('./views/Trade/Pay.vue'),
meta: { title: '支付' }
},
{
path: '/Business_School',
name: 'Business_School',
component: () => import('./views/Platform/Business_School.vue'),
meta: { title: '商学院' }
},
{
path: '/School_detail',
name: 'School_detail',
component: () => import('./views/Platform/School_Detail.vue'),
meta: { title: '商学院详情' }
},
{
path: '/School_Category',
name: 'School_Category',
component: () => import('./views/Platform/School_Category.vue'),
meta: { title: '商学院分类' }
},
{
path: '/Column',
name: 'Column',
component: () => import('./views/Platform/Column.vue'),
meta: { title: '栏目列表' }
},
{
path: '/ColumnDetail',
name: 'ColumnDetail',
component: () => import('./views/Platform/ColumnDetail.vue'),
meta: { title: '栏目详情' }
},
{
path: '/GoodsDetail',
name: 'GoodsDetail',
component: () => import('./views/Goods/GoodsDetail.vue'),
meta: { title: '商品详情' }
},
{
path: '/Category',
name: 'Category',
component: () => import('./views/Goods/Category.vue'),
meta: { title: '全部分类' }
},
{
path: '/Operations',
name: 'Operations',
component: () => import('./views/Operations/Operations.vue'),
meta: { title: '运营中心' }
},
{
path: '/CertificateRecord',
name: 'CertificateRecord',
component: () => import('./views/User/Wallet/CertificateRecord.vue'),
meta: { title: '核销记录' }
},
{
path: '/Merchant',
name: 'Merchant',
component: () => import('./views/Merchant/Merchant.vue'),
meta: { title: '商家中心' }
},
{
path: '/MerchantIncome',
name: 'MerchantIncome',
component: () => import('./views/Merchant/MerchantIncome.vue'),
meta: { title: '营业收入' }
},
{
path: '/MerchantCashout',
name: 'MerchantCashout',
component: () => import('./views/Merchant/MerchantCashout.vue'),
meta: { title: '提现记录' }
},
{
path: '/Statistics',
name: 'Statistics',
component: () => import('./views/Merchant/Statistics.vue'),
meta: { title: '数据统计' }
},
{
path: '/MerchantTrade',
name: 'MerchantTrade',
component: () => import('./views/Merchant/MerchantTrade.vue'),
meta: { title: '商家订单' }
},
{
path: '/MerchantTradeDetail',
name: 'MerchantTradeDetail',
component: () => import('./views/Merchant/MerchantTradeDetail.vue'),
meta: { title: '订单详情' }
},
{
path: '/MerchantIntroduction',
name: 'MerchantIntroduction',
component: () => import('./views/Merchant/MerchantIntroduction.vue'),
meta: { title: '商家资料' }
},
{
path: '/PayCode',
name: 'PayCode',
component: () => import('./views/Merchant/PayCode.vue'),
meta: { title: '收款码' }
},
{
path: '/QrReader',
name: 'QrReader',
component: () => import('./views/Operations/QrReader.vue'),
meta: { title: '扫一扫' }
},
{
path: '/Checkout',
name: 'Checkout',
component: () => import('./views/User/Checkout/Checkout.vue'),
meta: { title: '买单' }
},
{
path: '/CheckoutTrade',
name: 'CheckoutTrade',
component: () => import('./views/User/Checkout/CheckoutTrade.vue'),
meta: { title: '订单详情' }
},
{
path: '/Refresh',
name: 'Refresh',
component: { render: () => null },
meta: { noLogin: true },
beforeRouteEnter(to, from, next) {
next(vm => {
setTimeout(() => {
const redirect = to.query.redirect || '/Home'
vm.$router.replace(decodeURIComponent(redirect))
}, 50)
})
}
},
{
path: '/SyncAuth',
name: 'SyncAuth',
component: () => import('./views/SyncAuth.vue'),
},
{
path: '/404',
name: '404',
component: () => import('./views/404.vue'),
meta: {
title: '404',
noLogin: true,
}
},
{
path: '/:pathMatch(.*)',
redirect: '/404'
}
]
export { routes }
const router = createRouter({
history: createWebHashHistory(),
routes,
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition;
}
return { top: 0 };
},
})
export default router
// 全局前置守卫
router.beforeEach((to, from, next) => {
const userStore = useUserStore();
if (to.meta.title) {
document.title = to.meta.title;
}
if (to.meta.noLogin) {
return next();
}
const isLogin = userStore.isLogin;
if (!isLogin) {
return next({ name: 'Login', query: { redirect: to.fullPath } });
}
next();
});