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
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
64
import {
  lastStatusBarStyle,
  setStatusBarStyle
} from '../../bridge'
export function onWebviewPopGesture (webview) {
  let popStartStatusBarStyle
  webview.addEventListener('popGesture', e => {
    if (e.type === 'start') {
      // 设置下一个页面的 statusBarStyle
      const pages = getCurrentPages()
      const page = pages[pages.length - 2]
      popStartStatusBarStyle = lastStatusBarStyle
      const statusBarStyle = page && page.$page.meta.statusBarStyle
      statusBarStyle && setStatusBarStyle(statusBarStyle)
    } else if (e.type === 'end' && !e.result) {
      // 拖拽未完成,设置为当前状态栏前景色
      setStatusBarStyle(popStartStatusBarStyle)
    } else if (e.type === 'end' && e.result) {
      const pages = getCurrentPages()
      const len = pages.length
      const page = pages[pages.length - 1]
      page && page.$remove()
      setStatusBarStyle()
      // 仅当存在一个页面,且是直达页面时,才 reLaunch 首页
      if (page && len === 1 && isDirectPage(page)) {
        reLaunchEntryPage()
      } else {
        UniServiceJSBridge.emit('onAppRoute', {
          type: 'navigateBack'
        })
      }
    }
  })
}
 
/**
 * 是否处于直达页面
 * @param page
 * @returns
 */
function isDirectPage (page) {
  return (
    __uniConfig.realEntryPagePath &&
    page.$page.route === __uniConfig.entryPagePath
  )
}
/**
 * 重新启动到首页
 */
function reLaunchEntryPage () {
  __uniConfig.entryPagePath = __uniConfig.realEntryPagePath
  delete __uniConfig.realEntryPagePath
  uni.reLaunch({
    url: addLeadingSlash(__uniConfig.entryPagePath)
  })
}
 
function hasLeadingSlash (str) {
  return str.indexOf('/') === 0
}
 
function addLeadingSlash (str) {
  return hasLeadingSlash(str) ? str : '/' + str
}