1 Star 0 Fork 0

雷琦玮/HarmonyOS_Winsleikit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
WindowHome.ets 3.30 KB
一键复制 编辑 原始数据 按行查看 历史
雷琦玮 提交于 2024-07-20 15:17 +08:00 . 完善demo逻辑
import { WinsleiLogManager } from '@winslei/winsleilog'
import { MenuInfo } from '../../Common/model/MenuInfo'
import Window from '@ohos.window'
import { AppStorageNameConstant } from '../../Common/constants/AppStorageNameConstant'
const TAG = 'WindowHome'
@Entry
@Component
struct WindowHome {
scroller: Scroller = new Scroller()
@State focusIndex: number = -1
@State menus: MenuInfo[] = []
private window: Window.Window | undefined = AppStorage.Get(AppStorageNameConstant.MAIN_WINDOW_NAME)
aboutToDisappear() {
Window.getLastWindow(getContext(this)).then((win) => {
win.setWindowLayoutFullScreen(false).then(() => {
win.setWindowSystemBarEnable(['status', 'navigation', 'navigationIndicator']).then(()=> {
})
})
})
}
aboutToAppear() {
Window.getLastWindow(getContext(this)).then((win) => {
win.setWindowLayoutFullScreen(true).then(() => {
// win.setWindowSystemBarEnable(['navigation', 'navigationIndicator']).then(()=> {
//
// })
win.setSpecificSystemBarEnabled('navigationIndicator', true).then(()=> {
})
})
})
let menuInfo1 = new MenuInfo()
menuInfo1.title = '屏幕常亮'
let menuInfo2 = new MenuInfo()
menuInfo2.title = 'Window'
let menuInfo3 = new MenuInfo()
menuInfo3.title = 'Window'
let menuInfo4 = new MenuInfo()
menuInfo4.title = 'Window'
let menuInfo5 = new MenuInfo()
menuInfo5.title = 'Window'
let menuInfo6 = new MenuInfo()
menuInfo6.title = 'Window'
let menuInfo7 = new MenuInfo()
menuInfo7.title = 'Window'
let menuInfo8 = new MenuInfo()
menuInfo8.title = 'Window'
let menuInfo9 = new MenuInfo()
menuInfo9.title = 'Window'
this.menus.push(menuInfo1, menuInfo2, menuInfo3, menuInfo4, menuInfo5, menuInfo6, menuInfo7, menuInfo8, menuInfo9)
}
build() {
Grid() {
ForEach(this.menus, (menuInfo: MenuInfo, index: number) => {
GridItem() {
Text(menuInfo.title)
.fontSize(30)
.fontColor(Color.White)
.backgroundColor('#1affffff')
.width('100%')
.height('100%')
.textAlign(TextAlign.Center)
.border({
style: BorderStyle.Solid,
width: this.focusIndex == index ? 4 : 0,
color: Color.White
})
.focusable(true)
.defaultFocus(index == 0)
.onFocus(() => {
WinsleiLogManager.hilogIWithTag(TAG, JSON.stringify(menuInfo))
this.focusIndex = index
})
.onClick((event?: ClickEvent) => {
switch(menuInfo.title) {
case '屏幕常亮':
if (this.window as Window.Window) {
(this.window as Window.Window).setWindowKeepScreenOn(true).then(()=>{
WinsleiLogManager.hilogIWithTag(TAG, `setWindowKeepScreenOn success`)
})
}
break
}
AppStorage.setOrCreate('showGlobalCustomDialog', true)
})
}
})
}
.columnsTemplate('1fr 1fr 1fr')
.rowsTemplate('1fr 1fr 1fr')
.columnsGap(10)
.rowsGap(10)
.width('100%')
.backgroundColor('#304353')
.height('100%')
.padding(20)
.focusable(true)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/winslei/harmony-os_-winsleikit.git
git@gitee.com:winslei/harmony-os_-winsleikit.git
winslei
harmony-os_-winsleikit
HarmonyOS_Winsleikit
d103e7fd19873f1aabae29268c9ffbf86ffe7961

搜索帮助