|
@@ -1,14 +1,25 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, watch } from 'vue'
|
|
|
+import { nextTick, onMounted, provide, ref, watch } from 'vue'
|
|
|
import { useRouter } from 'vue-router';
|
|
|
+import emitter from '@/util/eventBus'
|
|
|
const router = useRouter()
|
|
|
+let nickName = ref<string>('')
|
|
|
+let avatar = ref<string>('')
|
|
|
let isTop = ref(true)
|
|
|
let activeIndex = ref(0)
|
|
|
let menuList = ref(['首页', '优巨引擎官网', '文档中心', '管理中心'])
|
|
|
const container = ref()
|
|
|
let currentRouteName = ref()
|
|
|
+let visible = ref<boolean>(false)
|
|
|
+let isRouterAlive = ref(true);
|
|
|
+const reload = () => {
|
|
|
+ isRouterAlive.value = false;
|
|
|
+ nextTick(() => {
|
|
|
+ isRouterAlive.value = true
|
|
|
+ })
|
|
|
+}
|
|
|
+provide("reload", reload);
|
|
|
watch(() => router.currentRoute.value.name, (newValue, oldValue) => {
|
|
|
- console.log(typeof newValue);
|
|
|
currentRouteName.value = newValue
|
|
|
if (newValue !== 'home') {
|
|
|
if (newValue === 'login') {
|
|
@@ -18,13 +29,34 @@ watch(() => router.currentRoute.value.name, (newValue, oldValue) => {
|
|
|
}
|
|
|
window.removeEventListener('scroll', handleScrollY, true)
|
|
|
} else {
|
|
|
+ isTop.value = true
|
|
|
window.addEventListener('scroll', handleScrollY, true)
|
|
|
}
|
|
|
|
|
|
})
|
|
|
+onMounted(() => {
|
|
|
+ let userInfo = localStorage.getItem('userInfo')
|
|
|
+ if (userInfo) {
|
|
|
+ let info = JSON.parse(userInfo)
|
|
|
+ nickName.value = info.nickname
|
|
|
+ avatar.value = info.avatar
|
|
|
+ }
|
|
|
+ emitter.on('userInfo', (e: any) => {
|
|
|
+ let userInfo = JSON.parse(e)
|
|
|
+ console.log('userInfo:', userInfo);
|
|
|
+ nickName.value = userInfo.nickname
|
|
|
+ avatar.value = userInfo.avatar
|
|
|
+ })
|
|
|
+})
|
|
|
function handleScrollY() {
|
|
|
isTop.value = !container.value.getBoundingClientRect().top
|
|
|
}
|
|
|
+const loginOut = () => {
|
|
|
+ localStorage.clear()
|
|
|
+ visible.value = false
|
|
|
+ nickName.value = ''
|
|
|
+ avatar.value = ''
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -42,20 +74,41 @@ function handleScrollY() {
|
|
|
<div @click="activeIndex = i" class="btn" v-for="(v, i) in menuList" :key="i"
|
|
|
:class="activeIndex === i && !isTop ? 'active-btn' : ''">
|
|
|
{{ v }}</div>
|
|
|
- <div v-if="currentRouteName === 'login'" class="login" @click="router.push('/register')">注册</div>
|
|
|
- <div v-else class="login" @click="router.push('/login')">登录</div>
|
|
|
+ <template v-if="nickName">
|
|
|
+ <a-tooltip placement="bottom" color="white">
|
|
|
+ <template #title>
|
|
|
+ <div class="flex items-center px-10px py-20px cursor-pointer hover:bg-gray-300">
|
|
|
+ <img class="w-18px h-18px mr-10px" src="@/assets/images/18-1.png" alt="">
|
|
|
+ <div class="text-14px font-500 text-dark-400">通知</div>
|
|
|
+ </div>
|
|
|
+ <div style="height: 2px; background-color: #F0F0F0"></div>
|
|
|
+ <div @click="visible = true" class="flex items-center px-10px py-20px cursor-pointer hover:bg-gray-300">
|
|
|
+ <img class="w-18px h-18px mr-10px" src="@/assets/images/18-2.png" alt="">
|
|
|
+ <div class="text-14px font-500 text-dark-400">账号退出</div>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <div class="flex items-center cursor-pointer">
|
|
|
+ <img class="w-30px h-30px rounded-1/2 mr-10px" :src="avatar" alt="">
|
|
|
+ <div class="text-18">{{ nickName }}</div>
|
|
|
+ </div>
|
|
|
+ </a-tooltip>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <div v-if="currentRouteName === 'login'" class="login" @click="router.push('/register')">注册</div>
|
|
|
+ <div v-else class="login" @click="router.push('/login')">登录</div>
|
|
|
+ </template>
|
|
|
</div>
|
|
|
</div>
|
|
|
</a-layout-header>
|
|
|
<!-- 内容 -->
|
|
|
- <a-layout-content class="">
|
|
|
+ <a-layout-content>
|
|
|
<div ref="container" class="lb-container">
|
|
|
- <router-view></router-view>
|
|
|
+ <router-view v-if="isRouterAlive"></router-view>
|
|
|
</div>
|
|
|
</a-layout-content>
|
|
|
<!-- 底部 -->
|
|
|
<a-layout-footer class="footer">
|
|
|
- <div class="name">优巨引擎</div>
|
|
|
+ <!-- <div class="name">优巨引擎</div> -->
|
|
|
<div class="agreement">
|
|
|
<div>开发者服务协议</div>
|
|
|
<div> | </div>
|
|
@@ -64,7 +117,7 @@ function handleScrollY() {
|
|
|
<div>联系我们</div>
|
|
|
</div>
|
|
|
<div class="record-number">
|
|
|
- 备案号:苏ICP备2021010118号
|
|
|
+ 优巨引擎   备案号:苏ICP备2021010118号
|
|
|
</div>
|
|
|
</a-layout-footer>
|
|
|
</a-layout>
|
|
@@ -96,6 +149,9 @@ function handleScrollY() {
|
|
|
</div>
|
|
|
</a-tooltip>
|
|
|
</div>
|
|
|
+ <a-modal centered v-model:visible="visible" ok-text="确认" cancel-text="取消" title="提示" @ok="loginOut">
|
|
|
+ <p>此操作将退出当前登录用户, 是否继续?</p>
|
|
|
+ </a-modal>
|
|
|
</template>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
@@ -124,8 +180,6 @@ function handleScrollY() {
|
|
|
width: 100%;
|
|
|
min-width: 600px;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
.left {
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
@@ -213,12 +267,12 @@ function handleScrollY() {
|
|
|
}
|
|
|
|
|
|
.lb-container {
|
|
|
- min-height: calc(100vh - 110px);
|
|
|
+ min-height: calc(100vh - 80px);
|
|
|
background: white;
|
|
|
}
|
|
|
|
|
|
.footer {
|
|
|
- height: 110px;
|
|
|
+ height: 80px;
|
|
|
padding: 10px 0;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|