mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	feat: 在左侧菜单右中侧再加一个折叠展开菜单的功能
This commit is contained in:
		
							parent
							
								
									791224b381
								
							
						
					
					
						commit
						2ebb584ec8
					
				@ -7,7 +7,7 @@ import boxen, { type Options as BoxenOptions } from "boxen";
 | 
				
			|||||||
dayjs.extend(duration);
 | 
					dayjs.extend(duration);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const welcomeMessage = gradientString("cyan", "magenta").multiline(
 | 
					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 = {
 | 
					const boxenOptions: BoxenOptions = {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										70
									
								
								src/layout/components/sidebar/centerCollapse.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								src/layout/components/sidebar/centerCollapse.vue
									
									
									
									
									
										Normal file
									
								
							@ -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>
 | 
				
			||||||
@ -41,7 +41,7 @@ const toggleClick = () => {
 | 
				
			|||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <div class="collapse-container">
 | 
					  <div class="left-collapse">
 | 
				
			||||||
    <IconifyIconOffline
 | 
					    <IconifyIconOffline
 | 
				
			||||||
      v-tippy="{
 | 
					      v-tippy="{
 | 
				
			||||||
        content: props.isActive ? '点击折叠' : '点击展开',
 | 
					        content: props.isActive ? '点击折叠' : '点击展开',
 | 
				
			||||||
@ -58,7 +58,7 @@ const toggleClick = () => {
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<style lang="scss" scoped>
 | 
					<style lang="scss" scoped>
 | 
				
			||||||
.collapse-container {
 | 
					.left-collapse {
 | 
				
			||||||
  position: absolute;
 | 
					  position: absolute;
 | 
				
			||||||
  bottom: 0;
 | 
					  bottom: 0;
 | 
				
			||||||
  width: 100%;
 | 
					  width: 100%;
 | 
				
			||||||
 | 
				
			|||||||
@ -3,8 +3,9 @@ import Logo from "./logo.vue";
 | 
				
			|||||||
import { useRoute } from "vue-router";
 | 
					import { useRoute } from "vue-router";
 | 
				
			||||||
import { emitter } from "@/utils/mitt";
 | 
					import { emitter } from "@/utils/mitt";
 | 
				
			||||||
import SidebarItem from "./sidebarItem.vue";
 | 
					import SidebarItem from "./sidebarItem.vue";
 | 
				
			||||||
import leftCollapse from "./leftCollapse.vue";
 | 
					import LeftCollapse from "./leftCollapse.vue";
 | 
				
			||||||
import { useNav } from "@/layout/hooks/useNav";
 | 
					import { useNav } from "@/layout/hooks/useNav";
 | 
				
			||||||
 | 
					import CenterCollapse from "./centerCollapse.vue";
 | 
				
			||||||
import { responsiveStorageNameSpace } from "@/config";
 | 
					import { responsiveStorageNameSpace } from "@/config";
 | 
				
			||||||
import { storageLocal, isAllEmpty } from "@pureadmin/utils";
 | 
					import { storageLocal, isAllEmpty } from "@pureadmin/utils";
 | 
				
			||||||
import { findRouteByPath, getParentPaths } from "@/router/utils";
 | 
					import { findRouteByPath, getParentPaths } from "@/router/utils";
 | 
				
			||||||
@ -12,6 +13,7 @@ import { usePermissionStoreHook } from "@/store/modules/permission";
 | 
				
			|||||||
import { ref, computed, watch, onMounted, onBeforeUnmount } from "vue";
 | 
					import { ref, computed, watch, onMounted, onBeforeUnmount } from "vue";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const route = useRoute();
 | 
					const route = useRoute();
 | 
				
			||||||
 | 
					const isShow = ref(false);
 | 
				
			||||||
const showLogo = ref(
 | 
					const showLogo = ref(
 | 
				
			||||||
  storageLocal().getItem<StorageConfigs>(
 | 
					  storageLocal().getItem<StorageConfigs>(
 | 
				
			||||||
    `${responsiveStorageNameSpace()}configure`
 | 
					    `${responsiveStorageNameSpace()}configure`
 | 
				
			||||||
@ -88,6 +90,8 @@ onBeforeUnmount(() => {
 | 
				
			|||||||
  <div
 | 
					  <div
 | 
				
			||||||
    v-loading="loading"
 | 
					    v-loading="loading"
 | 
				
			||||||
    :class="['sidebar-container', showLogo ? 'has-logo' : 'no-logo']"
 | 
					    :class="['sidebar-container', showLogo ? 'has-logo' : 'no-logo']"
 | 
				
			||||||
 | 
					    @mouseenter.prevent="isShow = true"
 | 
				
			||||||
 | 
					    @mouseleave.prevent="isShow = false"
 | 
				
			||||||
  >
 | 
					  >
 | 
				
			||||||
    <Logo v-if="showLogo" :collapse="isCollapse" />
 | 
					    <Logo v-if="showLogo" :collapse="isCollapse" />
 | 
				
			||||||
    <el-scrollbar
 | 
					    <el-scrollbar
 | 
				
			||||||
@ -114,7 +118,12 @@ onBeforeUnmount(() => {
 | 
				
			|||||||
        />
 | 
					        />
 | 
				
			||||||
      </el-menu>
 | 
					      </el-menu>
 | 
				
			||||||
    </el-scrollbar>
 | 
					    </el-scrollbar>
 | 
				
			||||||
    <leftCollapse
 | 
					    <CenterCollapse
 | 
				
			||||||
 | 
					      v-if="device !== 'mobile' && (isShow || isCollapse)"
 | 
				
			||||||
 | 
					      :is-active="pureApp.sidebar.opened"
 | 
				
			||||||
 | 
					      @toggleClick="toggleSideBar"
 | 
				
			||||||
 | 
					    />
 | 
				
			||||||
 | 
					    <LeftCollapse
 | 
				
			||||||
      v-if="device !== 'mobile'"
 | 
					      v-if="device !== 'mobile'"
 | 
				
			||||||
      :is-active="pureApp.sidebar.opened"
 | 
					      :is-active="pureApp.sidebar.opened"
 | 
				
			||||||
      @toggleClick="toggleSideBar"
 | 
					      @toggleClick="toggleSideBar"
 | 
				
			||||||
 | 
				
			|||||||
@ -92,7 +92,7 @@
 | 
				
			|||||||
    z-index: 1001;
 | 
					    z-index: 1001;
 | 
				
			||||||
    width: $sideBarWidth !important;
 | 
					    width: $sideBarWidth !important;
 | 
				
			||||||
    height: 100%;
 | 
					    height: 100%;
 | 
				
			||||||
    overflow: hidden;
 | 
					    overflow: visible;
 | 
				
			||||||
    font-size: 0;
 | 
					    font-size: 0;
 | 
				
			||||||
    background: $menuBg;
 | 
					    background: $menuBg;
 | 
				
			||||||
    border-right: 1px solid var(--pure-border-color);
 | 
					    border-right: 1px solid var(--pure-border-color);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user