Files
yuto-water-h5/src/bridge/index.ts
hermes f585c1c505 feat: Batch 1 - basic pages (scanCode/privacyPolicy/resetPwd/notice/menuEdit/addGroup)
Agent Loop: 2 agents, both passed on iteration 1
6 new pages + 6 routes added
2026-06-15 21:04:21 +08:00

71 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 桥接层统一入口
*
* 导出类型定义、环境检测器以及各环境提供者,
* 并提供 createBridge() 工厂函数自动选择合适的提供者实例。
*
* @module bridge
*/
// ── 类型定义 ──
export type {
IBridge,
GetLocationOptions,
LocationResult,
ScanType,
ScanCodeOptions,
ScanCodeResult,
OpenMapParams,
ImageSourceType,
ChooseImageOptions,
ChooseImageResult,
DeviceInfo,
} from './types'
// ── 环境检测 ──
export {
detectEnvironment,
isWechatMiniProgram,
isUniappWebView,
isBrowser,
} from './detector'
export type { Environment } from './detector'
// ── 提供者 ──
export { default as browserProvider } from './providers/browser'
// ── 工厂函数 ──
import type { IBridge } from './types'
import { detectEnvironment } from './detector'
import browserProvider from './providers/browser'
/**
* 根据当前运行环境自动创建对应的 Bridge 实例
*
* - 普通浏览器:返回 browserProvider基于 Web API 降级实现)
* - 微信小程序 WebView待实现
* - uni-app WebView待实现
*
* @returns 符合 IBridge 接口的提供者实例
*/
export function createBridge(): IBridge {
const env = detectEnvironment()
switch (env) {
case 'wechat-mp':
// TODO: 引入 WechatProvider 后替换
throw new Error('微信小程序 WebView Bridge 尚未实现')
case 'uniapp-webview':
// TODO: 引入 UniappProvider 后替换
throw new Error('uni-app WebView Bridge 尚未实现')
case 'browser':
default:
return browserProvider
}
}
/** 当前环境的 Bridge 单例,页面直接使用 */
export const bridge: IBridge = createBridge()