From ce136618264f719d5aa99fadb1ce423d80e6313e Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Tue, 6 Jan 2026 14:02:34 +0800 Subject: [PATCH] chore: wx.getSystemInfoSync is deprecated wx.getSystemInfoSync is deprecated.Please use wx.getSystemSetting/wx.getAppAuthorizeSetting/wx.getDeviceInfo/wx.getWindowInfo/wx.getAppBaseInfo instead. --- App.vue | 2 +- common/js/diy.js | 4 ++- common/js/map/openMap.js | 4 ++- common/js/navigation.js | 9 +++--- common/js/util.js | 30 +++++++++++++++---- components-diy/diy-goods-list.vue | 5 ++-- .../ns-goods-sku/ns-goods-sku-category.vue | 2 +- components/ns-goods-sku/ns-goods-sku.vue | 2 +- 8 files changed, 42 insertions(+), 16 deletions(-) diff --git a/App.vue b/App.vue index 7382b24..ad9b424 100644 --- a/App.vue +++ b/App.vue @@ -40,7 +40,7 @@ // #endif // #ifdef H5 - if (uni.getSystemInfoSync().platform == 'ios') { + if (this.$util.getDeviceInfo().platform == 'ios') { uni.setStorageSync('initUrl', location.href); } // #endif diff --git a/common/js/diy.js b/common/js/diy.js index 539e0fc..526d53f 100644 --- a/common/js/diy.js +++ b/common/js/diy.js @@ -1,7 +1,9 @@ import WxMap from 'common/js/map-wx-jssdk.js'; import Config from '@/common/js/config.js'; +import util from '@/common/js/util.js'; + +let systemInfo = util.getDeviceInfo(); -let systemInfo = uni.getSystemInfoSync(); export default { data() { return { diff --git a/common/js/map/openMap.js b/common/js/map/openMap.js index 9333ec7..943738c 100644 --- a/common/js/map/openMap.js +++ b/common/js/map/openMap.js @@ -1,3 +1,4 @@ +import util from '@/common/js/util.js' import TransformCoordinate from './transformCoordinate.js' function openMapByDefault(latitude, longitude, name) { @@ -85,7 +86,8 @@ export default { openMap(latitude, longitude, name, coord_type = 'gcj02') { let arr = getCoordByType(longitude, latitude, coord_type) // #ifdef APP-PLUS - switch (uni.getSystemInfoSync().platform) { + let platform = util.getDeviceInfo().platform; + switch (platform) { case 'android': console.log('运行Android上') openMapByAndroid(arr[1], arr[0], name) diff --git a/common/js/navigation.js b/common/js/navigation.js index 0550cd0..6494306 100644 --- a/common/js/navigation.js +++ b/common/js/navigation.js @@ -1,4 +1,5 @@ -import { EventSafety } from './event-safety' +import { EventSafety } from '@/common/js/event-safety.js' +import util from '@/common/js/util.js' export class NavigationHelper { constructor() { @@ -59,7 +60,7 @@ export class NavigationHelper { // 微信小程序精确计算 try { const menuButtonInfo = wx.getMenuButtonBoundingClientRect() - const systemInfo = uni.getSystemInfoSync() + let systemInfo = util.getDeviceInfo(); const height = menuButtonInfo.bottom + (menuButtonInfo.top - systemInfo.statusBarHeight) @@ -119,7 +120,7 @@ export class NavigationHelper { // 获取状态栏高度 getStatusBarHeight() { // #ifdef MP-WEIXIN - const systemInfo = uni.getSystemInfoSync() + let systemInfo = util.getDeviceInfo(); return systemInfo.statusBarHeight || 20 // #endif // #ifdef H5 @@ -138,7 +139,7 @@ export class NavigationHelper { // 获取安全区域 getSafeAreaInsets() { try { - const systemInfo = uni.getSystemInfoSync() + let systemInfo = util.getDeviceInfo(); return systemInfo.safeArea || { top: 0, bottom: 0, diff --git a/common/js/util.js b/common/js/util.js index 2874026..383881e 100644 --- a/common/js/util.js +++ b/common/js/util.js @@ -518,7 +518,7 @@ export default { * 检测苹果X以上的手机 */ isIPhoneX() { - let res = uni.getSystemInfoSync(); + let res = this.getDeviceInfo(); if (res.model.search('iPhone X') != -1) { return true; } @@ -526,13 +526,33 @@ export default { }, //判断安卓还是iOS isAndroid() { - let platform = uni.getSystemInfoSync().platform + let platform = this.getDeviceInfo().platform; if (platform == 'ios') { return false; } else if (platform == 'android') { return true; } }, + /** + * 获取设备信息(包含降级处理) + */ + getDeviceInfo() { + try { + return uni.getDeviceInfo(); + } catch (e) { + return uni.getSystemInfoSync(); + } + }, + /** + * 获取窗口信息(包含降级处理) + */ + getWindowInfo() { + try { + return uni.getWindowInfo(); + } catch (e) { + return uni.getSystemInfoSync(); + } + }, /** * 深度拷贝对象 * @param {Object} obj @@ -677,7 +697,7 @@ export default { */ uniappIsIPhoneX() { let isIphoneX = false; - let systemInfo = uni.getSystemInfoSync(); + let systemInfo = this.getDeviceInfo(); // #ifdef MP if (systemInfo.model.search('iPhone X') != -1 || systemInfo.model.search('iPhone 11') != -1 || systemInfo.model.search('iPhone 12') != -1 || systemInfo.model.search('iPhone 13') != -1) { isIphoneX = true; @@ -704,7 +724,7 @@ export default { */ uniappIsIPhone11() { let isIphone11 = false; - let systemInfo = uni.getSystemInfoSync(); + let systemInfo = this.getDeviceInfo(); // #ifdef MP if (systemInfo.model.search('iPhone 11') != -1) { isIphone11 = true; @@ -715,7 +735,7 @@ export default { // #ifdef H5 //判断该浏览器是否为safaria浏览器 isSafari() { - let res = uni.getSystemInfoSync(); + let res = this.getDeviceInfo(); var ua = navigator.userAgent.toLowerCase(); if (ua.indexOf('applewebkit') > -1 && ua.indexOf('mobile') > -1 && ua.indexOf('safari') > -1 && ua.indexOf('linux') === -1 && ua.indexOf('android') === -1 && ua.indexOf('chrome') === -1 && diff --git a/components-diy/diy-goods-list.vue b/components-diy/diy-goods-list.vue index 59441df..1095b78 100644 --- a/components-diy/diy-goods-list.vue +++ b/components-diy/diy-goods-list.vue @@ -254,6 +254,7 @@