Skip to content

Commit

Permalink
feat: get tabBarList
Browse files Browse the repository at this point in the history
flippedround committed Jun 13, 2024
1 parent b73993c commit a6e8ab0
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/stores/pages.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ export const usePagesState = createGlobalState(
const response = await fetch('/api/getPages')
pagesState.value = await response.json()
}
return pagesState
return pagesState.value
}

return {
4 changes: 2 additions & 2 deletions packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ export default function UniDevToolsPlugin(options: Partial<Options>): Plugin[] {
const port = options?.port || 5015
const inspect = loadInspectPlugin()
const app = createDevtoolServe(port)
const [pages, pagesPath] = getPagesInfo(options?.pageJsonPath)
const [pagesPath, pages, tabBarList] = getPagesInfo(options?.pageJsonPath)
const rootPath = pagesPath.replace('pages.json', '')

const plugin = <Plugin>{
@@ -52,7 +52,7 @@ export default function UniDevToolsPlugin(options: Partial<Options>): Plugin[] {
* 获取pages.json文件数据接口
*/
app.get('/api/getPages', (req, res) => {
res.end(JSON.stringify(pages))
res.end(JSON.stringify({ pages, tabBarList }))
})
},
transform(src, id) {
9 changes: 6 additions & 3 deletions packages/plugin/src/logic/getPages.ts
Original file line number Diff line number Diff line change
@@ -18,13 +18,16 @@ export function getPagesPath(pagesPath?: string) {
}

/** 获取pages.json文件数据 */
export function getPagesInfo(pagesPath?: string): [PagesJson['pages'], string] {
export function getPagesInfo(pagesPath?: string) {
const path = getPagesPath(pagesPath)
const pagesJson = JSON5.parse<PagesJson>(readFileSync(path, 'utf-8'))

const pages = pagesJson.pages
const tabBarList = pagesJson.tabBar?.list.map(item => item.pagePath)

return [
pages,
path,
]
pages,
tabBarList,
] as const
}
10 changes: 10 additions & 0 deletions packages/plugin/src/types.ts
Original file line number Diff line number Diff line change
@@ -9,8 +9,18 @@ export interface Pages {
type: string
}

export interface TabBarList {
pagePath: string
iconPath: string
selectedIconPath: string
text?: string
}

export interface PagesJson {
pages: Pages[]
tabBar?: {
list: TabBarList[]
}
}

export interface Options {

0 comments on commit a6e8ab0

Please sign in to comment.