import type { ConfirmOptions, FileDialogOptions, IDialogService, IFileService, IPlatformBridge, IStorageService, ISystemService, MessageOptions, PlatformType, SaveDialogOptions, } from '../types' export class WebBridge implements IPlatformBridge { readonly platform: PlatformType = 'web' file: IFileService = { async read(_path: string): Promise { console.warn('Web environment does not support file system access directly.') return '' }, async write(_path: string, _content: string): Promise { console.warn('Web environment does not support file system access directly.') }, async exists(_path: string): Promise { return false }, async openDialog(_options?: FileDialogOptions): Promise { return new Promise((resolve) => { const input = document.createElement('input') input.type = 'file' // Web端模拟,仅用于演示 input.onchange = (e) => { const files = (e.target as HTMLInputElement).files if (files && files.length > 0) { // Web端通常不能获取完整路径,这里只是模拟 resolve(files[0].name) } else { resolve(null) } } input.click() }) }, async saveDialog(_options?: SaveDialogOptions): Promise { console.warn('Web environment save dialog not fully supported.') return null }, } dialog: IDialogService = { async message(options: MessageOptions): Promise { // eslint-disable-next-line no-alert alert(`${options.title ? `${options.title}\n` : ''}${options.message}`) }, async confirm(options: ConfirmOptions): Promise { // eslint-disable-next-line no-alert return confirm(`${options.title ? `${options.title}\n` : ''}${options.message}`) }, } storage: IStorageService = { async get(key: string): Promise { const val = localStorage.getItem(key) return val ? JSON.parse(val) : null }, async set(key: string, value: T): Promise { localStorage.setItem(key, JSON.stringify(value)) }, async remove(key: string): Promise { localStorage.removeItem(key) }, async clear(): Promise { localStorage.clear() }, } system: ISystemService = { async getAppVersion(): Promise { return '1.0.0' }, async getPlatformInfo() { return { name: 'web', version: navigator.userAgent, os: navigator.platform, arch: 'unknown', } }, async openExternal(url: string): Promise { window.open(url, '_blank') }, } }