🎯 目标
封装一个灵活的抽屉组件 CommonDrawer
,适用于:
-
侧边栏设置面板(如通知管理、筛选器)
-
底部弹出菜单(如分享/选择操作)
-
多层嵌套抽屉(如“城市 → 区县 → 门店”级联)
-
支持遮罩关闭、滑动动画、内容自定义插槽
-
可配置打开方向(left / right / bottom)
🧱 样式示意
← 从左侧滑入内容 ↑ 底部弹出内容
╭───────────────╮ ╭───────────────╮
│ 设置内容区域 │ │ 分享方式区域 │
╰───────────────╯ ╰───────────────╯
🧰 组件实现:CommonDrawer.ets
@Component
export struct CommonDrawer {
@Prop visible: boolean = false
@Prop position: 'left' | 'right' | 'bottom' = 'right'
@Prop width: string = '70%' // left/right 模式宽度
@Prop height: string = '60%' // bottom 模式高度
@Prop maskClosable: boolean = true
@Prop onClose: () => void = () => {}
build() {
if (!this.visible) return
Stack()
.width('100%')
.height('100%') {
// 遮罩层
Blank()
.b