@liujitcn/kratos-uni-app-core 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/navigation.ts +47 -9
package/package.json
CHANGED
package/src/navigation.ts
CHANGED
|
@@ -140,6 +140,8 @@ let adapter: AppNavigationAdapter = {
|
|
|
140
140
|
list: () => defBaseMenuService.ListBaseMenu(),
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
const nativeTabViewKeys = ['HOME', 'PROFILE_HOME']
|
|
144
|
+
|
|
143
145
|
/** 替换导航远端适配器,供宿主接入自定义契约。 */
|
|
144
146
|
export function setAppNavigationAdapter(nextAdapter: AppNavigationAdapter): void {
|
|
145
147
|
adapter = nextAdapter
|
|
@@ -209,29 +211,65 @@ export function navigateAppRoute(rawRoute: string, options: { replace?: boolean
|
|
|
209
211
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
210
212
|
.join('&')
|
|
211
213
|
const url = `/${resolved.physicalRoute}${query ? `?${query}` : ''}`
|
|
212
|
-
if (resolved.menu.inTabBar) {
|
|
213
|
-
navigateTabRoute(url)
|
|
214
|
-
return
|
|
215
|
-
}
|
|
216
214
|
if (options.replace) {
|
|
217
215
|
uni.reLaunch({ url })
|
|
218
216
|
return
|
|
219
217
|
}
|
|
218
|
+
if (resolved.menu.inTabBar) {
|
|
219
|
+
navigateTabRoute(url)
|
|
220
|
+
return
|
|
221
|
+
}
|
|
220
222
|
uni.navigateTo({ url, fail: () => uni.reLaunch({ url }) })
|
|
221
223
|
}
|
|
222
224
|
|
|
223
|
-
/** 切换 tab
|
|
225
|
+
/** 切换 tab 页面,优先复用已有页面,避免重建页面栈产生空白帧。 */
|
|
224
226
|
function navigateTabRoute(url: string): void {
|
|
225
|
-
const targetRoute = url.slice(1).split('?', 1)[0]
|
|
227
|
+
const targetRoute = url.slice(1).split('?', 1)[0].replace(/^\/+/, '')
|
|
226
228
|
const pages = getCurrentPages()
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
+
const currentIndex = pages.length - 1
|
|
230
|
+
const currentRoute = pages[currentIndex]?.route?.replace(/^\/+/, '')
|
|
231
|
+
if (currentRoute === targetRoute || tabNavigationTarget) return
|
|
229
232
|
|
|
230
233
|
tabNavigationTarget = targetRoute
|
|
231
234
|
const release = () => {
|
|
232
235
|
if (tabNavigationTarget === targetRoute) tabNavigationTarget = undefined
|
|
233
236
|
}
|
|
234
|
-
|
|
237
|
+
if (nativeTabViewKeys.some((viewKey) => resolveStaticView(viewKey) === targetRoute)) {
|
|
238
|
+
uni.switchTab({
|
|
239
|
+
url,
|
|
240
|
+
success: release,
|
|
241
|
+
fail: () => navigateTabRouteInStack(url, targetRoute, pages, currentIndex, release),
|
|
242
|
+
})
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
navigateTabRouteInStack(url, targetRoute, pages, currentIndex, release)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** 在没有原生 tab 路由的动态菜单上复用页面栈。 */
|
|
249
|
+
function navigateTabRouteInStack(
|
|
250
|
+
url: string,
|
|
251
|
+
targetRoute: string,
|
|
252
|
+
pages: ReturnType<typeof getCurrentPages>,
|
|
253
|
+
currentIndex: number,
|
|
254
|
+
release: () => void,
|
|
255
|
+
): void {
|
|
256
|
+
const targetIndex = pages.findIndex((page) => page.route?.replace(/^\/+/, '') === targetRoute)
|
|
257
|
+
if (targetIndex >= 0 && targetIndex < currentIndex) {
|
|
258
|
+
uni.navigateBack({
|
|
259
|
+
delta: currentIndex - targetIndex,
|
|
260
|
+
success: release,
|
|
261
|
+
fail: release,
|
|
262
|
+
complete: release,
|
|
263
|
+
})
|
|
264
|
+
return
|
|
265
|
+
}
|
|
266
|
+
uni.navigateTo({
|
|
267
|
+
url,
|
|
268
|
+
success: release,
|
|
269
|
+
fail: () => {
|
|
270
|
+
uni.reLaunch({ url, success: release, fail: release, complete: release })
|
|
271
|
+
},
|
|
272
|
+
})
|
|
235
273
|
}
|
|
236
274
|
|
|
237
275
|
/** 获取导航响应式状态。 */
|