Просмотр исходного кода

refactor(utils): 重构页面路由相关工具函数

将 isCurrentPageTabbar 函数实现改为使用 currRoute 方法
新增 getCurrentPageI18nKey 函数用于获取当前页面国际化 key
feige996 9 месяцев назад
Родитель
Сommit
c69c350e0f
1 измененных файлов с 17 добавлено и 7 удалено
  1. 17 7
      src/utils/index.ts

+ 17 - 7
src/utils/index.ts

@@ -10,13 +10,6 @@ export function getLastPage() {
   return pages[pages.length - 1]
 }
 
-export function isCurrentPageTabbar() {
-  const lastPage = getLastPage()
-  const currRoute = (lastPage as any).$page
-  const { fullPath } = currRoute as { fullPath: string }
-  return tabbarList.some(item => `/${item.path}` === fullPath)
-}
-
 /**
  * 获取当前页面路由的 path 路径和 redirectPath 路径
  * path 如 '/pages/login/index'
@@ -100,6 +93,23 @@ export function getAllPages(key = 'needLogin') {
   return result
 }
 
+export function isCurrentPageTabbar() {
+  const routeObj = currRoute()
+  return tabbarList.some(item => `/${item.pagePath}` === routeObj.path)
+}
+
+export function getCurrentPageI18nKey() {
+  const routeObj = currRoute()
+  const currPage = pages.find(page => `/${page.path}` === routeObj.path)
+  if (!currPage) {
+    console.warn('路由不正确')
+    return ''
+  }
+  console.log(currPage)
+  console.log(currPage.style.navigationBarTitleText)
+  return currPage.style.navigationBarTitleText
+}
+
 /**
  * 得到所有的需要登录的 pages,包括主包和分包的
  * 只得到 path 数组