| | |
| | | * @param {object} pagesJson |
| | | * @returns [{"path": "/pages/tab/home/index","needLogin": false},...] |
| | | */ |
| | | function parseRoutes(pagesJson = {}) { |
| | | function parseRoutes (pagesJson = {}) { |
| | | if (!pagesJson.pages) { |
| | | pagesJson.pages = [] |
| | | } |
| | |
| | | pagesJson.subPackages = [] |
| | | } |
| | | |
| | | function parsePages(pages = [], rootPath = "") { |
| | | function parsePages (pages = [], rootPath = "") { |
| | | const routes = [] |
| | | for (let i = 0; i < pages.length; i++) { |
| | | routes.push({ |
| | |
| | | return routes |
| | | } |
| | | |
| | | function parseSubPackages(subPackages = []) { |
| | | function parseSubPackages (subPackages = []) { |
| | | const routes = [] |
| | | for (let i = 0; i < subPackages.length; i++) { |
| | | routes.push(...parsePages(subPackages[i].pages, subPackages[i].root)) |
| | |
| | | * 当前路由 |
| | | * @returns {string} 当前路由 |
| | | */ |
| | | export function currentRoute() { |
| | | export function currentRoute () { |
| | | // getCurrentPages() 至少有1个元素,所以不再额外判断 |
| | | const pages = getCurrentPages() |
| | | const currentPage = pages[pages.length - 1] |
| | |
| | | * @param {string} path |
| | | * @returns {string} 去除查询字符串后的路径 |
| | | */ |
| | | export function removeQueryString(path = "") { |
| | | export function removeQueryString (path = "") { |
| | | return path.split("?")[0] |
| | | } |
| | | |
| | |
| | | * @param {string} path |
| | | * @returns {boolean} 路径是否存在 |
| | | */ |
| | | export function isPathExists(path = "") { |
| | | export function isPathExists (path = "") { |
| | | const cleanPath = removeQueryString(path) |
| | | return routes.some(item => item.path === cleanPath) |
| | | } |
| | |
| | | * @param {string} path |
| | | * @returns {boolean} 是否是tabbar页面 |
| | | */ |
| | | export function isTabBarPath(path = "") { |
| | | export function isTabBarPath (path = "") { |
| | | const cleanPath = removeQueryString(path) |
| | | return ( |
| | | pagesJson.tabBar?.list?.some(item => `/${item.pagePath}` === cleanPath) === |