29 lines
704 B
JavaScript
29 lines
704 B
JavaScript
import MiniProgramPlatform from './MiniProgramPlatform';
|
|
import AppPlatform from './AppPlatform';
|
|
import H5Platform from './H5Platform';
|
|
|
|
class PlatformFactory {
|
|
static create() {
|
|
// 判断小程序环境
|
|
//#ifdef MP-WEIXIN
|
|
return new MiniProgramPlatform();
|
|
//#endif
|
|
|
|
// 判断 App 环境
|
|
//#ifdef APP-ANDROID
|
|
return new AppPlatform();
|
|
//#endif
|
|
// 判断 H5 环境
|
|
//#ifdef WEB
|
|
return new H5Platform();
|
|
//#endif
|
|
|
|
// 默认返回 小程序
|
|
return new MiniProgramPlatform();
|
|
}
|
|
}
|
|
|
|
// 使用示例
|
|
const platform = PlatformFactory.create();
|
|
console.log(platform.env);
|
|
export { platform }; |