<script setup>
import pagesJson from '@/pages.json'

const pagesConfig = pagesJson.pages
const title = ref('')
function getPageTitle() {
  const pages = getCurrentPages()
  const currentPage = pages[pages.length - 1] // 当前页面
  const currentRoute = currentPage.route // 当前页面路径，例如 "pages/authorization"

  // 根据路径查找 pages.json 中的配置
  const currentPageConfig = pagesConfig.find(page => page.path === currentRoute)
  console.log('currentPageConfig', currentPageConfig)
  // 返回页面标题，如果未找到，则返回默认标题
  return currentPageConfig?.title || ''
}
onLoad(() => {
  title.value = getPageTitle()
})

function handleClickLeft() {
  uni.navigateBack()
}
</script>

<template>
  <wd-navbar :title="title" left-text="返回" placeholder left-arrow safe-area-inset-top fixed @click-left="handleClickLeft" />
  <view class="box-border min-h-screen">
    <slot />
  </view>
</template>

<style scoped>

</style>
