@gm-pc/react 1.13.3-alpha.1 → 1.13.3-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-pc/react",
3
- "version": "1.13.3-alpha.1",
3
+ "version": "1.13.3-alpha.2",
4
4
  "description": "观麦前端基础组件库",
5
5
  "author": "liyatang <liyatang@qq.com>",
6
6
  "homepage": "https://github.com/gmfe/gm-pc#readme",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@gm-common/hooks": "^2.10.0",
26
26
  "@gm-common/tool": "^2.10.0",
27
- "@gm-pc/locales": "^1.13.3-alpha.1",
27
+ "@gm-pc/locales": "^1.13.3-alpha.2",
28
28
  "big.js": "^6.0.1",
29
29
  "classnames": "^2.2.5",
30
30
  "lodash": "^4.17.19",
@@ -48,5 +48,5 @@
48
48
  "react-router-dom": "^5.2.0",
49
49
  "react-window": "^1.8.5"
50
50
  },
51
- "gitHead": "4605da606ef3651da81968ad6802fae8806a10d6"
51
+ "gitHead": "bdd278fe8bf983b735b760af20581ab580972632"
52
52
  }
@@ -28,7 +28,13 @@ export interface VBrowserProps {
28
28
  auth?: (from?: VBrowserWindow, to?: VBrowserWindow) => Promise<boolean> | boolean
29
29
  /**
30
30
  * 错误码参考
31
+ *
31
32
  * code: 0, message: '超过最大允许的窗口数量'
33
+ *
34
+ * code: 1, message: '鉴权失败'
35
+ *
36
+ * code: 2, message: '路由不存在‘
37
+ *
32
38
  */
33
39
  onError?: (error: { code: number; message: string }) => void
34
40
  /** 打开窗口如果没有传入标题,则使用此方法取标题 */
@@ -48,11 +48,9 @@ const WindowWrapper: FC<WindowWrapperProps> = ({ path }) => {
48
48
  data-vbrowser-window={path}
49
49
  ref={createRef()}
50
50
  >
51
- {/* <BrowserWindowContext.Provider value={page.path}> */}
52
51
  <Suspense fallback={loading}>
53
52
  <Component />
54
53
  </Suspense>
55
- {/* </BrowserWindowContext.Provider> */}
56
54
  </div>
57
55
  ) as CacheItem['vNode']
58
56
  browser['_setCache'](path, { vNode })
@@ -65,7 +65,7 @@ class VBrowser implements VBrowser {
65
65
  if (ignored) {
66
66
  const i = this.windows.indexOf(oldWindow!)
67
67
  this.windows.splice(i, 1)
68
- delete this._cache[i]
68
+ delete this._cache[oldWindow?.path!]
69
69
  }
70
70
 
71
71
  if (typeof w === 'number') {
@@ -110,9 +110,16 @@ class VBrowser implements VBrowser {
110
110
  } else {
111
111
  pass = (auth(this.activeWindow, w as VBrowserWindow) as boolean) ?? false
112
112
  }
113
- if (!pass) return this._fire('error', new Error('鉴权失败'))
113
+ if (!pass) {
114
+ this._fire('error', { code: 1, message: '鉴权失败' })
115
+ return
116
+ }
114
117
  if (!pages.find((p) => p.path === (w as VBrowserWindow).path)) {
115
- console.error(w.path, '页面不存在')
118
+ this._fire('error', {
119
+ code: 2,
120
+ message: `无法找到页面 ${w.path}, 可用路径:${pages.map((p) => p.path)}`,
121
+ })
122
+ return
116
123
  }
117
124
  // #endregion
118
125
 
@@ -123,8 +130,7 @@ class VBrowser implements VBrowser {
123
130
  )
124
131
  if (index === -1) {
125
132
  if (this.props.maxLength && this.windows.length >= this.props.maxLength) {
126
- this.props.onError &&
127
- this.props.onError({ code: 0, message: '超过最大允许的窗口数量' })
133
+ this._fire('error', { code: 0, message: '超过最大允许的窗口数量' })
128
134
  return
129
135
  }
130
136
 
@@ -271,6 +277,9 @@ class VBrowser implements VBrowser {
271
277
  private _fire(eventName: EventName, ...args: any[]) {
272
278
  const events = this._events[eventName] || []
273
279
  events.forEach((item) => item.event(...args))
280
+ if (eventName === 'error') {
281
+ this.props.onError && this.props.onError(args?.[0])
282
+ }
274
283
  }
275
284
  }
276
285