ForCAX/entry/src/main/ets/pages/CustomStyle/StyleButton.ets
2026-03-04 16:40:27 +08:00

48 lines
1.2 KiB
Plaintext

import { BtnEvent } from "../LayoutData/TitleInterface";
//单一功能按钮
@ComponentV2
export struct EventButton {
@Param strIcon:string='';
@Param strName:string='';
build() {
Column({ space: 2 }) {
// 请将$r('app.media.loading')替换为实际资源文件
Image($r('app.media.' + this.strIcon))
.width(45)
.height(35)
.objectFit(ImageFit.Contain)
Text(this.strName)
.fontSize(10)
.width(45)
.height(10)
.textAlign(TextAlign.Center)
}
.height('50')
.width('50')
.padding('1')
}
}
//菜单目录按钮
//功能目录菜单,主要用于针对单一按钮多个功能形式
@ComponentV2
export struct EventBtnMenu {
@Param btnMenus: Array<BtnEvent>=[];
@Builder
EventMenu(_btnMenus:Array<BtnEvent>){
Menu() {
ForEach(_btnMenus, (item: BtnEvent, index: number) => {
MenuItem({ startIcon: $r('app.media.'+item.eIcon), content: item.eName })
.width('150')
.margin({ top: 0, left: 0, bottom: 0, right: 0
})
})
}
}
build() {
EventButton({strIcon:this.btnMenus[0].eIcon,strName:this.btnMenus[0].eName}).bindMenu(this.EventMenu(this.btnMenus))
}
}