import ts

pull/301/head
mistery-li 2021-08-03 13:17:15 +08:00
parent 20311d02df
commit ca28189057
2 changed files with 290 additions and 249 deletions

View File

@ -1,162 +1,171 @@
<template> <template>
<div class="header"> <div class="header">
<!-- 折叠按钮 --> <!-- 折叠按钮 -->
<div class="collapse-btn" @click="collapseChage"> <div class="collapse-btn" @click="collapseChage">
<i v-if="!collapse" class="el-icon-s-fold"></i> <i v-if="!collapse" class="el-icon-s-fold"></i>
<i v-else class="el-icon-s-unfold"></i> <i v-else class="el-icon-s-unfold"></i>
</div>
<div class="logo">后台管理系统</div>
<div class="header-right">
<div class="header-user-con">
<!-- 消息中心 -->
<div class="btn-bell">
<el-tooltip effect="dark" :content="message?`有${message}条未读消息`:`消息中心`" placement="bottom">
<router-link to="/tabs">
<i class="el-icon-bell"></i>
</router-link>
</el-tooltip>
<span class="btn-bell-badge" v-if="message"></span>
</div>
<!-- 用户头像 -->
<div class="user-avator">
<img src="../assets/img/img.jpg" />
</div>
<!-- 用户名下拉菜单 -->
<el-dropdown class="user-name" trigger="click" @command="handleCommand">
<span class="el-dropdown-link">
{{username}}
<i class="el-icon-caret-bottom"></i>
</span>
<template #dropdown>
<el-dropdown-menu>
<a href="https://github.com/lin-xin/vue-manage-system" target="_blank">
<el-dropdown-item>项目仓库</el-dropdown-item>
</a>
<el-dropdown-item command="user">个人中心</el-dropdown-item>
<el-dropdown-item divided command="loginout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</div> </div>
<div class="logo">后台管理系统</div>
<div class="header-right">
<div class="header-user-con">
<!-- 消息中心 -->
<div class="btn-bell">
<el-tooltip
effect="dark"
:content="message ? `有${message}条未读消息` : `消息中心`"
placement="bottom"
>
<router-link to="/tabs">
<i class="el-icon-bell"></i>
</router-link>
</el-tooltip>
<span class="btn-bell-badge" v-if="message"></span>
</div>
<!-- 用户头像 -->
<div class="user-avator">
<img src="../assets/img/img.jpg" />
</div>
<!-- 用户名下拉菜单 -->
<el-dropdown class="user-name" trigger="click" @command="handleCommand">
<span class="el-dropdown-link">
{{ username }}
<i class="el-icon-caret-bottom"></i>
</span>
<template #dropdown>
<el-dropdown-menu>
<a
href="https://github.com/lin-xin/vue-manage-system"
target="_blank"
>
<el-dropdown-item>项目仓库</el-dropdown-item>
</a>
<el-dropdown-item command="user">个人中心</el-dropdown-item>
<el-dropdown-item divided command="loginout"
>退出登录</el-dropdown-item
>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, onMounted } from "vue"; import { computed, onMounted, ref } from "vue";
import { useStore } from "vuex"; import { useStore } from "vuex";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
export default { export default {
setup() { setup() {
const username = localStorage.getItem("ms_username"); const username = localStorage.getItem("ms_username");
const message = 2; const message = ref(2);
const store = useStore(); const store = useStore();
const collapse = computed(() => store.state.collapse); const collapse = computed(() => store.state.collapse);
// //
const collapseChage = () => { const collapseChage = () => {
store.commit("handleCollapse", !collapse.value); store.commit("handleCollapse", !collapse.value);
}; };
onMounted(() => { onMounted(() => {
if (document.body.clientWidth < 1500) { if (document.body.clientWidth < 1500) {
collapseChage(); collapseChage();
} }
}); });
// //
const router = useRouter(); const router = useRouter();
const handleCommand = (command) => { const handleCommand = (command) => {
if (command == "loginout") { if (command == "loginout") {
localStorage.removeItem("ms_username"); localStorage.removeItem("ms_username");
router.push("/login"); router.push("/login");
} else if (command == "user") { } else if (command == "user") {
router.push("/user"); router.push("/user");
} }
}; };
return { return {
username, username,
message, message,
collapse, collapse,
collapseChage, collapseChage,
handleCommand, handleCommand,
}; };
}, },
}; };
</script> </script>
<style scoped> <style scoped>
.header { .header {
position: relative; position: relative;
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
height: 70px; height: 70px;
font-size: 22px; font-size: 22px;
color: #fff; color: #fff;
} }
.collapse-btn { .collapse-btn {
float: left; float: left;
padding: 0 21px; padding: 0 21px;
cursor: pointer; cursor: pointer;
line-height: 70px; line-height: 70px;
} }
.header .logo { .header .logo {
float: left; float: left;
width: 250px; width: 250px;
line-height: 70px; line-height: 70px;
} }
.header-right { .header-right {
float: right; float: right;
padding-right: 50px; padding-right: 50px;
} }
.header-user-con { .header-user-con {
display: flex; display: flex;
height: 70px; height: 70px;
align-items: center; align-items: center;
} }
.btn-fullscreen { .btn-fullscreen {
transform: rotate(45deg); transform: rotate(45deg);
margin-right: 5px; margin-right: 5px;
font-size: 24px; font-size: 24px;
} }
.btn-bell, .btn-bell,
.btn-fullscreen { .btn-fullscreen {
position: relative; position: relative;
width: 30px; width: 30px;
height: 30px; height: 30px;
text-align: center; text-align: center;
border-radius: 15px; border-radius: 15px;
cursor: pointer; cursor: pointer;
} }
.btn-bell-badge { .btn-bell-badge {
position: absolute; position: absolute;
right: 0; right: 0;
top: -2px; top: -2px;
width: 8px; width: 8px;
height: 8px; height: 8px;
border-radius: 4px; border-radius: 4px;
background: #f56c6c; background: #f56c6c;
color: #fff; color: #fff;
} }
.btn-bell .el-icon-bell { .btn-bell .el-icon-bell {
color: #fff; color: #fff;
} }
.user-name { .user-name {
margin-left: 10px; margin-left: 10px;
} }
.user-avator { .user-avator {
margin-left: 20px; margin-left: 20px;
} }
.user-avator img { .user-avator img {
display: block; display: block;
width: 40px; width: 40px;
height: 40px; height: 40px;
border-radius: 50%; border-radius: 50%;
} }
.el-dropdown-link { .el-dropdown-link {
color: #fff; color: #fff;
cursor: pointer; cursor: pointer;
} }
.el-dropdown-menu__item { .el-dropdown-menu__item {
text-align: center; text-align: center;
} }
</style> </style>

