Compare commits

...

2 Commits

Author SHA1 Message Date
龚皓 80738cb2a0 头部改侧边栏 2024-09-05 09:17:56 +08:00
龚皓 15235c09ad 全局边距设置 2024-09-05 09:16:58 +08:00
2 changed files with 59 additions and 136 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div id="app"> <div id="app" class="app-container">
<router-view></router-view> <router-view></router-view>
</div> </div>
</template> </template>
@ -13,5 +13,14 @@ export default {
</script> </script>
<style scoped> <style scoped>
/* 添加你的样式 */ #app{
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
}
/* .app-container{
margin: 0;
padding: 0;
} */
</style> </style>

View File

@ -1,167 +1,81 @@
<template> <template>
<div id="layout"> <div id="layout" class="layout-container">
<el-header > <el-aside width="200px" class="nav-sidebar">
<div class="logo"> <div class="logo">
<span>管理平台</span> <el-image src="/logo.png" fit="contain" />
</div> </div>
<div class="nav-menu"> <el-menu :default-active="activeIndex" class="el-menu-part" router>
<el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" router> <el-menu-item index="/">告警管理</el-menu-item>
<el-menu-item index="/" style="margin-left:230px">告警管理</el-menu-item> <el-menu-item index="/test">测试</el-menu-item>
</el-menu> </el-menu>
</div> </el-aside>
<div class="user-info">
<span>客流分析</span> <el-main class="main-content">
<span>|</span> <router-view />
<span @click="showDialog = true" style="cursor: pointer;">选择摊位</span> </el-main>
<span v-if="selectedStoreName">| 已选择: {{ selectedStoreName }}</span>
<span>|</span>
<span>区域管理</span>
<el-dropdown @command="handleCommand" placement="bottom-end">
<span class="el-dropdown-link">
{{ username }} <i class="el-icon-arrow-down el-icon--right"></i>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="logout">登出</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</el-header>
<router-view />
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent, ref, computed, watch, onMounted } from 'vue'; import { ref, watch } from 'vue';
import { useRouter, useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
// import type { Store } from '@/utils/type'
export default defineComponent({ const route = useRoute();
name: 'Layout', const activeIndex = ref(route.path);
components: {
},
setup() {
const router = useRouter();
const route = useRoute();
const token = ref(localStorage.getItem('token') || '');
const isUserLoggedIn = computed(() => !!token.value);
const username = ref(localStorage.getItem('username') || '');
// const isUserLoggedIn = computed(() => !!username.value);
const activeIndex = ref(route.path);
const showDialog = ref(false);
// const selectedStore = ref<Store | null>(null);
const selectedStoreName = ref(localStorage.getItem('store_name') || '');
watch(
const handleCommand = (command: string) => { () => route.path,
if (command === 'logout') { (newPath) => {
localStorage.removeItem('username'); activeIndex.value = newPath;
localStorage.removeItem('token'); }
localStorage.removeItem('store_id'); );
localStorage.removeItem('store_name');
token.value = '';
username.value = '';
selectedStoreName.value = '';
router.push('/login');
}
};
watch(
() => route.path,
(newPath) => {
activeIndex.value = newPath;
// if (!token.value && newPath !== '/login') {
// router.push('/login');
// }
}
);
onMounted(() => {
// if (!token.value) {
// router.push('/login');
// } else {
// selectedStoreName.value = localStorage.getItem('store_name') || '';
// }
});
return {
username,
token,
isUserLoggedIn,
activeIndex,
handleCommand,
showDialog,
selectedStoreName,
};
},
});
</script> </script>
<style scoped> <style scoped>
.el-header { .layout-container {
background-color: #1f2d3d;
color: #fff;
display: flex; display: flex;
justify-content: space-between; height: 100%;
align-items: center; width: 100%;
padding: 0 20px; margin: 1px;
margin: 10px 20x; /* padding: 1px; */
}
.nav-sidebar {
background-color: #1f2d3d;
/* width: 200px; */
color: #fff;
} }
.logo { .logo {
display: flex;
align-items: center;
margin-right: 10px;
}
.nav-menu {
flex-grow: 1;
display: flex; display: flex;
justify-content: center; justify-content: center;
margin-left: 110px; margin-bottom: 30px;
margin-right: 100px;
} }
.el-menu-demo { .el-menu-part {
background-color: transparent; background-color: transparent;
color: #fff; color: #fff;
display: flex; border: 1px;
justify-content: space-between; /* width: 200px; */
/* justify-content: flex-start; */
flex-grow: 1;
} }
.el-menu-demo .el-menu-item { .el-menu-part .el-menu-item {
padding: 0 20px; /* padding:30px 0; */
padding: 0px;
margin: 0;
text-align: center; text-align: center;
font-size: 16px; font-size: 16px;
color: #fff;
font-weight: bold; font-weight: bold;
color: #fff;
} }
.el-menu-demo .el-menu-item:hover { .el-menu-part .el-menu-item:hover {
color: #00aaff; color: #00aaff;
} }
.main-content {
.user-info { flex-grow: 1;
display: flex; padding: 20px;
align-items: center;
gap: 10px;
margin-left: 10px;
}
.user-info span {
color: #fff;
}
.el-dropdown-link {
cursor: pointer;
color: #fff;
display: flex;
align-items: center;
} }
</style> </style>