<template>
  <div class="page-main">
    <router-view></router-view>
  </div>
  <van-tabbar v-model="tabActive" active-color="#4fb5f9" inactive-color="#333">
    <van-tabbar-item name="home" replace to="/home" icon="wap-home-o">首页</van-tabbar-item>
    <van-tabbar-item name="automate" replace to="/automate" icon="star-o">自动化</van-tabbar-item>
  </van-tabbar>
  <van-number-keyboard safe-area-inset-bottom />
</template>

<script setup lang="ts">
const route = useRoute()

const tabActive = ref('home')
watch(
  () => route.path,
  () => {
    tabActive.value = route.path === '/home' || route.path === '/' ? 'home' : 'automate'
  },
  { immediate: true }
)

// const initWX = async () => {
//   const res = await fetch('/api/test/gettoken', {
//     method: 'POST',
//     body: JSON.stringify({ fd: 2 })
//   }).then((res) => res.json())
//   console.log(res)

//   let fd = {
//     token: sessionStorage.getItem('token'),
//     url: window.location.origin + window.location.pathname + window.location.search,
//     href: window.location.href
//   }
//   const res1 = await fetch('/api/user/getjsconfig', {
//     method: 'POST',
//     body: JSON.stringify(fd)
//   }).then((res) => res.json())

//   wx.config({
//   debug: false, // 调试模式，建议开发时开启
//   appId: '公众号的AppID',
//   timestamp: '生成签名的时间戳',
//   nonceStr: '生成签名的随机串',
//   signature: '后端生成的签名',
//   jsApiList: [], // 需要使用的JS接口，开放标签不需要填写
//   openTagList: ['wx-open-launch-weapp'] // 声明使用的开放标签
// });
// }
// initWX()
</script>

<style scoped>
.page-main {
  height: calc(100% - 50px);
  overflow: auto;
}
</style>
