Skip to content

Commit

Permalink
feat: 在左侧菜单右中侧再加一个折叠展开菜单的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Mar 22, 2024
1 parent 791224b commit 2ebb584
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import boxen, { type Options as BoxenOptions } from "boxen";
dayjs.extend(duration);

const welcomeMessage = gradientString("cyan", "magenta").multiline(
`Hello! 欢迎使用 pure-admin 开源项目\n我们为您精心准备了下面两个贴心的保姆级文档\nhttps://yiming_chang.gitee.io/pure-admin-doc\nhttps://pure-admin-utils.netlify.app`
`您好! 欢迎使用 pure-admin 开源项目\n我们为您精心准备了下面两个贴心的保姆级文档\nhttps://yiming_chang.gitee.io/pure-admin-doc\nhttps://pure-admin-utils.netlify.app`
);

const boxenOptions: BoxenOptions = {
Expand Down
70 changes: 70 additions & 0 deletions src/layout/components/sidebar/centerCollapse.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<script setup lang="ts">
import { computed } from "vue";
import { useGlobal } from "@pureadmin/utils";
import { useNav } from "@/layout/hooks/useNav";
import ArrowLeft from "@iconify-icons/ri/arrow-left-double-fill";
interface Props {
isActive: boolean;
}
const props = withDefaults(defineProps<Props>(), {
isActive: false
});
const { tooltipEffect } = useNav();
const iconClass = computed(() => {
return ["w-[16px]", "h-[16px]"];
});
const { $storage } = useGlobal<GlobalPropertiesApi>();
const themeColor = computed(() => $storage.layout?.themeColor);
const emit = defineEmits<{
(e: "toggleClick"): void;
}>();
const toggleClick = () => {
emit("toggleClick");
};
</script>

<template>
<div
v-tippy="{
content: props.isActive ? '点击折叠' : '点击展开',
theme: tooltipEffect,
hideOnClick: 'toggle',
placement: 'right'
}"
class="center-collapse"
@click="toggleClick"
>
<IconifyIconOffline
:icon="ArrowLeft"
:class="[iconClass, themeColor === 'light' ? '' : 'text-primary']"
:style="{ transform: props.isActive ? 'none' : 'rotateY(180deg)' }"
/>
</div>
</template>

<style lang="scss" scoped>
.center-collapse {
position: absolute;
top: 50%;
right: 2px;
z-index: 1002;
display: flex;
align-items: center;
justify-content: center;
width: 24px;
height: 34px;
cursor: pointer;
background: var(--el-bg-color);
border: 1px solid var(--pure-border-color);
border-radius: 4px;
transform: translate(12px, -50%);
}
</style>
4 changes: 2 additions & 2 deletions src/layout/components/sidebar/leftCollapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const toggleClick = () => {
</script>

<template>
<div class="collapse-container">
<div class="left-collapse">
<IconifyIconOffline
v-tippy="{
content: props.isActive ? '点击折叠' : '点击展开',
Expand All @@ -58,7 +58,7 @@ const toggleClick = () => {
</template>

<style lang="scss" scoped>
.collapse-container {
.left-collapse {
position: absolute;
bottom: 0;
width: 100%;
Expand Down
13 changes: 11 additions & 2 deletions src/layout/components/sidebar/vertical.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import Logo from "./logo.vue";
import { useRoute } from "vue-router";
import { emitter } from "@/utils/mitt";
import SidebarItem from "./sidebarItem.vue";
import leftCollapse from "./leftCollapse.vue";
import LeftCollapse from "./leftCollapse.vue";
import { useNav } from "@/layout/hooks/useNav";
import CenterCollapse from "./centerCollapse.vue";
import { responsiveStorageNameSpace } from "@/config";
import { storageLocal, isAllEmpty } from "@pureadmin/utils";
import { findRouteByPath, getParentPaths } from "@/router/utils";
import { usePermissionStoreHook } from "@/store/modules/permission";
import { ref, computed, watch, onMounted, onBeforeUnmount } from "vue";
const route = useRoute();
const isShow = ref(false);
const showLogo = ref(
storageLocal().getItem<StorageConfigs>(
`${responsiveStorageNameSpace()}configure`
Expand Down Expand Up @@ -88,6 +90,8 @@ onBeforeUnmount(() => {
<div
v-loading="loading"
:class="['sidebar-container', showLogo ? 'has-logo' : 'no-logo']"
@mouseenter.prevent="isShow = true"
@mouseleave.prevent="isShow = false"
>
<Logo v-if="showLogo" :collapse="isCollapse" />
<el-scrollbar
Expand All @@ -114,7 +118,12 @@ onBeforeUnmount(() => {
/>
</el-menu>
</el-scrollbar>
<leftCollapse
<CenterCollapse
v-if="device !== 'mobile' && (isShow || isCollapse)"
:is-active="pureApp.sidebar.opened"
@toggleClick="toggleSideBar"
/>
<LeftCollapse
v-if="device !== 'mobile'"
:is-active="pureApp.sidebar.opened"
@toggleClick="toggleSideBar"
Expand Down
2 changes: 1 addition & 1 deletion src/style/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
z-index: 1001;
width: $sideBarWidth !important;
height: 100%;
overflow: hidden;
overflow: visible;
font-size: 0;
background: $menuBg;
border-right: 1px solid var(--pure-border-color);
Expand Down

0 comments on commit 2ebb584

Please sign in to comment.