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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {
  getWebview
} from '../util'
 
export function setNavigationBarTitle ({
  __page__,
  title = ''
} = {}) {
  const webview = getWebview(__page__)
  if (webview) {
    const style = webview.getStyle()
    if (style && style.titleNView) {
      webview.setStyle({
        titleNView: {
          titleText: title
        }
      })
    }
    return {
      errMsg: 'setNavigationBarTitle:ok'
    }
  }
  return {
    errMsg: 'setNavigationBarTitle:fail'
  }
}
 
export function showNavigationBarLoading () {
  plus.nativeUI.showWaiting('', {
    modal: false
  })
  return {
    errMsg: 'showNavigationBarLoading:ok'
  }
}
 
export function hideNavigationBarLoading () {
  plus.nativeUI.closeWaiting()
  return {
    errMsg: 'hideNavigationBarLoading:ok'
  }
}
 
function setPageMeta (statusBarStyle) {
  const pages = getCurrentPages()
  if (!pages.length) {
    return
  }
  // 框架内部页面跳转会从这里获取style配置
  pages[pages.length - 1].$page.meta.statusBarStyle = statusBarStyle
}
 
export function setNavigationBarColor ({
  __page__,
  frontColor,
  backgroundColor
} = {}) {
  const webview = getWebview(__page__)
  if (webview) {
    const styles = {}
    if (frontColor) {
      styles.titleColor = frontColor
    }
    if (backgroundColor) {
      styles.backgroundColor = backgroundColor
    }
    const statusBarStyle = frontColor === '#000000' ? 'dark' : 'light'
    plus.navigator.setStatusBarStyle(statusBarStyle)
 
    // 用户调用api时同时改变当前页配置,这样在系统调用设置时,可以避免覆盖用户设置
    setPageMeta(statusBarStyle)
 
    const style = webview.getStyle()
    if (style && style.titleNView) {
      if (style.titleNView.autoBackButton) {
        styles.backButton = styles.backButton || {}
        styles.backButton.color = frontColor
      }
      webview.setStyle({
        titleNView: styles
      })
    }
    return {
      errMsg: 'setNavigationBarColor:ok'
    }
  }
  return {
    errMsg: 'setNavigationBarColor:fail'
  }
}