From 970d29994efd993371e9bf7c124397ac3ea7b151 Mon Sep 17 00:00:00 2001 From: qiang Date: Thu, 20 Jun 2019 18:59:01 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E8=B0=83=E6=95=B4=20tabbar=20?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E5=8F=82=E6=95=B0=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/helpers/protocol/tab-bar.js | 30 +--------------------------- src/core/service/api/tab-bar.js | 23 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/core/helpers/protocol/tab-bar.js b/src/core/helpers/protocol/tab-bar.js index 77da45a76..0573d6039 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 202328ecd..88446f052 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) -} +} -- GitLab