<script setup>
const webviewStyles = ref({
  top: `${uni.getSystemInfoSync().statusBarHeight + 44}px`, // 距离顶部的距离
  height: `${uni.getSystemInfoSync().windowHeight - uni.getSystemInfoSync().statusBarHeight - 44}px`, // 高度
  position: 'absolute', // 绝对定位
  dock: 'bottom', // 停靠在底部
  bounce: 'vertical', // 垂直方向的回弹效果
})

// 从环境变量获取基础URL
const BASE_URL = import.meta.env.VITE_APP_BASE_URL || 'https://www.quannengcha.com'

// 协议路径和标题的映射
const agreementMap = {
  user: {
    path: '/app/userAgreement',
    title: '用户协议'
  },
  privacy: {
    path: '/app/privacyPolicy',
    title: '隐私政策'
  },
  authorization: {
    path: '/app/authorization',
    title: '授权书'
  },
  service: {
    path: '/app/agentSerivceAgreement',
    title: '信息技术服务合同'
  },
  manage: {
    path: '/app/agentManageAgreement',
    title: '推广方管理制度协议'
  }
}

const agreementUrl = ref('')
const pageTitle = ref('协议')

// 使用 uniapp 的 onLoad 生命周期钩子获取页面参数
onLoad((option) => {
  const type = option.type || 'user'
  if (agreementMap[type]) {
    agreementUrl.value = `${BASE_URL}${agreementMap[type].path}`
    pageTitle.value = agreementMap[type].title

    // 设置标题 - 此标题会传递给 page 布局中的 wd-navbar
    uni.setNavigationBarTitle({
      title: pageTitle.value
    })
  }
})
function handleClickLeft() {
  uni.navigateBack()
}
</script>

<template>
  <view>
    <wd-navbar :title="pageTitle" left-text="返回" placeholder left-arrow safe-area-inset-top fixed @click-left="handleClickLeft" />
    <web-view :webview-styles="webviewStyles" :src="agreementUrl" />
  </view>
</template>
