54 lines
1.8 KiB
JavaScript
54 lines
1.8 KiB
JavaScript
|
|
// #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
|