123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- import { pages, subPackages, tabBar } from '@/pages.json'
- import { path } from 'node:path'
- const getLastPage = () => {
-
-
-
- const pages = getCurrentPages()
- return pages[pages.length - 1]
- }
- export const getIsTabbar = () => {
- if (!tabBar) {
- return false
- }
- if (!tabBar.list.length) {
-
- return false
- }
- const lastPage = getLastPage()
- const currPath = lastPage.route
- return !!tabBar.list.find((e) => e.pagePath === currPath)
- }
- export const currRoute = () => {
- const lastPage = getLastPage()
- const currRoute = (lastPage as any).$page
-
-
-
-
-
- let path = ''
-
- const { fullPath } = currRoute as { fullPath: string }
- path = fullPath
-
-
- path = lastPage.route
-
-
-
-
- return getUrlObj(path)
- }
- const ensureDecodeURIComponent = (url: string) => {
- if (url.startsWith('%')) {
- return ensureDecodeURIComponent(decodeURIComponent(url))
- }
- return url
- }
- export const getUrlObj = (url: string) => {
- const [path, queryStr] = url.split('?')
-
- if (!queryStr) {
- return {
- path,
- query: {},
- }
- }
- const query: Record<string, string> = {}
- queryStr.split('&').forEach((item) => {
- const [key, value] = item.split('=')
-
- query[key] = ensureDecodeURIComponent(value)
- })
- return { path, query }
- }
- export const getAllPages = (key = 'needLogin') => {
-
- const mainPages = [
- ...pages
- .filter((page) => !key || page[key])
- .map((page) => ({
- ...page,
- path: `/${page.path}`,
- })),
- ]
-
- const subPages: any[] = []
- subPackages.forEach((subPageObj) => {
-
- const { root } = subPageObj
- subPageObj.pages
- .filter((page) => !key || page[key])
- .forEach((page: { path: string } & Record<string, any>) => {
- subPages.push({
- ...page,
- path: `/${root}/${page.path}`,
- })
- })
- })
- const result = [...mainPages, ...subPages]
-
- return result
- }
- export const getNeedLoginPages = (): string[] => getAllPages('needLogin').map((page) => page.path)
- export const needLoginPages: string[] = getAllPages('needLogin').map((page) => page.path)
|