优化部分代码

This commit is contained in:
JackLee 2026-03-21 23:26:14 +08:00
parent 5ef8998322
commit dc2d4d0b26
5 changed files with 74 additions and 108 deletions

View File

@ -10,10 +10,11 @@ let ebWidth=mwInfo.mainWindowWidth*0.02;
let ebHeigth=mwInfo.mainWindowWidth*0.02;
//占位符的高度
let edHeigth=mwInfo.mainWindowWidth*0.005
//单一功能按钮
//图片->文本
//不能用于模块切换
@ComponentV2
export struct EventBtn {
//按钮动态布局类型,目前处于开发阶段两种状态.
@ -28,7 +29,6 @@ export struct EventBtn {
build() {
Column({ space: 2 }) {
//如果该类型是false表示为配普通事件按钮
if(!this.eventBtnType){
if (this.eventBtn != undefined) {
Button()
.width(ebWidth)
@ -41,33 +41,19 @@ export struct EventBtn {
height: '90%' // 图片高度占满按钮
})
.onClick(()=>{
ExecuteCommand(this.eventBtn as TitleButton);
})
}
}else {
//判断类型为true,属于模块切换事件
if (this.eventBtn != undefined) {
Button()
.width(ebWidth)
.height(ebHeigth)
.backgroundImage($r('app.media.' + this.eventBtn.eIcon))
.backgroundImagePosition({ x: '5%', y: '5%' })
.backgroundColor(Color.Transparent)
.backgroundImageSize({
width: '90%', // 图片宽度占满按钮
height: '90%' // 图片高度占满按钮
})
.onClick(() => {
if (this.eventBtn?.eEvent == 'Switch_Model_CAD') {
this.curtModel = TitleTabData.mModels.get(1)
} else if (this.eventBtn?.eEvent == 'Switch_Model_CAM') {
this.curtModel = TitleTabData.mModels.get(2)
} else if (this.eventBtn?.eEvent == 'Switch_Model_CAE') {
this.curtModel = TitleTabData.mModels.get(3)
if(!this.eventBtnType){
ExecuteCommand(this.eventBtn as TitleButton);
}else{
if (this.eventBtn?.eEvent == 'Switch_Model_CAD') {
this.curtModel = TitleTabData.mModels.get(1)
} else if (this.eventBtn?.eEvent == 'Switch_Model_CAM') {
this.curtModel = TitleTabData.mModels.get(2)
} else if (this.eventBtn?.eEvent == 'Switch_Model_CAE') {
this.curtModel = TitleTabData.mModels.get(3)
}
}
})
}
}
if (this.eventBtn != undefined) {
Text()
.width('auto')
@ -142,19 +128,14 @@ export struct MenuBtn {
}
}
export enum MenuType{
TEXT,
ICON,
INDEXICON
};
//Title Sub功能目录菜单
//图片按钮菜单功能.
//该符合组件支持用户选择Button的Icon的Index联动
@ComponentV2
export struct SubColumnMenu {
@Param menus: Array<TitleButton|Array<TitleButton>> = [];
@Local curtIndex:number=0;
@Param inputIcon:string|undefined=undefined;
@Param menuType:MenuType=MenuType.TEXT;
@Param icon:string|undefined=undefined;
@Param name:string|undefined=undefined;
@Builder
SubMenu (subMenu:Array<TitleButton>) {
@ -180,6 +161,7 @@ export struct SubColumnMenu {
MenuItem({ startIcon: $r('app.media.'+item.eIcon), content: item.eName })
.onClick(()=> {
this.curtIndex=index;
ExecuteCommand(item as TitleButton);
})
.size({height: ebWidth})
}else{
@ -195,49 +177,18 @@ export struct SubColumnMenu {
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.menus[this.curtIndex]as TitleButton).eIcon))
.backgroundImagePosition({ x: '5%', y: '5%' })
.backgroundImageSize({
width: '90%', // 图片宽度占满按钮
height: '90%' // 图片高度占满按钮
})
.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)
}
}
Button(){
Row(){
Image($r('app.media.'+(this.icon!=undefined ? this.icon:(this.menus[this.curtIndex]as TitleButton).eIcon)))
if(this.name!=undefined){
Text(this.name).fontSize(20)
}
}
}.width(ebWidth)
.height(ebWidth)
.backgroundColor(Color.Transparent)
.bindMenu(this.BaseMenu)
.type(ButtonType.Normal)
}.width(this.name!=undefined ?mwInfo.mainWindowWidth*0.03:ebWidth)
}
}

