提交 60a77629 authored 作者: 王鹏飞's avatar 王鹏飞

chore:增加权限控制

上级 396d4d9a
...@@ -10,6 +10,7 @@ import AppContainer from '@/components/base/AppContainer.vue' ...@@ -10,6 +10,7 @@ import AppContainer from '@/components/base/AppContainer.vue'
import Avatar from '@/components/Avatar.vue' import Avatar from '@/components/Avatar.vue'
import modules from './modules' import modules from './modules'
import { useUserStore } from '@/stores/user'
const app = createApp(App) const app = createApp(App)
// 注册公共组件 // 注册公共组件
...@@ -22,3 +23,6 @@ app.use(router) ...@@ -22,3 +23,6 @@ app.use(router)
app.use(Vant) app.use(Vant)
app.mount('#app') app.mount('#app')
// 初始化用户信息,判断是否登录
useUserStore().getUser()
...@@ -21,6 +21,7 @@ const dataset = reactive<Info>({ loading: false, page: 1, total: 0, list: [] }) ...@@ -21,6 +21,7 @@ const dataset = reactive<Info>({ loading: false, page: 1, total: 0, list: [] })
const showChapterRecord = () => { const showChapterRecord = () => {
chapterVisible.value = true chapterVisible.value = true
dataset.page = 1 dataset.page = 1
dataset.list = []
getChapterRecord() getChapterRecord()
} }
......
...@@ -8,7 +8,7 @@ export const routes: Array<RouteRecordRaw> = [ ...@@ -8,7 +8,7 @@ export const routes: Array<RouteRecordRaw> = [
children: [ children: [
{ path: '', component: () => import('./views/Index.vue') }, { path: '', component: () => import('./views/Index.vue') },
{ name: 'courseView', path: 'view/:id', component: () => import('./views/View.vue'), props: true }, { name: 'courseView', path: 'view/:id', component: () => import('./views/View.vue'), props: true },
{ path: 'publish', component: () => import('./views/Publish.vue') } { path: 'publish', component: () => import('./views/Publish.vue'), meta: { requireLogin: true } }
] ]
} }
] ]
...@@ -5,6 +5,7 @@ export const routes: Array<RouteRecordRaw> = [ ...@@ -5,6 +5,7 @@ export const routes: Array<RouteRecordRaw> = [
{ {
path: '/my', path: '/my',
component: AppLayout, component: AppLayout,
meta: { requireLogin: true },
children: [{ path: '', component: () => import('./views/Index.vue') }] children: [{ path: '', component: () => import('./views/Index.vue') }]
} }
] ]
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue' import { ref, onMounted } from 'vue'
import { getMyInfo } from '../api' import { getMyInfo } from '../api'
import { logout } from '@/api/base'
const info = ref() const info = ref()
const teamInfo = ref() const teamInfo = ref()
const fetchMyInfo = () => { const fetchMyInfo = () => {
...@@ -50,6 +50,13 @@ const menus: Array<{ ...@@ -50,6 +50,13 @@ const menus: Array<{
icon: 'https://webapp-pub.ezijing.com/project/prp-h5/my_menu_6.png' icon: 'https://webapp-pub.ezijing.com/project/prp-h5/my_menu_6.png'
} }
] ]
// 退出登录
const onLogout = () => {
logout().then(() => {
window.location.href = '/'
})
}
</script> </script>
<template> <template>
<div class="my" v-if="info"> <div class="my" v-if="info">
...@@ -79,7 +86,7 @@ const menus: Array<{ ...@@ -79,7 +86,7 @@ const menus: Array<{
</ul> </ul>
</nav> </nav>
</div> </div>
<div class="logout">退出登录</div> <div class="logout" @click="onLogout">退出登录</div>
</div> </div>
</template> </template>
......
...@@ -7,7 +7,7 @@ export const routes: Array<RouteRecordRaw> = [ ...@@ -7,7 +7,7 @@ export const routes: Array<RouteRecordRaw> = [
component: AppLayout, component: AppLayout,
children: [ children: [
{ path: '', component: () => import('./views/Index.vue') }, { path: '', component: () => import('./views/Index.vue') },
{ path: 'publish', component: () => import('./views/Publish.vue') } { path: 'publish', component: () => import('./views/Publish.vue'), meta: { requireLogin: true } }
] ]
} }
] ]
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
// import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
routes: [{ path: '/:pathMatch(.*)*', redirect: '/' }] routes: [{ path: '/:pathMatch(.*)*', redirect: '/' }]
}) })
// router.beforeEach((to, from, next) => { router.beforeEach(async (to, from, next) => {
// const user = useUserStore() const user = useUserStore()
// user.getUser() if (to.meta.requireLogin && !user.isLogin) {
// next() location.href = `${import.meta.env.VITE_LOGIN_URL}?rd=${encodeURIComponent(location.href)}`
// }) }
next()
})
export default router export default router
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论