优化部分代码
This commit is contained in:
parent
a4a6528a36
commit
5ef8998322
@ -4,8 +4,6 @@ import { TitleButton } from "../LayoutInterface/Interface/ButtonInterface";
|
||||
import { TitleModel } from "../LayoutInterface/Interface/ModelInterface";
|
||||
import { TitleTabData } from '../LayoutInterface/Layout/TitleTabData';
|
||||
import { mwInfo } from '../AppStorageV2Class';
|
||||
import {BaseMenu } from './Menu';
|
||||
import { BaseMenuData } from '../LayoutInterface/Interface/MenuInterface';
|
||||
|
||||
//按钮统一尺寸,该按钮为正方形,所以以主窗口宽为基准,长=高->正方形
|
||||
let ebWidth=mwInfo.mainWindowWidth*0.02;
|
||||
@ -90,20 +88,34 @@ export struct EventBtn {
|
||||
//功能目录菜单,主要用于针对单一按钮多个功能形式
|
||||
@ComponentV2
|
||||
export struct MenuBtn {
|
||||
@Param menuBtn: Array<TitleButton> | undefined = undefined;
|
||||
@Param menus: Array<TitleButton> | undefined = undefined;
|
||||
@Local curtIndex:number=0;
|
||||
@Local argsMenu:BaseMenuData= {
|
||||
aMenus: this.menuBtn as Array<TitleButton|Array<TitleButton>>,
|
||||
aIndex: this.curtIndex
|
||||
};
|
||||
|
||||
@Builder
|
||||
BaseMenu (){
|
||||
Menu() {
|
||||
ForEach(this.menus, (item: TitleButton, index: number) => {
|
||||
//如果是功能组则
|
||||
if(!Array.isArray(item)){
|
||||
MenuItem({ startIcon: $r('app.media.'+item.eIcon), content: item.eName })
|
||||
.onClick(()=> {
|
||||
this.curtIndex=index;
|
||||
ExecuteCommand(item as TitleButton);
|
||||
})
|
||||
.size({height: ebWidth})
|
||||
}
|
||||
})
|
||||
}.fontSize(20)
|
||||
}
|
||||
|
||||
build() {
|
||||
Column({ space: 0 }) {
|
||||
if (this.menuBtn != undefined) {
|
||||
if (this.menus != undefined) {
|
||||
Button()
|
||||
.bindMenu(BaseMenu(this.argsMenu))
|
||||
.bindMenu(this.BaseMenu)
|
||||
.width(ebWidth)
|
||||
.height(ebHeigth)
|
||||
.backgroundImage($r('app.media.' + this.menuBtn[this.curtIndex].eIcon))
|
||||
.backgroundImage($r('app.media.' + this.menus[this.curtIndex].eIcon))
|
||||
.backgroundImagePosition({ x: '5%', y: '5%' })
|
||||
.backgroundColor(Color.Transparent)
|
||||
.backgroundImageSize({
|
||||
@ -112,14 +124,14 @@ export struct MenuBtn {
|
||||
})
|
||||
Button()
|
||||
.type(ButtonType.Normal)
|
||||
.bindMenu(BaseMenu(this.argsMenu))
|
||||
.bindMenu(this.BaseMenu)
|
||||
.width(ebWidth)
|
||||
.height(edHeigth)
|
||||
.backgroundImage($r('app.media.base_chevron_down'))
|
||||
.backgroundImagePosition({ x: '35%', y: '0%' })
|
||||
.backgroundColor(Color.Transparent)
|
||||
|
||||
Text(this.menuBtn[this.curtIndex].eName)
|
||||
Text((this.menus[this.curtIndex].eName))
|
||||
.fontSize(16)
|
||||
.width('auto')
|
||||
.height(edHeigth)
|
||||
@ -130,31 +142,102 @@ export struct MenuBtn {
|
||||
}
|
||||
}
|
||||
|
||||
export enum MenuType{
|
||||
TEXT,
|
||||
ICON,
|
||||
INDEXICON
|
||||
};
|
||||
|
||||
//Title Sub功能目录菜单
|
||||
@ComponentV2
|
||||
export struct SubColumnMenu {
|
||||
@Param menus: Array<TitleButton>| undefined = undefined;
|
||||
@Param icon:string='';
|
||||
@Param menus: Array<TitleButton|Array<TitleButton>> = [];
|
||||
@Local curtIndex:number=0;
|
||||
@Local argsMenu:BaseMenuData= {
|
||||
aMenus: this.menus as Array<TitleButton|Array<TitleButton>>,
|
||||
aIndex: this.curtIndex
|
||||
};
|
||||
@Param inputIcon:string|undefined=undefined;
|
||||
@Param menuType:MenuType=MenuType.TEXT;
|
||||
@Param name:string|undefined=undefined;
|
||||
@Builder
|
||||
SubMenu (subMenu:Array<TitleButton>) {
|
||||
Menu() {
|
||||
ForEach(subMenu, (subItem: TitleButton, index: number) => {
|
||||
MenuItem({
|
||||
startIcon: $r('app.media.' + subItem.eIcon),
|
||||
content: subItem.eName,
|
||||
})
|
||||
.onClick(() => {
|
||||
ExecuteCommand(subItem as TitleButton);
|
||||
})
|
||||
.size({ height: ebWidth })
|
||||
})
|
||||
}.fontSize(20)
|
||||
}
|
||||
@Builder
|
||||
BaseMenu (){
|
||||
Menu() {
|
||||
ForEach(this.menus, (item: TitleButton|Array<TitleButton>, index: number) => {
|
||||
//如果是功能组则
|
||||
if(!Array.isArray(item)){
|
||||
MenuItem({ startIcon: $r('app.media.'+item.eIcon), content: item.eName })
|
||||
.onClick(()=> {
|
||||
this.curtIndex=index;
|
||||
})
|
||||
.size({height: ebWidth})
|
||||
}else{
|
||||
MenuItem({
|
||||
startIcon: $r('app.media.' + item[0].eIcon),
|
||||
content: item[0].eName,
|
||||
builder: this.SubMenu(item)
|
||||
})
|
||||
}
|
||||
})
|
||||
}.fontSize(20)
|
||||
}
|
||||
|
||||
build(){
|
||||
Row(){
|
||||
if(this.menuType==MenuType.INDEXICON){
|
||||
Button()
|
||||
.padding(1)
|
||||
.width(mwInfo.mainWindowWidth*0.013)
|
||||
.height(mwInfo.mainWindowWidth*0.013)
|
||||
.backgroundColor(Color.Transparent)
|
||||
.backgroundImage($r('app.media.'+this.icon))
|
||||
.backgroundImage($r('app.media.'+(this.menus[this.curtIndex]as TitleButton).eIcon))
|
||||
.backgroundImagePosition({ x: '5%', y: '5%' })
|
||||
.backgroundImageSize({
|
||||
width: '90%', // 图片宽度占满按钮
|
||||
height: '90%' // 图片高度占满按钮
|
||||
})
|
||||
.bindMenu(BaseMenu(this.argsMenu))
|
||||
.bindMenu(this.BaseMenu)
|
||||
.type(ButtonType.Normal)
|
||||
}else if(this.menuType==MenuType.ICON){
|
||||
Button()
|
||||
.padding(1)
|
||||
.width(mwInfo.mainWindowWidth*0.013)
|
||||
.height(mwInfo.mainWindowWidth*0.013)
|
||||
.backgroundColor(Color.Transparent)
|
||||
.backgroundImage($r('app.media.'+this.inputIcon))
|
||||
.backgroundImagePosition({ x: '5%', y: '5%' })
|
||||
.backgroundImageSize({
|
||||
width: '90%', // 图片宽度占满按钮
|
||||
height: '90%' // 图片高度占满按钮
|
||||
})
|
||||
.bindMenu(this.BaseMenu)
|
||||
.type(ButtonType.Normal)
|
||||
}else if(this.menuType==MenuType.TEXT){
|
||||
Button(this.name)
|
||||
.padding(1)
|
||||
.width(mwInfo.mainWindowWidth*0.013)
|
||||
.height(mwInfo.mainWindowWidth*0.013)
|
||||
.backgroundColor(Color.Transparent)
|
||||
.backgroundImagePosition({ x: '5%', y: '5%' })
|
||||
.backgroundImageSize({
|
||||
width: '90%', // 图片宽度占满按钮
|
||||
height: '90%' // 图片高度占满按钮
|
||||
})
|
||||
.bindMenu(this.BaseMenu)
|
||||
.type(ButtonType.Normal)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,8 +9,6 @@ import { BaseMenuData } from "../LayoutInterface/Interface/MenuInterface";
|
||||
let ebWidth=mwInfo.mainWindowWidth*0.02;
|
||||
let ebHeigth=mwInfo.mainWindowWidth*0.02;
|
||||
|
||||
|
||||
//不带Index的Menu
|
||||
@Builder
|
||||
export function BaseMenu(indexMenu:BaseMenuData) {
|
||||
Menu() {
|
||||
@ -25,7 +23,6 @@ export function BaseMenu(indexMenu:BaseMenuData) {
|
||||
}else{
|
||||
MenuItem({ startIcon: $r('app.media.'+item.eIcon), content: item.eName })
|
||||
.onClick(()=> {
|
||||
indexMenu.aIndex = index;
|
||||
ExecuteCommand(item as TitleButton);
|
||||
})
|
||||
.size({height: ebWidth})
|
||||
|
||||
@ -7,12 +7,11 @@ import {DisplayMode} from "../LayoutInterface/Layout/DisplayMode"
|
||||
import { LayoutSwitch } from "../LayoutInterface/Layout/LayoutSwitch";
|
||||
import { FileMenuData } from "../LayoutInterface/Layout/FileMenuData";
|
||||
import { mwInfo } from "../AppStorageV2Class";
|
||||
import { SubColumnMenu } from "../CustomStyle/Button";
|
||||
import { SubColumnMenu ,MenuType} from "../CustomStyle/Button";
|
||||
|
||||
|
||||
@ComponentV2
|
||||
export struct TitleColumnSub {
|
||||
|
||||
@Local layerArray: Array<TitleButton> = [];
|
||||
@Local dX:number=0;
|
||||
@Local dY:number=0;
|
||||
@ -34,7 +33,10 @@ export struct TitleColumnSub {
|
||||
|
||||
build(){
|
||||
Row({space:5}){
|
||||
SubColumnMenu({menus:FileMenuData.aMenus as Array<TitleButton>,icon:'base_shortcut_menu'})
|
||||
SubColumnMenu({
|
||||
menus:FileMenuData.aMenus as Array<TitleButton>,
|
||||
inputIcon:'base_shortcut_menu',
|
||||
menuType:MenuType.ICON})
|
||||
.margin({ top:0, left: 5, bottom: 0, right: 0 })
|
||||
Text('菜单')
|
||||
.fontSize(20)
|
||||
@ -48,7 +50,7 @@ export struct TitleColumnSub {
|
||||
Text('图层:')
|
||||
.fontSize(20)
|
||||
TextInputComboBox({menu:this.layerArray}).width('10%')
|
||||
SubColumnMenu({menus:LayoutSwitch,icon:LayoutSwitch[0].eIcon})
|
||||
SubColumnMenu({menus:LayoutSwitch,menuType:MenuType.INDEXICON})
|
||||
//视角弹窗
|
||||
Button().onClick((event) => {
|
||||
this.dX=event.windowX
|
||||
@ -65,7 +67,7 @@ export struct TitleColumnSub {
|
||||
width: '100%', // 图片宽度占满按钮
|
||||
height: '100%' // 图片高度占满按钮
|
||||
})
|
||||
SubColumnMenu({menus:DisplayMode,icon:DisplayMode[0].eIcon})
|
||||
SubColumnMenu({menus:DisplayMode,menuType:MenuType.INDEXICON})
|
||||
}.margin({ top: 1, left: 1, bottom: 1, right: 1 })
|
||||
}
|
||||
}
|
||||
@ -3,8 +3,8 @@ import {TitleTabData, TitleModel} from '../LayoutInterface/Layout/TitleTabData'
|
||||
import { FileMenuData } from "../LayoutInterface/Layout/FileMenuData";
|
||||
import {TitleTabContent} from './TitleTabContent'
|
||||
import { mwInfo } from '../AppStorageV2Class';
|
||||
import { BaseMenu} from '../CustomStyle/Menu';
|
||||
import { TitleButton } from '../LayoutInterface/Interface/ButtonInterface';
|
||||
import { BaseMenu } from '../CustomStyle/Menu';
|
||||
|
||||
@Entry
|
||||
@ComponentV2
|
||||
|
||||
@ -30,13 +30,13 @@ export struct TitleTabContent {
|
||||
ForEach(group_item.grpBtn, (btn_item: TitleButton|Array<TitleButton>, index: number) =>{
|
||||
if(this.curtLayout?.cmName=='应用模块'){
|
||||
if(Array.isArray(btn_item)){
|
||||
MenuBtn({menuBtn:btn_item})
|
||||
MenuBtn({menus:btn_item})
|
||||
}else{
|
||||
EventBtn({eventBtn:btn_item,eventBtnType:true})
|
||||
}
|
||||
}else{
|
||||
if(Array.isArray(btn_item)){
|
||||
MenuBtn({menuBtn:btn_item})
|
||||
MenuBtn({menus:btn_item})
|
||||
}else{
|
||||
EventBtn({eventBtn:btn_item})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user