Files
uniapp-tmp/polyfill.js
2026-04-24 10:20:50 +08:00

54 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// #ifdef MP-WEIXIN
// 拦截 wx.getSystemInfoSync 和 wx.getSystemInfo避免 uni-app 内部或第三方库调用导致微信原生警告
if (typeof wx !== 'undefined' && wx.getSystemInfoSync) {
const originalGetSystemInfoSync = wx.getSystemInfoSync;
wx.getSystemInfoSync = function () {
if (wx.getWindowInfo && wx.getAppBaseInfo && wx.getDeviceInfo && wx.getAppAuthorizeSetting && wx.getSystemSetting) {
try {
const windowInfo = wx.getWindowInfo() || {};
const appBaseInfo = wx.getAppBaseInfo() || {};
const deviceInfo = wx.getDeviceInfo() || {};
const appAuthorizeSetting = wx.getAppAuthorizeSetting() || {};
const systemSetting = wx.getSystemSetting() || {};
let safeAreaInsets = undefined;
if (windowInfo.safeArea) {
safeAreaInsets = {
top: windowInfo.safeArea.top,
left: windowInfo.safeArea.left,
right: windowInfo.screenWidth - windowInfo.safeArea.right,
bottom: windowInfo.screenHeight - windowInfo.safeArea.bottom
};
}
return {
...windowInfo,
...appBaseInfo,
...deviceInfo,
...appAuthorizeSetting,
...systemSetting,
safeAreaInsets,
system: deviceInfo.system,
platform: deviceInfo.platform,
model: deviceInfo.model
};
} catch (e) {
return originalGetSystemInfoSync.call(wx);
}
}
return originalGetSystemInfoSync.call(wx);
};
const originalGetSystemInfo = wx.getSystemInfo;
wx.getSystemInfo = function (options) {
if (wx.getSystemInfoAsync) {
try {
return wx.getSystemInfoAsync(options);
} catch (e) {
return originalGetSystemInfo.call(wx, options);
}
}
return originalGetSystemInfo.call(wx, options);
};
}
// #endif