<template>
    <van-nav-bar fixed :border="false" placeholder :title="pageTitle" left-text="返回" left-arrow
        @click-left="onClickLeft" />
    <router-view />
</template>

<script setup>
import { ref, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()
const pageTitle = ref('') // 用来保存页面标题
const onClickLeft = () => {
    if (route.name === 'report') {
        router.replace('/historyQuery')
    } else if (route.name === 'history') {
        router.replace('/')
    } else {
        router.back()
    }
}
onMounted(() => {
})
// 监听路由变化并更新标题
watch(
    () => route.meta.title,
    (newTitle) => {
        pageTitle.value = newTitle || '默认标题'
    },
    { immediate: true }
)
</script>

<style lang="scss" scoped></style>