zhou zhou
4 小时以前 fec285d150b377d004e47f0973d298b92fe4c711
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class IframeRouteManager {
  constructor() {
    this.iframeRoutes = []
  }
  static getInstance() {
    if (!IframeRouteManager.instance) {
      IframeRouteManager.instance = new IframeRouteManager()
    }
    return IframeRouteManager.instance
  }
  /**
   * 添加 iframe 路由
   */
  add(route) {
    if (!this.iframeRoutes.find((r) => r.path === route.path)) {
      this.iframeRoutes.push(route)
    }
  }
  /**
   * 获取所有 iframe 路由
   */
  getAll() {
    return this.iframeRoutes
  }
  /**
   * 根据路径查找 iframe 路由
   */
  findByPath(path) {
    return this.iframeRoutes.find((route) => route.path === path)
  }
  /**
   * 清空所有 iframe 路由
   */
  clear() {
    this.iframeRoutes = []
  }
  /**
   * 保存到 sessionStorage
   */
  save() {
    if (this.iframeRoutes.length > 0) {
      sessionStorage.setItem('iframeRoutes', JSON.stringify(this.iframeRoutes))
    }
  }
  /**
   * 从 sessionStorage 加载
   */
  load() {
    try {
      const data = sessionStorage.getItem('iframeRoutes')
      if (data) {
        this.iframeRoutes = JSON.parse(data)
      }
    } catch (error) {
      console.error('[IframeRouteManager] 加载 iframe 路由失败:', error)
      this.iframeRoutes = []
    }
  }
}
 
IframeRouteManager.instance = null
 
export { IframeRouteManager }