yfs/common/platform/PlatformFactory.js
2025-05-23 20:51:17 +08:00

65 lines
1.9 KiB
JavaScript

import MiniProgramPlatform from './MiniProgramPlatform';
//#ifdef APP-PLUS
import AppPlatform from './AppPlatform';
import IOSPlatform from './IOSPlatform';
//#endif
//#ifdef WEB
import H5Platform from './H5Platform';
import WebAppPlatform from './WebAppPlatform';
//#endif
class PlatformFactory {
static create() {
console.log('获取平台获取平台获取平台获取平台获取平台获取平台');
// 判断小程序环境
//#ifdef MP-WEIXIN
return new MiniProgramPlatform();
//#endif
// 判断 IOS环境
//#ifdef APP-IOS
return new IOSPlatform();
//#endif
// 判断 App 环境
//#ifdef APP
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
};