View File

@ -1,27 +1,43 @@
import { mwInfo } from "../AppStorageV2Class";
import { TitleButton } from "../LayoutInterface/Interface/ButtonInterface";
//按钮统一尺寸,该按钮为正方形,所以以主窗口宽为基准,长=高->正方形
let ebWidth=mwInfo.mainWindowWidth*0.075;
let ebHeigth=mwInfo.mainWindowHeight*0.03;
//占位符的高度
let edHeigth=mwInfo.mainWindowWidth*0.005
@ComponentV2
export struct TextComboBox {
@Param menu: Array<TitleButton> = new Array<TitleButton>;
@Local selectIndex:number=0;
@Param name:string|undefined=undefined;
@Builder
EventMenu() {
Menu() {
ForEach(this.menu, (item: TitleButton, index: number) => {
MenuItem({ content: item.eName })
.size({height: mwInfo.mainWindowWidth*0.02})
.size({height: ebHeigth})
.onClick(()=>{
this.selectIndex=index;
})
})
}
}.fontSize(20)
}
build() {
Row() {
Text(this.name!=undefined?this.name:'')
.fontSize(18)
.width('auto')
Text(this.menu[this.selectIndex].eName)
.bindMenu(this.EventMenu)
}
.width('50%')
.fontSize(18)
.backgroundColor('#ffe6e6e3')
.height(mwInfo.mainWindowHeight*0.022)
.margin({ top:0, left: 5, bottom: 0, right: 0 })
}.width(ebWidth)
.height(ebHeigth)
}
}
@ComponentV2
@ -33,7 +49,7 @@ export struct TextInputComboBox {
Menu() {
ForEach(this.menu, (item: TitleButton, index: number) => {
MenuItem({ content: item.eName })
.size({height: mwInfo.mainWindowWidth*0.02})
.size({height: ebHeigth})
.onClick(()=>{
this.selectIndex=index;
})

View File

@ -1,6 +1,10 @@
import { mwInfo } from "../AppStorageV2Class";
import { TitleButton } from "../LayoutInterface/Interface/ButtonInterface";
import {SwitchView} from "../LayoutInterface/Layout/SwitchView"
//按钮统一尺寸,该按钮为正方形,所以以主窗口宽为基准,长=高->正方形
let ebWidth=mwInfo.mainWindowWidth*0.02;
let ebHeigth=mwInfo.mainWindowWidth*0.02;
//视图切换弹窗
@CustomDialog
export struct ViewDialog {
@ -11,14 +15,19 @@ export struct ViewDialog {
ForEach(SwitchView, (item: TitleButton, index?: number | undefined) => {
GridCol({ span: 1 }) {
Row() {
Image($r('app.media.' + item.eIcon))
.width('35vp')
.height('35vp')
.objectFit(ImageFit.Contain)
Button()
.backgroundColor(Color.Transparent)
.backgroundImage($r('app.media.' + item.eIcon))
.backgroundImageSize({
width: '100%', // 图片宽度占满按钮
height: '100%' // 图片高度占满按钮
})
.width(ebWidth)
.height(ebWidth)
}
}
})
}
}
}.margin({ top: 5, left: 1, bottom: 1, right: 1 })
}
}

View File

@ -7,7 +7,7 @@ import {DisplayMode} from "../LayoutInterface/Layout/DisplayMode"
import { LayoutSwitch } from "../LayoutInterface/Layout/LayoutSwitch";
import { FileMenuData } from "../LayoutInterface/Layout/FileMenuData";
import { mwInfo } from "../AppStorageV2Class";
import { SubColumnMenu ,MenuType} from "../CustomStyle/Button";
import { SubColumnMenu} from "../CustomStyle/Button";
@ComponentV2
@ -21,8 +21,8 @@ export struct TitleColumnSub {
private ViewDialog(): CustomDialogController {
return new CustomDialogController({
builder: ViewDialog(), // 确保 ViewDialog 组件已正确定义
width: mwInfo.mainWindowWidth*0.04,
height: mwInfo.mainWindowWidth*0.04,
width: mwInfo.mainWindowWidth*0.06,
height: mwInfo.mainWindowWidth*0.052,
borderWidth: 1,
cornerRadius: 5,
isModal: true,
@ -34,23 +34,15 @@ export struct TitleColumnSub {
build(){
Row({space:5}){
SubColumnMenu({
menus:FileMenuData.aMenus as Array<TitleButton>,
inputIcon:'base_shortcut_menu',
menuType:MenuType.ICON})
menus:FileMenuData.aMenus as Array<TitleButton>, icon:'base_shortcut_menu',name:'菜单'})
.margin({ top:0, left: 5, bottom: 0, right: 0 })
Text('菜单')
.fontSize(20)
Text('|')
Text('拾取类型:')
.fontSize(20)
TextComboBox({menu:SelectionFilter})
.borderWidth(1)
.borderColor(Color.Grey)
.borderRadius(5)
TextComboBox({name:'拾取类型:',menu:SelectionFilter})
Text('图层:')
.fontSize(20)
TextInputComboBox({menu:this.layerArray}).width('10%')
SubColumnMenu({menus:LayoutSwitch,menuType:MenuType.INDEXICON})
SubColumnMenu({menus:LayoutSwitch})
//视角弹窗
Button().onClick((event) => {
this.dX=event.windowX
@ -59,15 +51,15 @@ export struct TitleColumnSub {
this.viewDialog=this.ViewDialog();
}
this.viewDialog.open();
}).width(mwInfo.mainWindowWidth*0.013)
.height(mwInfo.mainWindowWidth*0.013)
}).width(mwInfo.mainWindowWidth*0.014)
.height(mwInfo.mainWindowWidth*0.014)
.backgroundColor(Color.Transparent)
.backgroundImage($r('app.media.' + SwitchView[0].eIcon))
.backgroundImageSize({
width: '100%', // 图片宽度占满按钮
height: '100%' // 图片高度占满按钮
})
SubColumnMenu({menus:DisplayMode,menuType:MenuType.INDEXICON})
SubColumnMenu({menus:DisplayMode})
}.margin({ top: 1, left: 1, bottom: 1, right: 1 })
}
}

View File

@ -4,7 +4,6 @@ import { TitleGroup} from '../LayoutInterface/Interface/GroupInterface';
import {GroupTextEventMenu} from '../CustomStyle/Menu'
import {EventBtn,MenuBtn} from '../CustomStyle/Button'
import { TitleModel } from '../LayoutInterface/Layout/TitleTabData';
import { mwInfo } from '../AppStorageV2Class';
@ComponentV2
export struct TitleTabContent {
@ -42,13 +41,12 @@ export struct TitleTabContent {
}
}
})
}.margin({ top: 1,left:1,bottom:1,right:1})
}.margin({ top: 1,left:10,bottom:1,right:10})
//功能组名
Row(){
GroupTextEventMenu({grpEvent:group_item})
}
}.margin({ top: 0,left:0,bottom:-5,right:0})
}
Divider().vertical(true).strokeWidth(1).lineCap(LineCapStyle.Round).height('95%').backgroundColor(Color.Gray)
})
}else{