import MiniProgramPlatform from './MiniProgramPlatform'; import AppPlatform from './AppPlatform'; //#ifdef WEB import H5Platform from './H5Platform'; import WebAppPlatform from './WebAppPlatform'; //#endif class PlatformFactory { static create() { // 判断小程序环境 //#ifdef MP-WEIXIN return new MiniProgramPlatform(); //#endif // 判断 App 环境 //#ifdef APP-ANDROID return new AppPlatform(); //#endif // 判断 H5 环境 //#ifdef WEB // if(window.location.href.includes('cb2039d0e35094521ae46a1d11b0ddd1')){ // return new WebAppPlatform(); // } console.log(window.location.href); //window.location.search let is_web_app = uni.getStorageSync('is_web_app'); let search = window.location.search; if (search != null && search != '') { const searchParams = new URLSearchParams(window.location.search); const code = searchParams.get('_p'); if (code && code == 'cb2039d0e35094521ae46a1d11b0ddd1') { uni.setStorageSync('is_web_app', true); is_web_app = true; } } if (uni.getStorageSync('is_web_app') != null && uni.getStorageSync('is_web_app') != '') { is_web_app = true; } if (is_web_app) { return new WebAppPlatform(); } return new H5Platform(); //#endif // 默认返回 小程序 return new MiniProgramPlatform(); } } // 使用示例 const platform = PlatformFactory.create(); console.log(platform.env); export { platform };