uniapp 自定义菜单页面 顶部侧边菜单效果

uniapp 自定义菜单栏展示

最近需要实现一个多维数组展示的菜单效果,找来找去没有找到合适的插件,只能手写一个了,效果如下:

## 新的改变

代码如下,做个参考把,里面的数据也是我mock的假数据,可以参考下思路哈

<template>
	<view class="chioce">
		<!-- 顶部 -->
		<scroll-view class="top" scroll-x="true">
			<view class="top-list"
				 style="display: flex;width:2000rpx;height:76rpx; align-items:center;padding: 0 20rpx;padding-top:20rpx;"
			>
				<view 
				@click="topClickHandle(index, item.id)"
				:class="active === index ? 'active' : ''"
				class="item"
				v-for="(item, index) in list" 
				:key="item.id">
					{{ item.buildName }}
				</view>
			</view>
		</scroll-view>
		<view class="pics">
			<!-- 左侧 -->
			<scroll-view class="left" scroll-y>
				<view 
				@click="leftClickHandle(index, item.districtId)"
				:class="leftActive === index ? 'active' : ''"
				v-for="(item, index) in leftMenuList" 
				:key="item.floorId">
				  {{ item.floorName }}
				</view>
				<view style="height: 104px"></view>
				  
				<view class="fixed-icon" @click="showPop">
					<image class="icon" src="../../../static/icon/white-sort.png" />
				</view>
				  
			</scroll-view>
			<!-- 右侧 -->
			<scroll-view  v-if="refurbish" class="right" scroll-y 
	        :scroll-top="scrollTop" 
			scroll-with-animation>
				<view class="item" v-for="(item, index) in rightContent" :key="index">
					<view class="title">{{ item.districtName }}
						<image class="icon" src="../../../static/icon/sort.png" />
					</view>
					<!--  -->
					<view class="room-list" >
						<view 
						class="room-item" 
						@click="rightClickHandle(index,ind)"
						:class="rightActiveLabel === obj.roomName ? 'right-active' : ''"
						v-for="(obj, ind) in item.roomList" 
						:key="ind">{{ obj.roomName }}</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 弹出侧边栏 -->
		<uni-drawer ref="showRight" mode="right" :width="320">
			<view class="list">
				<view class="item" v-for="(item,index) in drawerList" :key="index">{{item.buildName}}</view>
			</view>
		</uni-drawer>
		<!-- 操作弹框 -->
		<u-action-sheet :actions="popType" title="选择排序" @select="selectClick" :closeOnClickOverlay="false" @close="closePop" cancelText="取消" round="20" :show="popShow"></u-action-sheet>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				popShow: false,
				popType: [
					{
						name: '楼排序',
						type: 1,
					},
					{
						name: '楼层排序',
						type: 2
					}
				],
				// 顶部菜单
				list: [],
				//左侧菜单
				leftMenuList: [],
				//顶部选择的状态
				active: 0,
				activeLabel:'',
				// 左侧选择
				leftActive: 0,
				leftActiveLabel: '',
				// 右侧数据
				rightContent: [],
				// 右侧选中数据
				rightActive: 0,
				rightActiveLabel: '',
				districtNmame: '',
				//接口返回数据
				cates:[],
				scrollTop:0,
                refurbish:true, //刷新数据
				drawerList:[]
			}
		},
		onLoad () {	
			this.getPicsCate()
		},
		methods: {
            //获取数据
			getPicsCate () {
				this.$http.get('http://localhost:8080/treeList').then(res => {
					this.list = res.list//顶部的数组
					this.leftMenuList = this.list[0].floorList//左侧的数组
					this.rightContent = this.list[this.active].floorList[0].districtList//右侧的数组
				})
			},
            //顶部菜单点击事件
			topClickHandle (index) {
				this.active = index
				this.activeLabel = this.list[index].buildName
				this.leftMenuList = this.list[index].floorList
				this.rightContent = this.list[this.active].floorList[0].districtList
				this.leftActive = 0
				this.leftActiveLabel = this.leftMenuList[0].buildName
				this.scrollTop = 0
                this.refurbish = false
				setTimeout(()=>{
					this.refurbish = true
				},1)
			},
            //左侧菜单点击事件
			leftClickHandle(index, districtId) {
				this.leftActive = index
				this.leftActiveLabel = this.leftMenuList[index].districtName
				this.rightContent = this.list[this.active].floorList[index].districtList
				this.scrollTop = 0
			},
			// 右侧菜单
			rightClickHandle(index,ind) {
				this.rightActive = index
				this.rightActiveLabel = this.rightContent[index].roomList[ind].roomName
				this.districtNmame = this.rightContent[index].districtNmame
			},
			// 
			selectClick(obj){
				if(obj.type==1){
					this.drawerList = this.list
				}
				this.$refs.showRight.open()
				// console.log(index)
			},
			// 展示弹框
			showPop() {
				this.popShow = true
			},
			// 关闭弹框
			closePop() {
				this.popShow = false
				this.$refs.showRight.close()
			},
            //跳转对应的id
            handleDetalis(url){
                  uni.navigateTo({
					url
				})  
            },
		}
	}
