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