diff --git a/src/core/helpers/protocol/tab-bar.js b/src/core/helpers/protocol/tab-bar.js index 77da45a763b96e4b1f264e3d9a810f2b243651b9..0573d60395e08d0508ce89cabe16db7b26f5889e 100644 --- a/src/core/helpers/protocol/tab-bar.js +++ b/src/core/helpers/protocol/tab-bar.js @@ -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, diff --git a/src/core/service/api/tab-bar.js b/src/core/service/api/tab-bar.js index 202328ecd1ad249793b7804a1bcea9629c5333d3..88446f052f9357ebb9abe11f64c9b56395cb4234 100644 --- a/src/core/service/api/tab-bar.js +++ b/src/core/service/api/tab-bar.js @@ -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) -} +}