提交 eaffd476 编写于 作者: fxy060608's avatar fxy060608

fix: setTabBarItem (#3592)

上级 f12baea3
import { isArray as isArray$1, hasOwn as hasOwn$1, isString, isPlainObject, isObject as isObject$1, toRawType, capitalize, makeMap, isFunction, isPromise, extend, remove, toTypeString } from '@vue/shared';
import { LINEFEED, parseNVueDataset, once, I18N_JSON_DELIMITERS, Emitter, addLeadingSlash, resolveComponentInstance, invokeArrayFns, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, SCHEME_RE, DATA_RE, cacheStringFunction, parseQuery, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, removeLeadingSlash, getLen, formatLog, TABBAR_HEIGHT, NAVBAR_HEIGHT, sortObject, ON_THEME_CHANGE, ON_KEYBOARD_HEIGHT_CHANGE, BACKGROUND_COLOR, ON_NAVIGATION_BAR_BUTTON_TAP, stringifyQuery as stringifyQuery$1, debounce, ON_PULL_DOWN_REFRESH, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_BACK_PRESS, UniNode, NODE_TYPE_PAGE, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_INSERT, ACTION_TYPE_CREATE, ACTION_TYPE_REMOVE, ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ON_READY, ON_UNLOAD, EventChannel, ON_REACH_BOTTOM_DISTANCE, parseUrl, onCreateVueApp, ON_TAB_ITEM_TAP, ON_LAUNCH, ACTION_TYPE_EVENT, createUniEvent, ON_WXS_INVOKE_CALL_METHOD, WEB_INVOKE_APPSERVICE } from '@dcloudio/uni-shared';
import { LINEFEED, parseNVueDataset, once, I18N_JSON_DELIMITERS, Emitter, addLeadingSlash, resolveComponentInstance, invokeArrayFns, removeLeadingSlash, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, SCHEME_RE, DATA_RE, cacheStringFunction, parseQuery, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, getLen, formatLog, TABBAR_HEIGHT, NAVBAR_HEIGHT, sortObject, ON_THEME_CHANGE, ON_KEYBOARD_HEIGHT_CHANGE, BACKGROUND_COLOR, ON_NAVIGATION_BAR_BUTTON_TAP, stringifyQuery as stringifyQuery$1, debounce, ON_PULL_DOWN_REFRESH, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_BACK_PRESS, UniNode, NODE_TYPE_PAGE, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_INSERT, ACTION_TYPE_CREATE, ACTION_TYPE_REMOVE, ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ON_READY, ON_UNLOAD, EventChannel, ON_REACH_BOTTOM_DISTANCE, parseUrl, onCreateVueApp, ON_TAB_ITEM_TAP, ON_LAUNCH, ACTION_TYPE_EVENT, createUniEvent, ON_WXS_INVOKE_CALL_METHOD, WEB_INVOKE_APPSERVICE } from '@dcloudio/uni-shared';
import { ref, injectHook, createVNode, render, queuePostFlushCb, getCurrentInstance, onMounted, nextTick, onBeforeUnmount } from 'vue';
/*
......@@ -1634,6 +1634,24 @@ function getRouteMeta(path) {
if (routeOptions) {
return routeOptions.meta;
}
}
function normalizeTabBarRoute(index, oldPagePath, newPagePath) {
const oldTabBarRoute = getRouteOptions(addLeadingSlash(oldPagePath));
if (oldTabBarRoute) {
const { meta } = oldTabBarRoute;
delete meta.tabBarIndex;
meta.isQuit = meta.isTabBar = false;
}
const newTabBarRoute = getRouteOptions(addLeadingSlash(newPagePath));
if (newTabBarRoute) {
const { meta } = newTabBarRoute;
meta.tabBarIndex = index;
meta.isQuit = meta.isTabBar = true;
const tabBar = __uniConfig.tabBar;
if (tabBar && tabBar.list && tabBar.list[index]) {
tabBar.list[index].pagePath = removeLeadingSlash(newPagePath);
}
}
}
let plus_;
......@@ -16206,19 +16224,16 @@ const setTabBarBadge = defineAsyncApi(API_SET_TAB_BAR_BADGE, ({ index, text }, {
tabBarInstance.setTabBarBadge('text', index, text);
resolve();
}, SetTabBarBadgeProtocol, SetTabBarBadgeOptions);
const setTabBarItem = defineAsyncApi(API_SET_TAB_BAR_ITEM, ({ index, text, iconPath, selectedIconPath, pagePath, visible, iconfont }, { resolve, reject }) => {
const setTabBarItem = defineAsyncApi(API_SET_TAB_BAR_ITEM, ({ index, text, iconPath, selectedIconPath, pagePath, visible, iconfont }, { resolve }) => {
tabBarInstance.setTabBarItem(index, text, iconPath, selectedIconPath, visible, iconfont);
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] && pagePath) {
tabBar.list[index].pagePath = pagePath.startsWith('/')
? pagePath.substring(1)
: pagePath;
if (pagePath) {
const tabBarItem = __uniConfig.tabBar.list[index];
if (tabBarItem) {
const oldPagePath = tabBarItem.pagePath;
const newPagePath = removeLeadingSlash(pagePath);
if (newPagePath !== oldPagePath) {
normalizeTabBarRoute(index, oldPagePath, newPagePath);
}
}
}
resolve();
......@@ -18062,7 +18077,7 @@ const navigateBack = defineAsyncApi(API_NAVIGATE_BACK, (args, { resolve, reject
return reject(`getCurrentPages is empty`);
}
if (invokeHook(page, ON_BACK_PRESS, {
from: args.from,
from: args.from || 'navigateBack',
})) {
return resolve();
}
......
......@@ -33,6 +33,8 @@ import {
} from '@dcloudio/uni-api'
import { isTabBarPage } from '../../utils'
import tabBar from '../../framework/app/tabBar'
import { removeLeadingSlash } from '@dcloudio/uni-shared'
import { normalizeTabBarRoute } from '@dcloudio/uni-core'
export const setTabBarBadge = defineAsyncApi<API_TYPE_SET_TAB_BAR_BADGE>(
API_SET_TAB_BAR_BADGE,
......@@ -48,7 +50,7 @@ export const setTabBarItem = defineAsyncApi<API_TYPE_SET_TAB_BAR_ITEM>(
API_SET_TAB_BAR_ITEM,
(
{ index, text, iconPath, selectedIconPath, pagePath, visible, iconfont },
{ resolve, reject }
{ resolve }
) => {
tabBar.setTabBarItem(
index,
......@@ -58,17 +60,14 @@ export const setTabBarItem = defineAsyncApi<API_TYPE_SET_TAB_BAR_ITEM>(
visible,
iconfont
)
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] && pagePath) {
tabBar.list[index].pagePath = pagePath.startsWith('/')
? pagePath.substring(1)
: pagePath
if (pagePath) {
const tabBarItem = __uniConfig.tabBar!.list[index]
if (tabBarItem) {
const oldPagePath = tabBarItem.pagePath
const newPagePath = removeLeadingSlash(pagePath)
if (newPagePath !== oldPagePath) {
normalizeTabBarRoute(index, oldPagePath, newPagePath)
}
}
}
resolve()
......
import { addLeadingSlash } from '@dcloudio/uni-shared'
import { addLeadingSlash, removeLeadingSlash } from '@dcloudio/uni-shared'
export function normalizeRoute(toRoute: string) {
if (toRoute.indexOf('/') === 0) {
......@@ -47,3 +47,26 @@ export function getRouteMeta(path: string) {
return routeOptions.meta
}
}
export function normalizeTabBarRoute(
index: number,
oldPagePath: string,
newPagePath: string
) {
const oldTabBarRoute = getRouteOptions(addLeadingSlash(oldPagePath))
if (oldTabBarRoute) {
const { meta } = oldTabBarRoute
delete meta.tabBarIndex
meta.isQuit = meta.isTabBar = false
}
const newTabBarRoute = getRouteOptions(addLeadingSlash(newPagePath))
if (newTabBarRoute) {
const { meta } = newTabBarRoute
meta.tabBarIndex = index
meta.isQuit = meta.isTabBar = true
const tabBar = __uniConfig.tabBar
if (tabBar && tabBar.list && tabBar.list[index]) {
tabBar.list[index].pagePath = removeLeadingSlash(newPagePath)
}
}
}
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, h, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, isArray, remove, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, sortObject, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, removeLeadingSlash, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, getLen, debounce, ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, sortObject, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
export { onCreateVueApp } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
......@@ -1013,6 +1013,24 @@ function getRouteOptions(path, alias = false) {
}
return __uniRoutes.find((route) => route.path === path);
}
function normalizeTabBarRoute(index2, oldPagePath, newPagePath) {
const oldTabBarRoute = getRouteOptions(addLeadingSlash(oldPagePath));
if (oldTabBarRoute) {
const { meta } = oldTabBarRoute;
delete meta.tabBarIndex;
meta.isQuit = meta.isTabBar = false;
}
const newTabBarRoute = getRouteOptions(addLeadingSlash(newPagePath));
if (newTabBarRoute) {
const { meta } = newTabBarRoute;
meta.tabBarIndex = index2;
meta.isQuit = meta.isTabBar = true;
const tabBar2 = __uniConfig.tabBar;
if (tabBar2 && tabBar2.list && tabBar2.list[index2]) {
tabBar2.list[index2].pagePath = removeLeadingSlash(newPagePath);
}
}
}
class ComponentDescriptor {
constructor(vm) {
this.$bindClass = false;
......@@ -18706,7 +18724,9 @@ const chooseLocation = /* @__PURE__ */ defineAsyncApi(API_CHOOSE_LOCATION, (args
}, ChooseLocationProtocol);
const navigateBack = /* @__PURE__ */ defineAsyncApi(API_NAVIGATE_BACK, (args, { resolve, reject }) => {
let canBack = true;
if (invokeHook(ON_BACK_PRESS, { from: args.from }) === true) {
if (invokeHook(ON_BACK_PRESS, {
from: args.from || "navigateBack"
}) === true) {
canBack = false;
}
if (!canBack) {
......@@ -19389,20 +19409,6 @@ function setProperties(item, props2, propsData) {
}
});
}
function normalizeTabBarRoute(index2, oldPagePath, newPagePath) {
const oldTabBarRoute = getRouteOptions(addLeadingSlash(oldPagePath));
if (oldTabBarRoute) {
const { meta } = oldTabBarRoute;
delete meta.tabBarIndex;
meta.isQuit = meta.isTabBar = false;
}
const newTabBarRoute = getRouteOptions(addLeadingSlash(newPagePath));
if (newTabBarRoute) {
const { meta } = newTabBarRoute;
meta.tabBarIndex = index2;
meta.isQuit = meta.isTabBar = false;
}
}
function setTabBar(type, args, resolve) {
const tabBar2 = useTabBar();
switch (type) {
......@@ -19418,8 +19424,11 @@ function setTabBar(type, args, resolve) {
const oldPagePath = tabBarItem.pagePath;
setProperties(tabBarItem, setTabBarItemProps, args);
const { pagePath } = args;
if (pagePath && pagePath !== oldPagePath) {
normalizeTabBarRoute(index2, oldPagePath, pagePath);
if (pagePath) {
const newPagePath = addLeadingSlash(pagePath);
if (newPagePath !== oldPagePath) {
normalizeTabBarRoute(index2, oldPagePath, newPagePath);
}
}
break;
case API_SET_TAB_BAR_STYLE:
......
......@@ -32,7 +32,7 @@ import {
ShowTabBarRedDotOptions,
ShowTabBarRedDotProtocol,
} from '@dcloudio/uni-api'
import { getRouteOptions } from '@dcloudio/uni-core'
import { normalizeTabBarRoute } from '@dcloudio/uni-core'
import { addLeadingSlash } from '@dcloudio/uni-shared'
import { useTabBar } from '../../../framework/setup/state'
......@@ -63,25 +63,6 @@ function setProperties(
})
}
function normalizeTabBarRoute(
index: number,
oldPagePath: string,
newPagePath: string
) {
const oldTabBarRoute = getRouteOptions(addLeadingSlash(oldPagePath))
if (oldTabBarRoute) {
const { meta } = oldTabBarRoute
delete meta.tabBarIndex
meta.isQuit = meta.isTabBar = false
}
const newTabBarRoute = getRouteOptions(addLeadingSlash(newPagePath))
if (newTabBarRoute) {
const { meta } = newTabBarRoute
meta.tabBarIndex = index
meta.isQuit = meta.isTabBar = false
}
}
function setTabBar(
type: string,
args: Record<string, any>,
......@@ -101,8 +82,11 @@ function setTabBar(
const oldPagePath = tabBarItem.pagePath
setProperties(tabBarItem, setTabBarItemProps, args)
const { pagePath } = args
if (pagePath && pagePath !== oldPagePath) {
normalizeTabBarRoute(index, oldPagePath, pagePath)
if (pagePath) {
const newPagePath = addLeadingSlash(pagePath)
if (newPagePath !== oldPagePath) {
normalizeTabBarRoute(index, oldPagePath, newPagePath)
}
}
break
case API_SET_TAB_BAR_STYLE:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册