设备信息读取统一,app权限优化

This commit is contained in:
gongfuxiang
2026-03-30 16:08:59 +08:00
parent 5de10cb32f
commit d73d992a4d
11 changed files with 32 additions and 25 deletions

18
App.vue
View File

@ -312,13 +312,13 @@
* is_real 是否实时读取
*/
get_system_info(key, dv, is_real) {
var info = null;
var info = {};
if ((is_real || false) == true) {
info = this.set_system_info() || null;
info = this.set_system_info() || {};
} else {
info = uni.getStorageSync(this.data.cache_system_info_key) || null;
info = uni.getStorageSync(this.data.cache_system_info_key) || {};
}
if (info == null || (key || null) == null) {
if ((key || null) == null) {
return info;
}
return info[key] == undefined ? (dv == undefined ? null : dv) : info[key];
@ -328,9 +328,11 @@
* 设置设备信息
*/
set_system_info() {
var system_info = uni.getSystemInfoSync();
uni.setStorageSync(this.data.cache_system_info_key, system_info);
return system_info;
if(!plus.runtime.isAgreePrivacy()) {
var system_info = uni.getSystemInfoSync();
uni.setStorageSync(this.data.cache_system_info_key, system_info);
return system_info;
}
},
/**
@ -2032,7 +2034,7 @@
// 是否pc
is_pc() {
var arr = ['macos', 'windows'];
return arr.indexOf(uni.getSystemInfoSync().platform) != -1;
return arr.indexOf(this.get_system_info('platform')) != -1;
},
// 终端类型

View File

@ -39,7 +39,7 @@
var btn_width = this.propBtnWidth;
// 未指定购物车对象则读取tabbar数据自动计算购物车位置
if((cart || null) == null || (cart[0] || null) == null) {
var info = uni.getSystemInfoSync();
var info = app.globalData.get_system_info();
// 当前页面
var page = app.globalData.current_page().split('?');
switch(page[0]) {

View File

@ -133,8 +133,8 @@
// #ifndef H5
// 底部菜单距离底部的安全距离减去20、默认的安全距离太高了
var safe_areaInsets = uni.getSystemInfoSync().safeAreaInsets || {};
var bottom = parseInt(safe_areaInsets.bottom || 0);
var safe_area_insets = app.globalData.get_system_info('safeAreaInsets') || {};
var bottom = parseInt(safe_area_insets.bottom || 0);
if (bottom > 0) {
bottom -= 24;
}

View File

@ -121,7 +121,7 @@
var left = 0;
// #ifdef H5
// 处理内容左边距、避免父级设置内边距影响
var width = uni.getSystemInfoSync().windowWidth;
var width = parseInt(app.globalData.get_system_info('windowWidth', 0));
if (width > 960) {
left = (width - 800) / 2;
}

View File

@ -49,12 +49,10 @@
computed: {
// 跳过样式
skip_position_style() {
const {
statusBarHeight
} = uni.getSystemInfoSync();
const status_bar_height = parseInt(app.globalData.get_system_info('statusBarHeight', 0));
if (!this.propHasNavbar) {
return this.obj_to_style({
'top': `${statusBarHeight*2 + 88 + 30}rpx`,
'top': `${status_bar_height*2 + 88 + 30}rpx`,
});
}
return this.obj_to_style({

View File

@ -15,7 +15,7 @@
components: {},
props: {},
mounted() {
this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
this.statusBarHeight = app.globalData.get_system_info('statusBarHeight') + 'px';
},
methods: {}
};

View File

@ -34,6 +34,7 @@
</template>
<script>
const app = getApp();
// #ifdef H5
import keypress from './keypress.js';
// #endif
@ -365,7 +366,7 @@
},
mounted() {
const fixSize = () => {
const { windowWidth, windowHeight, windowTop, safeArea, screenHeight, safeAreaInsets } = uni.getSystemInfoSync();
const { windowWidth, windowHeight, windowTop, safeArea, screenHeight, safeAreaInsets } = app.globalData.get_system_info();
this.popupWidth = windowWidth;
this.popupHeight = windowHeight + (windowTop || 0);
// TODO fix by mehaotian 是否适配底部安全区 ,目前微信ios 、和 app ios 计算有差异,需要框架修复

View File

@ -55,7 +55,15 @@
],
"targetSdkVersion" : 30,
"minSdkVersion" : 23,
"excludePermissions" : []
"excludePermissions" : [],
"permissionPhoneState" : {
"request" : "none",
"prompt" : "为保证您正常、安全地使用,需要获取设备识别码(部分手机提示为获取手机号码)使用权限,请允许。"
},
"permissionExternalStorage" : {
"request" : "none",
"prompt" : "应用保存运行状态等信息,需要获取读写手机存储(系统提示为访问设备上的照片、媒体内容和文件)权限,请您允许。"
}
},
"ios" : {
"dSYMs" : false,

View File

@ -151,10 +151,8 @@
init() {
const new_form = this.propValue.content;
const new_style = this.propValue.style;
// 获取当前手机的宽度
const { windowWidth } = uni.getSystemInfoSync();
// 将80%的宽度分成16份
const block = (windowWidth * 0.8) / 16;
const block = (system.windowWidth * 0.8) / 16;
const { common_style, actived_color, data_left_spacing = 0, data_padding = old_padding } = new_style;
// scaleToFill 对应 fill aspectFit 对应 contain aspectFill 对应 cover

View File

@ -76,7 +76,7 @@
}
const { float_style, float_style_color, display_location, offset_number_percentage } = this.propValue.style;
// 获取当前手机的宽度和高度
const { windowWidth, windowHeight } = uni.getSystemInfoSync();
const { windowWidth, windowHeight } = app.globalData.get_system_info();
// 计算出距离左边的距离
let x = display_location == 'left' ? 10 : windowWidth - 60;
// 计算出距离顶部的距离

View File

@ -313,8 +313,8 @@
const findIndex = new_content_tabs_list.findIndex(item => item.is_sliding_fixed == '1');
let roll = '';
// #ifdef H5
let systemInfo = uni.getSystemInfoSync();
if(/(iPhone|iPod|Android|ios|iPad)/i.test(systemInfo.platform)) {
let platform = app.globalData.get_system_info('platform');
if(/(iPhone|iPod|Android|ios|iPad)/i.test(platform)) {
roll = 'tabs_phone';
} else {
roll = 'tabs_pc';