提交 98e63c7f authored 作者: 王鹏飞's avatar 王鹏飞

update

上级 b2845271
VITE_LOGIN_URL=https://login.ezijing.com/auth/login/index
VITE_LOGIN_URL=https://login.ezijing.com/auth/login/index
VITE_LOGIN_URL=https://login2.ezijing.com/auth/login/index
/// <reference types="vite/client" /> /// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_LOGIN_URL: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}
import httpRequest from '@/utils/axios'
// 获取用户信息
export function getUser() {
return httpRequest.get('/api/passport/account/get-user-info')
}
// 退出登录
export function logout() {
return httpRequest.get('/api/passport/rest/logout')
}
// 获取oss token
export function getToken() {
return httpRequest.get('/api/usercenter/aliyun/assume-role')
}
// 获取oss signature
export function getSignature() {
return httpRequest.get('/api/usercenter/aliyun/get-signature')
}
// 图片上传
export function uploadFile(data: object) {
return httpRequest.post('https://webapp-pub.oss-cn-beijing.aliyuncs.com', data, {
withCredentials: false,
headers: { 'Content-Type': 'multipart/form-data' }
})
}
<script setup lang="ts"> <script setup lang="ts">
// function logout() { import { useUserStore } from '@/stores/user'
// // this.$store.dispatch('logout').then(() => {
// // window.location.href = `${import.meta.env.VITE_LOGIN_URL}?rd=${encodeURIComponent(window.location.href)}` const user = useUserStore()
// // }) const LOGINURL = `${import.meta.env.VITE_LOGIN_URL}?rd=${encodeURIComponent(location.href)}`
// }
// 退出登录
function handleLogout() {
user.logout().then(() => {
location.href = '/'
})
}
</script> </script>
<template> <template>
...@@ -15,7 +21,12 @@ ...@@ -15,7 +21,12 @@
</div> </div>
<div class="app-name">紫荆教育SAAS平台</div> <div class="app-name">紫荆教育SAAS平台</div>
</div> </div>
<div class="app-header-right"></div> <div class="app-header-right">
<template v-if="user.isLogin">
你好,{{ user.userName }} <span class="app-header-logout" @click="handleLogout">退出</span>
</template>
<template v-else><a :href="LOGINURL">登录</a></template>
</div>
</div> </div>
</header> </header>
</template> </template>
...@@ -57,63 +68,14 @@ ...@@ -57,63 +68,14 @@
} }
.app-header-right { .app-header-right {
display: flex; display: flex;
color: #666;
.avatar { .app-header-logout {
width: 40px; background: url('https://webapp-pub.ezijing.com/project/saas/logout.png') no-repeat left center;
height: 40px; background-size: auto 16px;
border-radius: 50%; padding-left: 22px;
overflow: hidden; margin-left: 40px;
img { cursor: pointer;
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 50%;
overflow: hidden;
}
&:hover {
background-color: rgba(60, 64, 67, 0.08);
}
}
}
.app-header-user {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
padding: 16px;
}
.app-header-user-avatar {
margin-bottom: 6px;
width: 80px;
height: 80px;
border-radius: 50%;
overflow: hidden;
img {
width: 100%;
height: 100%;
object-fit: cover;
}
}
.app-header-user-main {
h3 {
color: #202124;
font: 500 16px/22px Helvetica, Arial, sans-serif;
letter-spacing: 0.29px;
margin: 0;
text-align: center;
text-overflow: ellipsis;
overflow: hidden;
}
p {
color: #5f6368;
font: 400 14px/19px Helvetica, Arial, sans-serif;
letter-spacing: normal;
text-align: center;
text-overflow: ellipsis;
overflow: hidden;
} }
} }
.app-header-user-buttons {
padding-top: 16px;
}
</style> </style>
import type { RouteRecordRaw } from 'vue-router'
import AppLayout from '@/components/layout/Index.vue' import AppLayout from '@/components/layout/Index.vue'
const routes = [ const routes: Array<RouteRecordRaw> = [
{ {
path: '/', path: '/',
component: AppLayout, component: AppLayout,
......
const modules = Object.values(import.meta.globEager('./**/index.js'))
export default function ({ router }) {
modules.forEach(({ routes }) => {
// 注册路由
routes.forEach(route => {
router.addRoute(route)
})
})
}
import type { Router } from 'vue-router'
import type { Module } from '@/types'
export default function ({ router }: { router: Router }) {
const modules: Array<Module> = Object.values(import.meta.globEager('./**/index.ts'))
modules.forEach(({ routes = [] }) => {
// 注册路由
routes.forEach(route => {
router.addRoute(route)
})
})
}
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory } from 'vue-router'
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) => {
const user = useUserStore()
user.getUser()
next()
})
export default router export default router
import { defineStore } from 'pinia'
export const useCounterStore = defineStore({
id: 'counter',
state: () => ({
counter: 0
}),
getters: {
doubleCount: (state) => state.counter * 2
},
actions: {
increment() {
this.counter++
}
}
})
import { defineStore } from 'pinia'
import { getUser, logout } from '@/api/base'
import type { UserState } from '@/types'
export const useUserStore = defineStore({
id: 'user',
state: () => {
return {
user: null as UserState | null
}
},
getters: {
isLogin: state => !!state.user,
userName: ({ user }) => {
if (!user) return ''
return user.realname || user.nickname || user.username || ''
}
},
actions: {
getUser() {
return getUser().then(res => {
this.user = res.data
})
},
logout() {
return logout().then(() => {
this.user = null
})
}
}
})
import type { RouteRecordRaw } from 'vue-router'
export interface UserState {
id: string
avatar: string
mobile: string
realname: string
nickname: string
username: string
}
export interface Module {
routes: Array<RouteRecordRaw>
}
import axios from 'axios' import axios from 'axios'
const httpRequest = axios.create({ const httpRequest = axios.create({
baseURL: 'https://learn-api.ezijing.com',
timeout: 60000, timeout: 60000,
withCredentials: true withCredentials: true
}) })
// 响应拦截 // 响应拦截
httpRequest.interceptors.response.use( httpRequest.interceptors.response.use(
function (response) { function (response) {
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"@/*": ["./src/*"] "@/*": ["./src/*"]
} },
"lib": ["DOM", "ESNext"]
}, },
"references": [ "references": [
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
"include": ["vite.config.*"], "include": ["vite.config.*"],
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
"types": ["node", "vitest"] "types": ["node"]
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论