</script>
 
<style lang="scss">
scroll-view ::-webkit-scrollbar {  
	display: none !important;  
	width: 0 !important;  
	height: 0 !important;  
	-webkit-appearance: none;  
	background: transparent;  
}
page{
	overflow-y: hidden;
	height: 100%;
}
.top{
	color: #fff;
	width: 100%;
	background-color: #3c9cff;
	// background-color: #fff;
	.item{
		flex: 1;
		text-align: center;
	    padding-bottom: 12px;
	}
	.active{
		font-weight: 600;
		border-bottom: 4px solid #fff;
		padding-bottom: 10px;
		border-radius: 4px;
	}
}

.chioce{
	height: 100%;
}
.pics{
	display: flex;
		height: 100%;
	.left{
		margin-top: 5px;
		background: #3c9cff;
		view:first-child{
			margin-top: 0rpx !important;
		}
		width: 200rpx;
		height: 100%;
		// position: relative;
		view{
			padding-top: 10rpx;
			height: 80rpx;
			line-height: 80rpx;
			color: #fff;
			text-align: center;
			font-size: 24rpx;
			border-bottom: 1px solid #fff;
		}
		.active{
			background:#F8F8F8;
			color: #000;
			font-weight: bold;
		}
		.fixed-icon{
			position: fixed;
			bottom: 0;
			left: 0;
			background: #3c9cff;
			/* width: 100%; */
			width: 100px;
			.icon{
				width: 20px;
				height: 20px;
			}
		}
	}
	.right{
		height: 100%;
		width: 520rpx;
		margin: 10rpx auto;
		.title{
			// width: 100%;
			background: #e0e0e0;
			padding: 10px;
			color: #666;
			margin-bottom: 8px;
			display: flex;
			justify-content: space-between;
			.icon{
				width: 20px;
				height: 20px;
			}
		}
		.room-list{
			display: flex;
		    flex-wrap: wrap;
		}
		.room-item{
			padding: 8px;
    		margin-bottom: 8px;
		}
		.right-active{
			background: #e0e0e0;
			color: #666;
		}
		.item{
			margin-bottom: 20rpx;
			width: 100%;
			> text {
				font-size: 20rpx;
				font-weight: bold;
			}
			.item-phone{
				margin-top: 20rpx;
				background-color: #F8F8F8;
				border-radius: 8rpx;
				padding: 10rpx;
				display: flex;
				align-items: center;
				view:first-child{
					image{
						width: 120rpx;
						height: 100rpx;
					}
				}
				.phone-r{
					margin-left: 15rpx;
					display: flex;
					flex-direction: column;
					align-items: flex-start;
					view{
						font-size: 20rpx;
					}
					view:last-child{
						margin-top: 10rpx;
					}
				}
			}
		}
		.item:last-child{
			padding-bottom: 30rpx;
		}
	}
}
</style>

由于只是demo,所以可能效果 不是特别好,仅仅是想给大家提供个思路哈,如果有更好的写法可以一起探讨~

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
uniapp是一种跨平台开发框架,可以用于开发应用程序。在uniapp中,左滑菜单是一种常见的交互设计,用于展示隐藏在页面侧边的额外功能或选项。 实现左滑菜单的方法有多种,下面简单介绍一种基本的实现方式。 首先,需要在页面中添加一个滑动组件,可以使用uniapp提供的swiper组件,通过设置方向为水平,实现左右滑动。然后在swiper组件内部添加一个容器,作为菜单的内容。菜单内容可以自定义,可以包含一些选项、按钮或其他交互元素。 接着,在页面的逻辑代码中,监听swiper组件的滑动事件。当用户向左滑动超过一定距离时,触发显示菜单的动画效果,使菜单内容从隐藏状态滑动到显示状态。当用户继续向左滑动一定距离,或者点击其他区域,菜单会再次滑动返回隐藏状态。 为了提升用户体验,可以在菜单显示时禁止页面其他区域的滑动。可以通过监听页面的滑动事件,在菜单显示时阻止页面的滑动事件响应。 最后,需要添加一些交互逻辑,比如当用户点击菜单选项时,执行相应的操作或页面跳转。可以通过监听菜单选项的点击事件,在事件回调函数中实现相应的逻辑处理。 以上是一种简单的实现uniapp左滑菜单的方式。根据具体的需求和设计,还可以进行更多的样式和交互的定制,以满足不同的应用场景和用户需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值