mh-two-thousand-and-two
2024-04-12 3d2ec2fd0578d3ba0a414b0cc4e4a2ae60878596
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
import {
  WEBVIEW_READY
} from '../../../constants'
 
export function onWebviewRecovery (webview, routeOptions) {
  const {
    subscribe,
    unsubscribe
  } = UniServiceJSBridge
 
  const id = webview.id
  const onWebviewRecoveryReady = function (data, pageId) {
    if (id !== pageId) {
      return
    }
    unsubscribe(WEBVIEW_READY, onWebviewRecoveryReady)
    if (process.env.NODE_ENV !== 'production') {
      console.log(`UNIAPP[webview][${id}]:onWebviewRecoveryReady ready`)
    }
    // 恢复目标页面
    pageId = parseInt(pageId)
    const page = getCurrentPages(true).find(page => page.$page.id === pageId)
    if (!page) {
      return console.error(`Page[${pageId}] not found`)
    }
    page.$vm._$vd.restore()
  }
 
  webview.addEventListener('recovery', e => {
    if (process.env.NODE_ENV !== 'production') {
      console.log(`UNIAPP[webview][${this.id}].recovery.reload:` + JSON.stringify({
        path: routeOptions.path,
        webviewId: id
      }))
    }
    subscribe(WEBVIEW_READY, onWebviewRecoveryReady)
  })
}