index.js 3.1 KB
Newer Older
1 2 3 4 5 6 7 8
import Vue from 'vue'
import VueRouter from 'vue-router'
import pathArr from '@/router/pathArr.js'

// 导入需要的组件
import Login from '@/components/MyLogin.vue'
import Home from '@/components/MyHome.vue'

9
import Pic from '@/components/menus/MyPic.vue'
10
import Chat from '@/components/menus/MyChat.vue'
11
import Interview from '@/components/menus/MyInterview.vue'
12
import Algorithmic from '@/components/menus/MyAlgorithmic.vue'
13
import AphorismPoetry from '@/components/menus/MyAphorismPoetry.vue'
14
import MyCsdnUser from '@/components/menus/MyCsdnUser.vue'
15
import MyFansInfo from '@/components/menus/MyFansInfo.vue'
16
import MyAccountManagement from '@/components/menus/MyAccountManagement.vue'
17
import MyMessage from '@/components/menus/MyMessage.vue'
18
import MyArticleInfo from '@/components/menus/MyArticleInfo.vue'
19
import MyTripletDayInfo from '@/components/menus/MyTripletDayInfo.vue'
20
import MyChatDetail from '@/components/user/MyChatDetail.vue'
21
import AddChatDetail from '@/components/user/AddChatDetail.vue'
22

23 24 25
Vue.use(VueRouter)

const router = new VueRouter({
26 27 28 29 30 31 32 33 34 35
	routes: [
		{
			path: '/',
			redirect: '/login',
		},
		// 登录的路由规则
		{
			path: '/login',
			component: Login,
			meta: {
36
				title: '登录',
37 38 39 40 41 42
			},
		},
		// 后台主页的路由规则
		{
			path: '/home',
			component: Home,
43
			redirect: '/home/tripletDayInfo',
44 45
			children: [
				{
46 47
					path: 'tripletDayInfo',
					component: MyTripletDayInfo,
48
					meta: {
49
						title: '三连管理',
50 51 52
					},
				},
				{
53 54
					path: 'csdnUser',
					component: MyCsdnUser,
55
					meta: {
56
						title: '用户管理',
57 58 59
					},
				},
				{
60 61
					path: 'articleInfo',
					component: MyArticleInfo,
62
					meta: {
63 64 65 66 67 68 69 70
						title: '文章管理',
					},
				},
				{
					path: 'accountManagement',
					component: MyAccountManagement,
					meta: {
						title: '余额管理',
71 72 73
					},
				},
				{
74 75
					path: 'message',
					component: MyMessage,
76
					meta: {
77
						title: '私信管理',
78 79
					},
				},
80 81 82 83
				{
					path: 'fansInfo',
					component: MyFansInfo,
					meta: {
84
						title: '粉丝管理',
85 86
					},
				},
87
				{
88 89
					path: 'interview',
					component: Interview,
90
					meta: {
91
						title: '面试题',
92 93 94
					},
				},
				{
95 96
					path: 'algorithmic',
					component: Algorithmic,
97
					meta: {
98
						title: '算法题',
99 100 101
					},
				},
				{
102 103
					path: 'aphorismpoetry',
					component: AphorismPoetry,
104
					meta: {
105
						title: '名言警句',
106 107 108
					},
				},
				{
109 110
					path: 'chat',
					component: Chat,
111
					meta: {
112
						title: 'chatgpt记录',
113 114 115 116 117 118
					},
				},
				{
					path: 'pic',
					component: Pic,
					meta: {
119
						title: '图片',
120 121 122 123 124 125 126
					},
				},
				{
					path: 'chatinfo/:id',
					component: MyChatDetail,
					props: true,
					meta: {
127
						title: 'chat信息',
128 129 130 131 132 133
					},
				},
				{
					path: 'addChat',
					component: AddChatDetail,
					meta: {
134
						title: '添加chat信息',
135 136 137 138 139
					},
				},
			],
		},
	],
140 141 142
})

// 全局前置守卫
143
router.beforeEach(function (to, from, next) {
144 145 146 147 148 149 150 151 152 153
	if (pathArr.indexOf(to.path) !== -1) {
		const token = localStorage.getItem('token')
		if (token) {
			next()
		} else {
			next('/login')
		}
	} else {
		next()
	}
154 155 156
})

export default router