File size: 5,643 Bytes
77b0e0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/login/LoginView.vue'),
      meta: {
        title: '登录页' // 面包屑显示标题
      }
    },
    {
      path: '/',
      redirect: { name: 'Home' },
      component: () => import('@/layouts/BaseLayout.vue'),
      meta: {
        requiresAuth: true // 是否需要登录验证,配置根路由即可,子路由会继承
      },
      children: [
        {
          path: '/home',
          name: 'Home',
          component: () => import('@/views/home/HomeView.vue'),
          meta: { title: '主页' }
        },
        // ---------------------
        //       商品
        // ---------------------
        {
          path: '/product',
          name: 'Product',
          redirect: { name: 'ProductList' },
          meta: { title: '商品管理' },
          children: [
            {
              path: '/product/list',
              name: 'ProductList',
              component: () => import('@/views/product/ProductListView.vue'),
              meta: { title: '商品列表' }
            },
            {
              path: '/product/create',
              name: 'ProductCreate',
              component: () => import('@/views/product/ProductEditView.vue'),
              meta: { title: '新增商品' }
            },
            {
              path: '/product/:productId/edit',
              name: 'ProductEdit',
              component: () => import('@/views/product/ProductEditView.vue'),
              meta: { title: '商品修改' },
              props: true
            }
          ]
        },
        // ---------------------
        //       数字人管理
        // ---------------------
        {
          path: '/digital_human',
          name: 'DigitalHuman',
          redirect: { name: 'DigitalHumanList' },
          meta: { title: '数字人管理' },
          children: [
            {
              path: '/digital_human/list',
              name: 'DigitalHumanList',
              component: () => import('@/views/digital-human/DigitalHumanView.vue'),
              meta: { title: '角色管理' }
            }
          ]
        },
        // ---------------------
        //       直播管理
        // ---------------------

        {
          path: '/streaming',
          name: 'Streaming',
          redirect: { name: 'StreamingOverview' },
          meta: { title: '直播管理' },
          children: [
            {
              path: '/streaming/overview',
              name: 'StreamingOverview',
              component: () => import('@/views/streaming/StreamingRoomListView.vue'),
              meta: { title: '直播间管理' }
            },
            {
              path: '/streaming/create',
              name: 'StreamingCreate',
              component: () => import('@/views/streaming/StreamingRoomeEditView.vue'),
              meta: { title: '新建直播间' }
            },
            {
              path: '/streaming/:roomId/edit',
              name: 'StreamingEdit',
              component: () => import('@/views/streaming/StreamingRoomeEditView.vue'),
              meta: { title: '编辑直播间' },
              props: true
            },
            {
              path: '/streaming/:roomId/on-air',
              name: 'StreamingOnAir',
              component: () => import('@/views/streaming/StreamingOnAirView.vue'),
              meta: { title: '直播间' },
              props: true
            }
          ]
        },
        // ---------------------
        //       订单管理
        // ---------------------
        {
          path: '/order',
          name: 'Order',
          redirect: { name: 'OrderOverview' },
          meta: { title: '订单管理' },
          children: [
            {
              path: '/order/overview',
              name: 'OrderOverview',
              component: () => import('@/views/order/OrderView.vue'),
              meta: { title: '订单管理' }
            }
          ]
        },
        // ---------------------
        //       系统配置
        // ---------------------
        {
          path: '/system',
          name: 'System',
          redirect: { name: 'SystemPlugins' },
          meta: { title: '系统配置' },
          children: [
            {
              path: '/system/plugins',
              name: 'SystemPlugins',
              component: () => import('@/views/system/SystemPluginsView.vue'),
              meta: { title: '组件状态' }
            }
          ]
        }
      ]
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      component: () => import('@/views/error/NotFound.vue'),
      meta: { title: '404' }
    }
  ]
})

import { useTokenStore } from '@/stores/userToken'

router.beforeEach((to, from, next) => {
  if (to.matched.some((r) => r.meta?.requiresAuth)) {
    // 登录状态缓存
    const tokenStore = useTokenStore()

    if (!tokenStore.token.access_token) {
      // 没有登录,跳转登录页面,同时记录 想去的地址 to.fullPath,方便执行登陆后跳转回去
      next({ name: 'Login', query: { redirect: to.fullPath } })
      return
    }
  }
  // 动态更改页面 title
  to.matched.some((item) => {
    if (!item.meta.title) return ''

    const Title = '销冠——卖货主播大模型'
    if (Title) document.title = `${item.meta.title} | ${Title}`
    else document.title = item.meta.title as string
  })

  next()
})

export default router