refactor: refactor the frame layout of admin module

This commit is contained in:
RockYang
2023-06-21 14:22:28 +08:00
parent 0e6606e469
commit 3674d9da85
35 changed files with 1758 additions and 334 deletions

View File

@@ -1,14 +1,13 @@
<template>
<el-dialog
v-model="show"
v-model="showDialog"
:close-on-click-modal="false"
:show-close="true"
:before-close="close"
:top="top"
title="用户设置"
>
<div class="user-info" id="user-info">
<el-form :model="form" label-width="120px">
<el-form v-if="form.id" :model="form" label-width="120px">
<el-form-item label="昵称">
<el-input v-model="form['nickname']"/>
</el-form-item>
@@ -77,6 +76,9 @@ const props = defineProps({
models: Array,
});
const showDialog = computed(() => {
return props.show
})
const form = ref({})
const top = computed(() => {
if (window.innerHeight < 768) {

View File

@@ -1,6 +1,6 @@
<template>
<el-dialog
v-model="show"
v-model="showDialog"
:close-on-click-modal="false"
:show-close="true"
:before-close="close"
@@ -32,20 +32,17 @@
</template>
<script setup>
import {onMounted, ref} from "vue"
import {computed, ref} from "vue"
import {httpPost} from "@/utils/http";
import {ElMessage} from "element-plus";
const props = defineProps({
show: Boolean,
});
const form = ref({})
onMounted(() => {
const showDialog = computed(() => {
return props.show
})
const form = ref({})
const emits = defineEmits(['hide', 'logout']);
const save = function () {
if (!form.value['password'] || form.value['password'].length < 8) {

View File

@@ -0,0 +1,168 @@
<template>
<div class="header">
<!-- 折叠按钮 -->
<div class="collapse-btn" @click="collapseChange">
<el-icon v-if="sidebar.collapse">
<Expand/>
</el-icon>
<el-icon v-else>
<Fold/>
</el-icon>
</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"
>
<i class="el-icon-lx-notice"></i>
</el-tooltip>
<span class="btn-bell-badge" v-if="message"></span>
</div>
<!-- 用户头像 -->
<el-avatar class="user-avatar" :size="30" :src="imgUrl"/>
<!-- 用户名下拉菜单 -->
<el-dropdown class="user-name" trigger="click" @command="handleCommand">
<span class="el-dropdown-link">
{{ username }}
<el-icon class="el-icon--right">
<arrow-down/>
</el-icon>
</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="logout">退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</div>
</template>
<script setup>
import {onMounted, ref} from 'vue';
import {useSidebarStore} from '@/store/sidebar';
import {useRouter} from 'vue-router';
import imgUrl from '../../assets/img/avatar.jpg';
import {ArrowDown, Expand, Fold} from "@element-plus/icons-vue";
const message = ref(5);
const username = ref('极客学长')
const sidebar = useSidebarStore();
// 侧边栏折叠
const collapseChange = () => {
sidebar.handleCollapse();
};
onMounted(() => {
if (document.body.clientWidth < 1024) {
collapseChange();
}
});
// 用户名下拉菜单选择事件
const router = useRouter();
const handleCommand = (command) => {
if (command === 'logout') {
localStorage.removeItem('ms_username');
router.push('/login');
}
};
</script>
<style scoped>
.header {
position: relative;
box-sizing: border-box;
width: 100%;
height: 70px;
font-size: 22px;
color: #fff;
}
.collapse-btn {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
float: left;
padding: 0 21px;
cursor: pointer;
}
.header .logo {
float: left;
width: 250px;
line-height: 70px;
}
.header-right {
float: right;
padding-right: 50px;
}
.header-user-con {
display: flex;
height: 70px;
align-items: center;
}
.btn-fullscreen {
transform: rotate(45deg);
margin-right: 5px;
font-size: 24px;
}
.btn-bell,
.btn-fullscreen {
position: relative;
width: 30px;
height: 30px;
text-align: center;
border-radius: 15px;
cursor: pointer;
display: flex;
align-items: center;
}
.btn-bell-badge {
position: absolute;
right: 4px;
top: 0px;
width: 8px;
height: 8px;
border-radius: 4px;
background: #f56c6c;
color: #fff;
}
.btn-bell .el-icon-lx-notice {
color: #fff;
}
.user-name {
margin-left: 10px;
}
.user-avatar {
margin-left: 20px;
}
.el-dropdown-link {
color: #fff;
cursor: pointer;
display: flex;
align-items: center;
}
.el-dropdown-menu__item {
text-align: center;
}
</style>

View File

@@ -0,0 +1,132 @@
<template>
<div class="sidebar">
<el-menu
class="sidebar-el-menu"
:default-active="onRoutes"
:collapse="sidebar.collapse"
background-color="#324157"
text-color="#bfcbd9"
active-text-color="#20a0ff"
unique-opened
router
>
<template v-for="item in items">
<template v-if="item.subs">
<el-sub-menu :index="item.index" :key="item.index">
<template #title>
<i :class="'iconfont '+item.icon"></i>
<span>{{ item.title }}</span>
</template>
<template v-for="subItem in item.subs">
<el-sub-menu
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-sub-menu>
<el-menu-item v-else :index="subItem.index">
{{ subItem.title }}
</el-menu-item>
</template>
</el-sub-menu>
</template>
<template v-else>
<el-menu-item :index="item.index" :key="item.index">
<i :class="'iconfont icon-'+item.icon"></i>
<template #title>{{ item.title }}</template>
</el-menu-item>
</template>
</template>
</el-menu>
</div>
</template>
<script setup>
import {computed} from 'vue';
import {useSidebarStore} from '@/store/sidebar';
import {useRoute} from 'vue-router';
const items = [
{
icon: 'home',
index: '/admin/welcome',
title: '系统首页',
},
{
icon: 'config',
index: '/admin/system',
title: '系统设置',
},
{
icon: 'menu',
index: '1',
title: '常用模板页面',
subs: [
{
icon: 'menu',
index: '/admin/demo/form',
title: '表单页面',
},
{
index: '/admin/demo/table',
title: '常用表格',
},
{
index: '/admin/demo/import',
title: '导入Excel',
},
{
index: '/admin/demo/editor',
title: '富文本编辑器',
},
],
},
];
const route = useRoute();
const onRoutes = computed(() => {
return route.path;
});
const sidebar = useSidebarStore();
</script>
<style scoped lang="stylus">
.sidebar {
display: block;
position: absolute;
left: 0;
top: 70px;
bottom: 0;
overflow-y: scroll;
ul {
height: 100%;
.el-menu-item {
.iconfont {
font-size 16px;
margin-right 5px;
}
}
.el-menu-item.is-active {
background-color #242f42
}
}
.sidebar-el-menu:not(.el-menu--collapse) {
width: 250px;
}
}
.sidebar::-webkit-scrollbar {
width: 0;
}
</style>

View File

@@ -0,0 +1,171 @@
<template>
<div class="tags" v-if="tags.show">
<ul>
<li
class="tags-li"
v-for="(item, index) in tags.list"
:class="{ active: isActive(item.path) }"
:key="index"
>
<router-link :to="item.path" class="tags-li-title">{{ item.title }}</router-link>
<el-icon @click="closeTags(index)">
<Close/>
</el-icon>
</li>
</ul>
<div class="tags-close-box">
<el-dropdown @command="handleTags">
<el-button size="small" type="primary">
标签选项
<el-icon class="el-icon--right">
<arrow-down/>
</el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu size="small">
<el-dropdown-item command="other">关闭其他</el-dropdown-item>
<el-dropdown-item command="all">关闭所有</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</template>
<script setup>
import {useTagsStore} from '@/store/tags';
import {onBeforeRouteUpdate, useRoute, useRouter} from 'vue-router';
import {ArrowDown, Close} from "@element-plus/icons-vue";
const route = useRoute();
const router = useRouter();
const isActive = (path) => {
return path === route.fullPath;
};
const tags = useTagsStore();
// 关闭单个标签
const closeTags = (index) => {
const delItem = tags.list[index];
tags.delTagsItem(index);
const item = tags.list[index] ? tags.list[index] : tags.list[index - 1];
if (item) {
delItem.path === route.fullPath && router.push(item.path);
} else {
router.push('/');
}
};
// 设置标签
const setTags = (route) => {
const isExist = tags.list.some(item => {
return item.path === route.fullPath;
});
if (!isExist) {
if (tags.list.length >= 8) tags.delTagsItem(0);
tags.setTagsItem({
name: route.name,
title: route.meta.title,
path: route.fullPath
});
}
};
setTags(route);
onBeforeRouteUpdate(to => {
setTags(to);
});
// 关闭全部标签
const closeAll = () => {
tags.clearTags();
router.push('/');
};
// 关闭其他标签
const closeOther = () => {
const curItem = tags.list.filter(item => {
return item.path === route.fullPath;
});
tags.closeTagsOther(curItem);
};
const handleTags = (command) => {
command === 'other' ? closeOther() : closeAll();
};
// 关闭当前页面的标签页
// tags.closeCurrentTag({
// $router: router,
// $route: route
// });
</script>
<style>
.tags {
position: relative;
height: 30px;
overflow: hidden;
background: #fff;
padding-right: 120px;
box-shadow: 0 5px 10px #ddd;
}
.tags ul {
box-sizing: border-box;
width: 100%;
height: 100%;
}
.tags-li {
display: flex;
align-items: center;
float: left;
margin: 3px 5px 2px 3px;
border-radius: 3px;
font-size: 12px;
overflow: hidden;
cursor: pointer;
height: 23px;
border: 1px solid #e9eaec;
background: #fff;
padding: 0 5px 0 12px;
color: #666;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
transition: all 0.3s ease-in;
}
.tags-li:not(.active):hover {
background: #f8f8f8;
}
.tags-li.active {
color: #fff;
}
.tags-li-title {
float: left;
max-width: 80px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin-right: 5px;
color: #666;
}
.tags-li.active .tags-li-title {
color: #fff;
}
.tags-close-box {
position: absolute;
right: 0;
top: 0;
box-sizing: border-box;
padding-top: 1px;
text-align: center;
width: 110px;
height: 30px;
background: #fff;
box-shadow: -3px 0 15px 3px rgba(0, 0, 0, 0.1);
z-index: 10;
}
</style>