<script setup lang="ts">
import { useRouter } from 'vue-router'
import User from './component/User.vue'
import { onMounted, ref } from 'vue'
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
const router = useRouter()
// 记录切换值
const changeValue = ref('/book/index')

const changeRouters = () => {
	if (changeValue.value == '/book/my') {
		changeValue.value = '/book/index'
	} else if (changeValue.value == '/book/index') {
		changeValue.value = '/book/my'
	}
	router.push(changeValue.value)
}
</script>

<template>
	<div class="bg-color">
		<div class="nav-link">
			<div class="site-nav-bd">
				<ul>
					<li @click="changeRouters">{{ changeValue == '/book/my' ? '商城首页' : '我的淘宝' }}</li>
					<li @click="router.push('/book/trolley')">
						<el-icon>
							<ShoppingCart />
						</el-icon>
						购物车
					</li>
					<li @click="router.push('/book/collection')">
						<el-icon>
							<Collection />
						</el-icon>
						收藏夹
					</li>
				</ul>
				<ul>
					<li v-if="userStore?.token"><User></User></li>
					<li v-else @click="router.push('/login')">登录/注册</li>
				</ul>
			</div>
		</div>
		<div style="height: 35px"></div>
		<router-view></router-view>
	</div>
</template>

<style scoped lang="scss">
.nav-link {
	background-color: #f5f5f5;
	border-bottom: 1px solid #eee;
	width: 100%;
	height: 35px;
	position: fixed;
	top: 0;
	left: 0;
	z-index: 10000;

	.site-nav-bd {
		margin: 0 auto;
		width: 1190px;
		height: 35px;
		background: #f5f5f5;
		display: flex;
		justify-content: space-between;

		ul {
			display: flex;
		}

		ul li {
			list-style-type: none;
			height: 35px;
			margin-right: 15px;
			display: flex;
			align-items: center;
		}

		li:hover {
			color: #ff4400;
			cursor: pointer;
		}
	}
}

.bg-color {
	position: fixed;
	width: 100%;
	height: 100%;
	background-color: #f5f8fa;
	overflow-y: scroll;
}
</style>
