Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChenYFan_OHHH
uni-app
提交
eaffd476
U
uni-app
项目概览
ChenYFan_OHHH
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eaffd476
编写于
6月 14, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: setTabBarItem (#3592)
上级
f12baea3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
97 addition
and
67 deletion
+97
-67
packages/uni-app-plus/dist/uni.runtime.esm.js
packages/uni-app-plus/dist/uni.runtime.esm.js
+29
-14
packages/uni-app-plus/src/service/api/ui/tabBar.ts
packages/uni-app-plus/src/service/api/ui/tabBar.ts
+11
-12
packages/uni-core/src/helpers/route.ts
packages/uni-core/src/helpers/route.ts
+24
-1
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+27
-18
packages/uni-h5/src/service/api/ui/tabBar.ts
packages/uni-h5/src/service/api/ui/tabBar.ts
+6
-22
未找到文件。
packages/uni-app-plus/dist/uni.runtime.esm.js
浏览文件 @
eaffd476
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();
}
...
...
packages/uni-app-plus/src/service/api/ui/tabBar.ts
浏览文件 @
eaffd476
...
...
@@ -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
()
...
...
packages/uni-core/src/helpers/route.ts
浏览文件 @
eaffd476
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
)
}
}
}
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
eaffd476
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, re
solveOwnerVm, 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, re
moveLeadingSlash, 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:
...
...
packages/uni-h5/src/service/api/ui/tabBar.ts
浏览文件 @
eaffd476
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录