提交 970d2999 编写于 作者: Q qiang

update: 调整 tabbar 相关接口参数校验

上级 8934a4d8
......@@ -2,33 +2,12 @@ import {
getLen
} from 'uni-shared'
function beforeValidate (params) {
let isTabBar = false
const pages = getCurrentPages()
if (pages.length) {
if (pages[pages.length - 1].$page.meta.isTabBar) {
isTabBar = true
}
} else if (getApp().$children[0].hasTabBar) {
isTabBar = true
}
if (!isTabBar) {
return 'not TabBar page'
}
}
const indexValidator = {
type: Number,
required: true,
validator (index, params) {
if (index >= __uniConfig.tabBar.list.length) {
return 'tabbar item not found'
}
}
required: true
}
export const setTabBarItem = {
beforeValidate,
index: indexValidator,
text: {
type: String
......@@ -42,7 +21,6 @@ export const setTabBarItem = {
}
export const setTabBarStyle = {
beforeValidate,
color: {
type: String
},
......@@ -63,7 +41,6 @@ export const setTabBarStyle = {
}
export const hideTabBar = {
beforeValidate,
animation: {
type: Boolean,
default: false
......@@ -71,7 +48,6 @@ export const hideTabBar = {
}
export const showTabBar = {
beforeValidate,
animation: {
type: Boolean,
default: false
......@@ -79,22 +55,18 @@ export const showTabBar = {
}
export const hideTabBarRedDot = {
beforeValidate,
index: indexValidator
}
export const showTabBarRedDot = {
beforeValidate,
index: indexValidator
}
export const removeTabBarBadge = {
beforeValidate,
index: indexValidator
}
export const setTabBarBadge = {
beforeValidate,
index: indexValidator,
text: {
type: String,
......
......@@ -10,11 +10,32 @@ const setTabBarBadgeProps = ['badge', 'redDot']
function setTabBar (type, args = {}) {
const app = getApp()
if (app) {
let isTabBar = false
const pages = getCurrentPages()
if (pages.length) {
if (pages[pages.length - 1].$page.meta.isTabBar) {
isTabBar = true
}
} else if (app.$children[0].hasTabBar) {
isTabBar = true
}
if (!isTabBar) {
return {
errMsg: `${type}:fail not TabBar page`
}
}
const {
index
} = args
const tabBar = app.$children[0].tabBar
if (index >= __uniConfig.tabBar.list.length) {
return {
errMsg: `${type}:fail tabbar item not found`
}
}
switch (type) {
case 'showTabBar':
app.$children[0].hideTabBar = false
......@@ -80,4 +101,4 @@ export function removeTabBarBadge (args) {
export function setTabBarBadge (args) {
return setTabBar('setTabBarBadge', args)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册