Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
8c1abfb1
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6067
Star
93
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
8c1abfb1
编写于
10月 18, 2024
作者:
DCloud-yinjiacheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新getWindowInfo示例
上级
1ed52515
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
178 addition
and
1 deletion
+178
-1
pages.json
pages.json
+9
-0
pages/API/get-current-pages/page-style.uts
pages/API/get-current-pages/page-style.uts
+10
-0
pages/API/get-window-info/get-window-info.uvue
pages/API/get-window-info/get-window-info.uvue
+7
-0
pages/API/get-window-info/window-area.uvue
pages/API/get-window-info/window-area.uvue
+146
-0
pages/template/slider-100/slider-100.uvue
pages/template/slider-100/slider-100.uvue
+6
-1
未找到文件。
pages.json
浏览文件 @
8c1abfb1
...
...
@@ -967,6 +967,13 @@
"navigationBarTitleText"
:
"getWindowInfo | 获取窗口信息"
}
},
{
"path"
:
"pages/API/get-window-info/window-area"
,
"style"
:
{
"navigationBarTitleText"
:
"window area"
,
"navigationStyle"
:
"custom"
}
},
//
#ifndef
WEB
{
"path"
:
"pages/API/element-draw/element-draw"
,
...
...
@@ -1879,6 +1886,8 @@
"backgroundColorContent"
:
"@backgroundColorContent"
,
"backgroundColor"
:
"@backgroundColor"
,
"backgroundTextStyle"
:
"@backgroundTextStyle"
"hideStatusBar"
:
false
,
"hideBottomNavigationIndicator"
:
false
},
"tabBar"
:
{
"color"
:
"@tabBarColor"
,
...
...
pages/API/get-current-pages/page-style.uts
浏览文件 @
8c1abfb1
...
...
@@ -70,4 +70,14 @@ export const PageStyleArray = [
key: "navigationBarAutoBackButton",
type: "boolean",
value: [true, false]
},
{
key: "hideStatusBar",
type: "boolean",
value: [true, false]
},
{
key: "hideBottomNavigationIndicator",
type: "boolean",
value: [true, false]
}] as PageStyleItem[]
pages/API/get-window-info/get-window-info.uvue
浏览文件 @
8c1abfb1
...
...
@@ -15,6 +15,13 @@
<view class="uni-btn-v">
<button type="primary" @tap="getWindowInfo">获取窗口信息</button>
</view>
<!-- #ifdef APP-ANDROID -->
<view class="uni-btn-v">
<navigator url="/pages/API/get-window-info/window-area">
<button type="primary">窗口各区域示例</button>
</navigator>
</view>
<!-- #endif -->
</view>
</view>
</template>
...
...
pages/API/get-window-info/window-area.uvue
0 → 100644
浏览文件 @
8c1abfb1
<template>
<view style="flex:1;">
<view id="statusBar" class="statusBar" v-if="statusBarArea.width > 0 && statusBarArea.height > 0"
:style="{'width': statusBarArea.width,'height': statusBarArea.height}">
</view>
<view id="cutoutArea" class="cutoutArea" v-if="cutoutArea.length > 0" v-for="(item, _) in cutoutArea"
:style="{'top': item.top,'left': item.left,'width': item.width,'height': item.height}"></view>
<view id="safeArea" class="safeArea"
:style="{'top': safeArea.top,'left': safeArea.left,'width': safeArea.width,'height': safeArea.height}"></view>
<view id="bottomNavigationIndicator" class="bottomNavigationIndicator"
v-if="bottomNavigationIndicatorArea.width > 0 && bottomNavigationIndicatorArea.height > 0"
:style="{'width': bottomNavigationIndicatorArea.width,'height': bottomNavigationIndicatorArea.height}"></view>
<view style="flex: 1;justify-content: center;align-items: center;">
<view style="margin: 5px 0;">
<text style="color: red;">系统状态栏区域</text>
</view>
<view style="margin: 5px 0;">
<text style="color: orange;">摄像头区域</text>
</view>
<view style="margin: 5px 0;">
<text style="color: green;">安全区域</text>
</view>
<view style="margin: 5px 0;">
<text style="color: blue;">系统导航栏区域</text>
</view>
<!-- <view style="flex-direction: row;align-items: center;margin: 5px 0">
<text>显示系统状态栏</text>
<switch :checked="isStatusBarShow" @change="statusBarChange"></switch>
</view>
<view style="flex-direction: row;align-items: center;margin: 5px 0">
<text>显示系统导航栏</text>
<switch :checked="isBottomNavigationIndicatorShow" @change="bottomNavigationIndicatorChange"></switch>
</view> -->
</view>
</view>
</template>
<script setup>
type StatusBarArea = {
width : number,
height : number
}
type CutoutArea = {
top : number,
left : number,
width : number,
height : number
}
type SafeArea = {
top : number,
left : number,
width : number,
height : number
}
type BottomNavigationIndicatorArea = {
width : number,
height : number
}
const statusBarArea = ref({ width: 0, height: 0 } as StatusBarArea);
const cutoutArea = ref([] as CutoutArea[]);
const safeArea = ref({ top: 0, left: 0, width: 0, height: 0 } as SafeArea);
const bottomNavigationIndicatorArea = ref({ width: 0, height: 0 } as BottomNavigationIndicatorArea);
const isStatusBarShow = ref(false);
const isBottomNavigationIndicatorShow = ref(false);
const getWindowInfo = () => {
const info = uni.getWindowInfo();
statusBarArea.value.width = info.windowWidth;
statusBarArea.value.height = info.safeAreaInsets.top;
cutoutArea.value.length = 0;
(info.cutoutArea ?? []).forEach((item) => {
cutoutArea.value.push({
top: item.top,
left: item.left,
width: item.right - item.left,
height: item.bottom - item.top
} as CutoutArea);
})
safeArea.value.top = info.safeArea.top;
safeArea.value.left = info.safeArea.left;
safeArea.value.width = info.safeArea.width;
safeArea.value.height = info.safeArea.height;
bottomNavigationIndicatorArea.value.width = info.windowWidth;
bottomNavigationIndicatorArea.value.height = info.safeAreaInsets.bottom;
};
const statusBarChange = (e : UniSwitchChangeEvent) => {
const pages = getCurrentPages();
pages[pages.length - 1].setPageStyle({
'hideStatusBar': !e.detail.value,
});
};
const bottomNavigationIndicatorChange = (e : UniSwitchChangeEvent) => {
const pages = getCurrentPages();
pages[pages.length - 1].setPageStyle({
'hideBottomNavigationIndicator': !e.detail.value,
});
};
onReady(() => {
const pages = getCurrentPages();
isStatusBarShow.value = !(pages[pages.length - 1].getPageStyle()['hideStatusBar'] as boolean);
isBottomNavigationIndicatorShow.value = !(pages[pages.length - 1].getPageStyle()['hideBottomNavigationIndicator'] as boolean);
getWindowInfo();
});
onResize((_ : OnResizeOptions) => {
getWindowInfo();
});
</script>
<style>
.statusBar {
position: absolute;
border-style: solid;
border-color: red;
border-width: 4px;
}
.cutoutArea {
position: absolute;
border-style: solid;
border-color: orange;
border-width: 4px;
}
.safeArea {
position: absolute;
border-style: solid;
border-color: green;
border-width: 4px;
}
.bottomNavigationIndicator {
position: absolute;
bottom: 0;
border-style: solid;
border-color: blue;
border-width: 4px;
}
</style>
pages/template/slider-100/slider-100.uvue
浏览文件 @
8c1abfb1
...
...
@@ -10,6 +10,7 @@
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
<view :style="{'height': safeAreaInsetsBottom}"></view>
</template>
<script>
...
...
@@ -17,9 +18,13 @@
data() {
return {
title: 'slider 滑块 x 100',
sliderValue: 50
sliderValue: 50,
safeAreaInsetsBottom: 0
}
},
onReady() {
this.safeAreaInsetsBottom = uni.getWindowInfo().safeAreaInsets.bottom;
},
methods: {
sliderChange(e : UniSliderChangeEvent) {
this.updateSliderValue(e.detail.value)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录