| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import * as VueRouter from 'vue-router'
- import { useUserStore } from '@/store'
- const DEFAULT_LAYOUT = () => import('@/layout/default-layout.vue')
- import { Message } from '@arco-design/web-vue'
- const routes = [
- {
- path: "/",
- name: "main",
- component: () => import('../pages/Main/Main.vue'),
- meta: {
- hideInMenu: true
- }
- },
- {
- path: "/login",
- name: "login",
- component: () => import('../pages/login/login.vue'),
- meta: {
- title: '用户登录',
- hideInMenu: true
- }
- },
- {
- path: "/store",
- name: 'store',
- redirect: '/store/goodsList',
- component: DEFAULT_LAYOUT,
- meta: {
- title: 'Forge商城',
- icon: 'icon-gift'
- },
- children: [
- {
- path: 'goodsList',
- name: 'store.goodsList',
- component: () => import('../pages/store/goodsList/index.vue'),
- meta: {
- title: '商品列表'
- }
- },
- {
- path: 'goodsDetail/:id',
- name: 'store.goodsDetail',
- component: () => import('../pages/store/goodsDetail/index.vue'),
- meta: {
- title: '商品详情',
- hideInMenu: true
- }
- },
- {
- path: 'orderDetail/:id',
- name: 'store.orderDetail',
- component: () => import('../pages/store/orders/orderDetail/index.vue'),
- meta: {
- title: '订单详情',
- hideInMenu: true
- }
- },
- {
- path: 'myOrder',
- name: 'store.myOrder',
- component: () => import('../pages/store/orders/orderList/index.vue'),
- meta: {
- title: '我的订单'
- }
- },
- ]
- },
- {
- path: "/lepao",
- name: 'lepao',
- redirect: '/lepao/accountList',
- component: DEFAULT_LAYOUT,
- meta: {
- title: '校园乐跑',
- icon: 'icon-robot'
- },
- children: [
- {
- path: 'accountList',
- name: 'lepao.accountList',
- component: () => import('../pages/lepao/accountList/index.vue'),
- meta: {
- title: '账号管理'
- }
- },
- {
- path: 'lepaoRecords',
- name: 'lepao.lepaoRecords',
- component: () => import('../pages/lepao/lepaoRecords/index.vue'),
- meta: {
- title: '乐跑记录'
- }
- },
- {
- path: 'recordDetail/:id',
- name: 'lepao.recordDetail',
- component: () => import('../pages/lepao/lepaoRecords/recordDetail.vue'),
- meta: {
- title: '路线详情',
- hideInMenu: true
- }
- }
- ]
- },
- {
- path: "/user",
- name: "user",
- redirect: '/user/setting',
- component: DEFAULT_LAYOUT,
- meta: {
- title: '个人中心',
- icon: 'icon-user'
- },
- children: [
- {
- path: 'setting',
- name: 'user.setings',
- component: () => import('../pages/user/setting/index.vue'),
- meta: {
- title: '用户设置'
- },
- }
- ]
- },
- {
- path: "/path",
- name: "path",
- redirect: '/path/list',
- component: DEFAULT_LAYOUT,
- meta: {
- title: '路径数据',
- icon: 'icon-location',
- permission: ['admin', 'path']
- },
- children: [
- {
- path: 'list',
- name: 'path.list',
- component: () => import('../pages/path/pathList.vue'),
- meta: {
- title: '路径列表'
- }
- },
- {
- path: 'detail/:id',
- name: 'path.detail',
- component: () => import('../pages/path/pathDetail.vue'),
- meta: {
- title: '路径详情',
- hideInMenu: true
- }
- }
- ]
- },
- ]
- const router = VueRouter.createRouter({
- history: VueRouter.createWebHashHistory(),
- routes: routes
- })
- const allow = ['/', '/login']
- router.beforeEach(async (to, from, next) => {
- if (!allow.includes(to.path)) {
- const userStore = useUserStore()
- let user = await userStore.getInfo()
- if (!user || !user.uuid || !user.session) {
- // Message.error('请先登录')
- return router.push(`/login?from=${to.path}`)
- }
- }
- if (!to.meta.title) {
- document.title = 'RunForge - 让跑步的意义由技术重新定义'
- } else {
- document.title = to.meta.title + ' - RunForge'
- }
- next()
- })
- export { routes, router };
|