navigation-bar.js 1.6 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3
function setNavigationBar (type, args) {
  const pages = getCurrentPages()
  if (pages.length) {
fxy060608's avatar
fxy060608 已提交
4
    const page = pages[pages.length - 1].$holder
fxy060608's avatar
fxy060608 已提交
5 6 7 8 9 10

    switch (type) {
      case 'setNavigationBarColor':
        const {
          frontColor,
          backgroundColor,
fxy060608's avatar
fxy060608 已提交
11 12 13 14 15 16 17
          animation
        } = args

        const {
          duration,
          timingFunc
        } = animation
fxy060608's avatar
fxy060608 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

        if (frontColor) {
          page.navigationBar.textColor = frontColor === '#000000' ? 'black' : 'white'
        }
        if (backgroundColor) {
          page.navigationBar.backgroundColor = backgroundColor
        }
        page.navigationBar.duration = duration + 'ms'
        page.navigationBar.timingFunc = timingFunc
        break
      case 'showNavigationBarLoading':
        page.navigationBar.loading = true
        break
      case 'hideNavigationBarLoading':
        page.navigationBar.loading = false
        break
      case 'setNavigationBarTitle':
        const {
          title
        } = args
        page.navigationBar.titleText = title
39 40 41
        if (__PLATFORM__ === 'h5') {
          document.title = title
        }
fxy060608's avatar
fxy060608 已提交
42 43 44 45
        break
    }
  }
  return {}
fxy060608's avatar
fxy060608 已提交
46 47
}

fxy060608's avatar
fxy060608 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61
export function setNavigationBarColor (args) {
  return setNavigationBar('setNavigationBarColor', args)
}

export function showNavigationBarLoading () {
  return setNavigationBar('showNavigationBarLoading')
}

export function hideNavigationBarLoading () {
  return setNavigationBar('hideNavigationBarLoading')
}

export function setNavigationBarTitle (args) {
  return setNavigationBar('setNavigationBarTitle', args)
62
}