tab-bar.js 1.8 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4
import {
  isTabBarPage
} from '../util'

fxy060608's avatar
fxy060608 已提交
5
import tabBar from '../../framework/tab-bar'
fxy060608's avatar
fxy060608 已提交
6 7 8 9

export function setTabBarBadge ({
  index,
  text,
Q
qiang 已提交
10
  type = 'text'
fxy060608's avatar
fxy060608 已提交
11
}) {
fxy060608's avatar
fxy060608 已提交
12
  tabBar.setTabBarBadge(type, index, text)
fxy060608's avatar
fxy060608 已提交
13 14 15 16 17 18 19 20 21
  return {
    errMsg: 'setTabBarBadge:ok'
  }
}

export function setTabBarItem ({
  index,
  text,
  iconPath,
22 23
  selectedIconPath,
  pagePath
fxy060608's avatar
fxy060608 已提交
24
}) {
25 26 27 28 29 30 31 32 33 34
  tabBar.setTabBarItem(index, text, iconPath, selectedIconPath)
  const route = pagePath && __uniRoutes.find(({ path }) => path === pagePath)
  if (route) {
    const meta = route.meta
    meta.isTabBar = true
    meta.tabBarIndex = index
    meta.isQuit = true
    const tabBar = __uniConfig.tabBar
    if (tabBar && tabBar.list && tabBar.list[index]) {
      tabBar.list[index].pagePath = pagePath.startsWith('/') ? pagePath.substring(1) : pagePath
fxy060608's avatar
fxy060608 已提交
35 36 37 38 39 40 41
    }
  }
  return {
    errMsg: 'setTabBarItem:ok'
  }
}

42
export function setTabBarStyle (style = {}) {
fxy060608's avatar
fxy060608 已提交
43 44 45 46 47
  if (!isTabBarPage()) {
    return {
      errMsg: 'setTabBarStyle:fail not TabBar page'
    }
  }
48 49 50 51
  const borderStyles = {
    black: 'rgba(0,0,0,0.4)',
    white: 'rgba(255,255,255,0.4)'
  }
52
  const borderStyle = style.borderStyle
53
  if (borderStyle in borderStyles) {
54
    style.borderStyle = borderStyles[borderStyle]
55 56
  }
  tabBar.setTabBarStyle(style)
fxy060608's avatar
fxy060608 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69
  return {
    errMsg: 'setTabBarStyle:ok'
  }
}

export function hideTabBar ({
  animation
}) {
  if (!isTabBarPage()) {
    return {
      errMsg: 'hideTabBar:fail not TabBar page'
    }
  }
fxy060608's avatar
fxy060608 已提交
70
  tabBar.hideTabBar(animation)
fxy060608's avatar
fxy060608 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83
  return {
    errMsg: 'hideTabBar:ok'
  }
}

export function showTabBar ({
  animation
}) {
  if (!isTabBarPage()) {
    return {
      errMsg: 'showTabBar:fail not TabBar page'
    }
  }
fxy060608's avatar
fxy060608 已提交
84
  tabBar.showTabBar(animation)
fxy060608's avatar
fxy060608 已提交
85 86 87
  return {
    errMsg: 'showTabBar:ok'
  }
88
}