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

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

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