diff --git a/common/js/util-navigate.js b/common/js/util-navigate.js index 75b4be8..ba7d407 100644 --- a/common/js/util-navigate.js +++ b/common/js/util-navigate.js @@ -421,12 +421,18 @@ export function getPlatform() { } // 2) 编译时变量 - try { /* #ifdef H5 */ return 'h5'; /* #endif */ } catch (e) { /* ignore */ } - try { /* #ifdef MP-WEIXIN */ return 'mp-weixin'; /* #endif */ } catch (e) { /* ignore */ } - try { /* #ifdef MP-HARMONY */ return 'mp-harmony'; /* #endif */ } catch (e) { /* ignore */ } - try { /* #ifdef MP-QUICKAPP */ return 'quickapp'; /* #endif */ } catch (e) { /* ignore */ } + // #ifdef MP-WEIXIN + return 'mp-weixin' + // #endif + // #ifdef MP-HARMONY + return 'mp-harmony' + // #endif // 3) 运行时 + if (navigator?.userAgent?.includes('mode-quickapp')) { // H5网页,如何判断自己在华为快应用的Webview中 + return 'quickapp' + } + if (typeof process !== 'undefined' && process.env && process.env.UNI_PLATFORM) { return process.env.UNI_PLATFORM; } @@ -435,7 +441,7 @@ export function getPlatform() { } if (typeof uni !== 'undefined' && typeof uni.getSystemInfoSync === 'function') { try { - const info = uni.getSystemInfoSync(); + const info = uni?.getSystemInfoSync(); const p = (info && info.platform) || ''; if (/harmony|ohos/i.test(p)) return 'mp-harmony'; if (info.mp === true || /miniprogram/i.test(info.appName || '')) return 'mp-weixin'; @@ -443,6 +449,8 @@ export function getPlatform() { return 'h5'; } catch (e) { /* ignore */ } } + + // 默认返回 return 'h5'; }