提交 4e956ff2 编写于 作者: 辛宝Otto's avatar 辛宝Otto 🥊

refactor: 全局获取 systemInfoSync 兼容本地测试环境

上级 31bd7c5e
...@@ -38,7 +38,15 @@ ...@@ -38,7 +38,15 @@
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 {
...@@ -50,7 +58,6 @@ ...@@ -50,7 +58,6 @@
}, },
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}`);
...@@ -67,12 +74,12 @@ ...@@ -67,12 +74,12 @@
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);
} }
...@@ -90,12 +97,12 @@ ...@@ -90,12 +97,12 @@
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);
} }
...@@ -105,7 +112,7 @@ ...@@ -105,7 +112,7 @@
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.
先完成此消息的编辑!
想要评论请 注册