View File

@ -1,154 +1,186 @@
<template> <template>
<div class="sidebar"> <div class="sidebar">
<el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157" <el-menu
text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router> class="sidebar-el-menu"
<template v-for="item in items"> :default-active="onRoutes"
<template v-if="item.subs"> :collapse="collapse"
<el-submenu :index="item.index" :key="item.index"> background-color="#324157"
<template #title> text-color="#bfcbd9"
<i :class="item.icon"></i> active-text-color="#20a0ff"
<span>{{ item.title }}</span> unique-opened
</template> router
<template v-for="subItem in item.subs"> >
<el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index"> <template v-for="item in items">
<template #title>{{ subItem.title }}</template> <template v-if="item.subs">
<el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index"> <el-submenu :index="item.index" :key="item.index">
{{ threeItem.title }}</el-menu-item> <template #title>
</el-submenu> <i :class="item.icon"></i>
<el-menu-item v-else :index="subItem.index" :key="subItem.index">{{ subItem.title }} <span>{{ item.title }}</span>
</el-menu-item>
</template>
</el-submenu>
</template>
<template v-else>
<el-menu-item :index="item.index" :key="item.index">
<i :class="item.icon"></i>
<template #title>{{ item.title }}</template>
</el-menu-item>
</template>
</template> </template>
</el-menu> <template v-for="subItem in item.subs">
</div> <el-submenu
v-if="subItem.subs"
:index="subItem.index"
:key="subItem.index"
>
<template #title>{{ subItem.title }}</template>
<el-menu-item
v-for="(threeItem, i) in subItem.subs"
:key="i"
:index="threeItem.index"
>
{{ threeItem.title }}</el-menu-item
>
</el-submenu>
<el-menu-item v-else :index="subItem.index" :key="subItem.index"
>{{ subItem.title }}
</el-menu-item>
</template>
</el-submenu>
</template>
<template v-else>
<el-menu-item :index="item.index" :key="item.index">
<i :class="item.icon"></i>
<template #title>{{ item.title }}</template>
</el-menu-item>
</template>
</template>
</el-menu>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, watch } from "vue"; import { computed, defineComponent } from "vue";
import { useStore } from "vuex"; import { useStore } from "vuex";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
export default {
setup() {
const items = [
{
icon: "el-icon-lx-home",
index: "/dashboard",
title: "系统首页",
},
{
icon: "el-icon-lx-cascades",
index: "/table",
title: "基础表格",
},
{
icon: "el-icon-lx-copy",
index: "/tabs",
title: "tab选项卡",
},
{
icon: "el-icon-lx-calendar",
index: "3",
title: "表单相关",
subs: [
{
index: "/form",
title: "基本表单",
},
{
index: "/upload",
title: "文件上传",
},
{
index: "4",
title: "三级菜单",
subs: [
{
index: "/editor",
title: "富文本编辑器",
},
],
},
],
},
{
icon: "el-icon-lx-emoji",
index: "/icon",
title: "自定义图标",
},
{
icon: "el-icon-pie-chart",
index: "/charts",
title: "schart图表",
},
{
icon: "el-icon-lx-global",
index: "/i18n",
title: "国际化功能",
},
{
icon: "el-icon-lx-warn",
index: "7",
title: "错误处理",
subs: [
{
index: "/permission",
title: "权限测试",
},
{
index: "/404",
title: "404页面",
},
],
},
{
icon: "el-icon-lx-redpacket_fill",
index: "/donate",
title: "支持作者",
},
];
const route = useRoute(); interface menuItem {
icon: string;
index: string;
title: string;
subs?: subItem[];
}
const onRoutes = computed(() => { interface subItem {
return route.path; index: string;
}); title: string;
subs?: subItem[];
}
const store = useStore(); export default defineComponent({
const collapse = computed(() => store.state.collapse); setup() {
const items: menuItem[] = [
{
icon: "el-icon-lx-home",
index: "/dashboard",
title: "系统首页",
},
{
icon: "el-icon-lx-cascades",
index: "/table",
title: "基础表格",
},
{
icon: "el-icon-lx-copy",
index: "/tabs",
title: "tab选项卡",
},
{
icon: "el-icon-lx-calendar",
index: "3",
title: "表单相关",
subs: [
{
index: "/form",
title: "基本表单",
},
{
index: "/upload",
title: "文件上传",
},
{
index: "4",
title: "三级菜单",
subs: [
{
index: "/editor",
title: "富文本编辑器",
},
],
},
],
},
{
icon: "el-icon-lx-emoji",
index: "/icon",
title: "自定义图标",
},
{
icon: "el-icon-pie-chart",
index: "/charts",
title: "schart图表",
},
{
icon: "el-icon-lx-global",
index: "/i18n",
title: "国际化功能",
},
{
icon: "el-icon-lx-warn",
index: "7",
title: "错误处理",
subs: [
{
index: "/permission",
title: "权限测试",
},
{
index: "/404",
title: "404页面",
},
],
},
{
icon: "el-icon-lx-redpacket_fill",
index: "/donate",
title: "支持作者",
},
];
return { const route = useRoute();
items,
onRoutes, const onRoutes = computed(() => {
collapse, return route.path;
}; });
},
}; const store = useStore();
const collapse = computed(() => store.state.collapse);
return {
items,
onRoutes,
collapse,
};
},
});
</script> </script>
<style scoped> <style scoped>
.sidebar { .sidebar {
display: block; display: block;
position: absolute; position: absolute;
left: 0; left: 0;
top: 70px; top: 70px;
bottom: 0; bottom: 0;
overflow-y: scroll; overflow-y: scroll;
} }
.sidebar::-webkit-scrollbar { .sidebar::-webkit-scrollbar {
width: 0; width: 0;
} }
.sidebar-el-menu:not(.el-menu--collapse) { .sidebar-el-menu:not(.el-menu--collapse) {
width: 250px; width: 250px;
} }
.sidebar > ul { .sidebar > ul {
height: 100%; height: 100%;
} }
</style> </style>