From 6dca70bc9562df724267f8e3e7aaa00936d9d4bd Mon Sep 17 00:00:00 2001 From: wangzhitong Date: Mon, 25 Mar 2024 18:37:01 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E5=88=86ext=20api=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get-app-base-info/get-app-base-info.uvue | 13 ++++- .../API/get-device-info/get-device-info.uvue | 30 ++++++---- .../API/get-system-info/get-system-info.uvue | 58 ++++++++++++------- 3 files changed, 66 insertions(+), 35 deletions(-) diff --git a/pages/API/get-app-base-info/get-app-base-info.uvue b/pages/API/get-app-base-info/get-app-base-info.uvue index f181af48..e51cee92 100644 --- a/pages/API/get-app-base-info/get-app-base-info.uvue +++ b/pages/API/get-app-base-info/get-app-base-info.uvue @@ -35,8 +35,16 @@ methods: { getAppBaseInfo: function () { const res = uni.getAppBaseInfo(); + const res_str = JSON.stringify(res); + const res_obj = JSON.parseObject(res_str); + const res_map = res_obj!.toMap(); + let keys = [] as string[] + res_map.forEach((_, key) => { + keys.push(key); + }); + this.items = [] as Item[]; - for(const key in res){ + keys.sort().forEach( key => { const value = res[key]; if(value != null){ const item = { @@ -45,7 +53,8 @@ } as Item; this.items.push(item); } - } + }); + } } } diff --git a/pages/API/get-device-info/get-device-info.uvue b/pages/API/get-device-info/get-device-info.uvue index 91a77555..72f0b557 100644 --- a/pages/API/get-device-info/get-device-info.uvue +++ b/pages/API/get-device-info/get-device-info.uvue @@ -51,17 +51,25 @@ const res = uni.getDeviceInfo(); // 获取像素比, 供截图对比使用 setDevicePixelRatio(res.devicePixelRatio !== null ? parseFloat(res.devicePixelRatio!) : 1) - this.items = [] as Item[]; - for (const key in res) { - const value = res[key]; - if (value != null) { - const item = { - label: key, - value: "" + ((typeof value == "object") ? JSON.stringify(value) : value) - } as Item; - this.items.push(item); - } - } + this.items = [] as Item[]; + + const res_str = JSON.stringify(res); + const res_obj = JSON.parseObject(res_str); + const res_map = res_obj!.toMap(); + let keys = [] as string[] + res_map.forEach((_, key) => { + keys.push(key); + }); + keys.sort().forEach( key => { + const value = res[key]; + if(value != null){ + const item = { + label: key, + value: "" + ((typeof value == "object")? JSON.stringify(value) : value) + } as Item; + this.items.push(item); + } + }); } } } diff --git a/pages/API/get-system-info/get-system-info.uvue b/pages/API/get-system-info/get-system-info.uvue index 598c25f1..f1115d1d 100644 --- a/pages/API/get-system-info/get-system-info.uvue +++ b/pages/API/get-system-info/get-system-info.uvue @@ -51,33 +51,47 @@ getSystemInfo: function () { uni.getSystemInfo({ success: (res) => { - this.items = [] as Item[]; - for (const key in res) { - const value = res[key]; - if (value != null) { - const item = { - label: key, - value: "" + ((typeof value == "object") ? JSON.stringify(value) : value) - } as Item; - this.items.push(item); - } - } + this.items = [] as Item[]; + const res_str = JSON.stringify(res); + const res_obj = JSON.parseObject(res_str); + const res_map = res_obj!.toMap(); + let keys = [] as string[] + res_map.forEach((_, key) => { + keys.push(key); + }); + keys.sort().forEach( key => { + const value = res[key]; + if(value != null){ + const item = { + label: key, + value: "" + ((typeof value == "object")? JSON.stringify(value) : value) + } as Item; + this.items.push(item); + } + }); }, }) }, getSystemInfoSync: function () { this.items = [] as Item[]; - const res = uni.getSystemInfoSync() - for (const key in res) { - const value = res[key]; - if (value != null) { - const item = { - label: key, - value: "" + ((typeof value == "object") ? JSON.stringify(value) : value) - } as Item; - this.items.push(item); - } - } + const res = uni.getSystemInfoSync() + const res_str = JSON.stringify(res); + const res_obj = JSON.parseObject(res_str); + const res_map = res_obj!.toMap(); + let keys = [] as string[] + res_map.forEach((_, key) => { + keys.push(key); + }); + keys.sort().forEach( key => { + const value = res[key]; + if(value != null){ + const item = { + label: key, + value: "" + ((typeof value == "object")? JSON.stringify(value) : value) + } as Item; + this.items.push(item); + } + }); }, //自动化测试例专用 jest_getSystemInfo() : GetSystemInfoResult { -- GitLab