Files
tk-mini-program/uni_modules/yinrh-menu-popup
pengxiaolong 8580cd18fa 优化
2025-07-25 16:39:52 +08:00
..
2025-07-25 16:39:52 +08:00
2025-07-25 16:39:52 +08:00
2025-07-25 16:39:52 +08:00
2025-07-25 16:39:52 +08:00

yinrh-menu-popup

仿IOS长按的悬浮菜单

使用方法

template中直接使用

<yinrh-menu-popup v-model="value" :pop-data="menu" dynamic :x="x" :y="y" direction="row" theme="dark"
			:placement="place" @tapPopup="tapPopup" />

template中,需要出现菜单的 view 上添加 id 和 click 事件

<text id="popup-menu" @longTap="longTap">长按出现悬浮菜单</text>

script中,添加 longTap 和 tapPopup 方法

longTap() {
	let dom = uni.createSelectorQuery().in(this);
	// popup-menu 为上面添加的 id 值
	dom.select('#popup-menu').boundingClientRect();
	dom.exec(data => {
		// 配置 place、value、x、y 的值
		let isTop = data[0].top >= 60,
			place = isTop ? 'bottom' : 'top';
		this.place = place + '-center';
		this.value = !this.value;
		this.x = data[0]['width'] / 2;
		this.y = data[0][isTop ? 'top' : 'bottom'];
	});
}
tapPopup(e) {
	console.log(e);
}

参数说明

  • maskBg遮罩背景颜色默认 rgba(0,0,0,0),不透明
  • value显示或隐藏菜单true-显示false-隐藏,默认 true
  • x长按组件的中心值单位px
  • y长按组件的 top 或 bootom 值单位px
  • theme悬浮菜单的样式支持 light 和 dark默认 light
  • gap
  • triangle悬浮菜单的箭头true-显示false-隐藏,默认 true
  • dynamic悬浮菜单的显示方式true-动态false-静态,默认 true
  • popData悬浮菜单的列表
  • direction悬浮菜单排列方向支持 column 和 row默认 column
  • placement悬浮菜单的箭头相对于菜单的位置 top-start、top-end、bottom-start、bottom-end、top-center、bottom-center默认 top-start