Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
4e956ff2
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6006
Star
91
Fork
164
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
4e956ff2
编写于
6月 20, 2024
作者:
辛宝Otto
🥊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: 全局获取 systemInfoSync 兼容本地测试环境
上级
31bd7c5e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
47 deletion
+54
-47
pages/API/get-system-info/get-system-info.uvue
pages/API/get-system-info/get-system-info.uvue
+54
-47
未找到文件。
pages/API/get-system-info/get-system-info.uvue
浏览文件 @
4e956ff2
...
@@ -37,76 +37,83 @@
...
@@ -37,76 +37,83 @@
type Item = {
type Item = {
label : string,
label : string,
value : string,
value : string,
}
}
const globalScreenHeight = uni.getSystemInfoSync().screenHeight
let globalScreenHeight = 0
try {
globalScreenHeight = uni.getSystemInfoSync().screenHeight
} catch (e) {
// 兼容本地测试
console.error(e)
}
export default {
export default {
data() {
data() {
return {
return {
title: 'getSystemInfo',
title: 'getSystemInfo',
items: [] as Item[],
items: [] as Item[],
screenHeightAtReady: 0,
screenHeightAtReady: 0,
jest_result: false,
jest_result: false,
}
}
},
},
onUnload: function () {
onUnload: function () {
},
},
onReady() {
onReady() {
this.screenHeightAtReady = uni.getSystemInfoSync().screenHeight
this.screenHeightAtReady = uni.getSystemInfoSync().screenHeight
console.log(`全局获取屏幕高度: ${globalScreenHeight} onReady内获取屏幕高度: ${this.screenHeightAtReady}`);
console.log(`全局获取屏幕高度: ${globalScreenHeight} onReady内获取屏幕高度: ${this.screenHeightAtReady}`);
},
},
methods: {
methods: {
getSystemInfo: function () {
getSystemInfo: function () {
uni.getSystemInfo({
uni.getSystemInfo({
success: (res) => {
success: (res) => {
this.items = [] as Item[];
this.items = [] as Item[];
const res_str = JSON.stringify(res);
const res_str = JSON.stringify(res);
const res_obj =
JSON.parseObject(res_str);
const res_obj =
JSON.parseObject(res_str);
const res_map = res_obj!.toMap();
const res_map = res_obj!.toMap();
let keys = [] as string[]
let keys = [] as string[]
res_map.forEach((_, key) => {
res_map.forEach((_, key) => {
keys.push(key);
keys.push(key);
});
});
keys.sort().forEach(
key => {
keys.sort().forEach(
key => {
const value = res[key];
const value = res[key];
if
(value != null){
if
(value != null) {
const item = {
const item = {
label: key,
label: key,
value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
} as Item;
} as Item;
this.items.push(item);
this.items.push(item);
}
}
});
});
},
},
})
})
},
},
getSystemInfoSync: function () {
getSystemInfoSync: function () {
this.items = [] as Item[];
this.items = [] as Item[];
const res = uni.getSystemInfoSync()
const res = uni.getSystemInfoSync()
const res_str = JSON.stringify(res);
const res_str = JSON.stringify(res);
const res_obj =
JSON.parseObject(res_str);
const res_obj =
JSON.parseObject(res_str);
const res_map = res_obj!.toMap();
const res_map = res_obj!.toMap();
let keys = [] as string[]
let keys = [] as string[]
res_map.forEach((_, key) => {
res_map.forEach((_, key) => {
keys.push(key);
keys.push(key);
});
});
keys.sort().forEach(
key => {
keys.sort().forEach(
key => {
const value = res[key];
const value = res[key];
if
(value != null){
if
(value != null) {
const item = {
const item = {
label: key,
label: key,
value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
value: "" + ((typeof value == "object") ? JSON.stringify(value) : value)
} as Item;
} as Item;
this.items.push(item);
this.items.push(item);
}
}
});
});
},
},
//自动化测试例专用
//自动化测试例专用
jest_getSystemInfo() : GetSystemInfoResult {
jest_getSystemInfo() : GetSystemInfoResult {
return uni.getSystemInfoSync();
return uni.getSystemInfoSync();
},
},
jest_getScreenHeight_at_different_stages()
{
jest_getScreenHeight_at_different_stages()
{
this.jest_result = (globalScreenHeight == this.screenHeightAtReady)
this.jest_result = (globalScreenHeight == this.screenHeightAtReady)
}
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录