<template>
  <div class="homepage">
    <!-- <BackToHomeButton /> -->
    <!-- 顶部主图背景 -->
    <!-- <div class="main-icon"></div> -->

    <img class="main-icon" :src="robot" alt="AI小财神" />
    <!-- 按钮区域 -->
    <div class="buttons-container">
      <!-- 夺宝奇兵模块 -->
      <div class="btn-item" @click="goToDBQBmodel">
        <div class="btn-icon btn-dbqb"></div>
        <div class="btn-ball"></div>
        <div class="btn-text btn-text-dbqb"></div>
      </div>

      <!-- AI情绪模块 -->
      <div class="btn-item" @click="goToEmotionsmodel">
        <div class="btn-icon btn-ai"></div>
        <div class="btn-ball"></div>
        <div class="btn-text btn-text-ai"></div>
      </div>
    </div>

    <!-- 底部口号与说明 -->
    <div class="footer-wrapper">
      <div class="footer-text1"></div>
      <div class="footer-text2"></div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { setHeight } from "@/utils/setHeight";
import { useDataStore } from "@/store/dataList.js";
const { getQueryVariable, setActiveTabIndex, getUserInfo } = useDataStore();
import robot from "@/assets/img/Selectmodel/机器人 拷贝.png";
import BackToHomeButton from "@/views/components/BackToHomeButton.vue";
import { useAppBridge } from "@/assets/js/useAppBridge.js";
const router = useRouter();
const pageRef = ref(null);

onMounted(() => {
  // setHeight(pageRef.value)
  const isPhone =
    /phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone/i.test(
      navigator.userAgent
    );

    !isPhone &&
    localStorage.setItem(
      "localToken",
      decodeURIComponent(String(getQueryVariable("token")))
    );
  fnGetToken()
  // localStorage.setItem(
  //   "localToken",
  //   "pCtw6AYK0EHAaIexoFHsbZjtsfEAIhcmwkCFm6uKko8VPfMvyDiODL9v9c0veic9fIpQbvT8zN4sH/Si6Q"
  // );

  getUserInfo();
});

// 获取token的核心函数
const fnGetToken = () => {
  console.log('进入fnGetToken')
  window.JWready = (ress) => {
    console.log('进入JWready')
    try {
      ress = JSON.parse(ress);
      // console.log(ress, 'ress')
    } catch (error) {
      console.log(error, "fnGetToken error");
    } //platform为5是app端
    // platform.value = ress.data.platform
    // 处理平台判断
    console.log(ress.data.platform, "ress.data.platform");
    if (!ress.data.platform) {
      // 非App环境通过URL参数获取
      localStorage.setItem(
        "localToken",
        decodeURIComponent(String(getQueryVariable("token")))
      );
      // localStorage.setItem('localToken', "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w")
    } else {
      // App环境通过桥接获取
      useAppBridge().packageFun(
        "JWgetStorage",
        (response) => {
          const res = JSON.parse(response); // 解析返回的结果
          localStorage.setItem("localToken", res.data);
          // localStorage.setItem('localToken', "+SsksARQgUHIbIG3rRnnbZi0+fEeMx8pywnIlrmTxo5EOPR/wjWDV7w7+ZUseiBtf9kFa/atmNx6QfSpv5w")
        },
        5,
        {
          key: "token",
        }
      );
    }
  };
  // console.log('出来了')
  // 触发App桥接
  useAppBridge().packageFun("JWwebReady", () => {}, 5, {});
};

const goToDBQBmodel = () => {
  router.push("/DBQBmodel");
};
const goToEmotionsmodel = () => {
  router.push("/Emotionsmodel");
};
</script>

<style scoped>
.homepage {
  background-image: url("@/assets/img/Selectmodel/bg.png");
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  width: 100vw;
  height: 100vh;
  /* min-height: 100vh; */
  /* overflow-x: hidden; */
  display: flex;
  flex-direction: column;
  align-items: center;
  /* box-sizing: border-box;
  text-align: center; */
  background-attachment: fixed;
}

.main-icon {
  max-width: 350px;
  width: 28vw;
  /* max-width: 280px; */
  height: auto;
  position: absolute;
  top: 20vh;
}

/* ===== 默认（PC端）按钮区域 ===== */
.buttons-container {
  margin-top: 8vh;
  display: flex;
  gap: 30vw;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: nowrap;
  position: absolute;
  top: 40vh;
}

.btn-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 90vw;
  max-width: 200px;
  cursor: pointer;
  animation: breathing 1.5s ease-in-out infinite;
}

/* 呼吸动效关键帧 */
@keyframes breathing {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}

.btn-icon {
  /* height: 80px;
  width: 100%; */
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.btn-dbqb {
  height: 150px;
  width: 100%;
  background-image: url("@/assets/img/Selectmodel/-s-夺宝奇兵logo.png");
}

.btn-ai {
  height: 150px;
  width: 100%;
  background-image: url("@/assets/img/Selectmodel/金轮 拷贝.png");
  z-index: 3;
}

.btn-ball {
  height: 150px;
  width: 150%;
  margin-top: -30px;
  background-image: url("@/assets/img/Selectmodel/球.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  position: relative;
}

.btn-text {
  height: 200px;
  width: 150%;
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.btn-text-dbqb {
  background-image: url("@/assets/img/Selectmodel/-s-夺宝奇兵大模型.png");
}

.btn-text-ai {
  background-image: url("@/assets/img/Selectmodel/-s-AI情绪大模型.png");
}

/* ===== 底部口号区域 ===== */
.footer-wrapper {
  /* margin-top: 6vh; */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5vh;
  position: absolute;
  bottom: 20px;
}

.footer-text1 {
  /* width: 200vw; */
  /* max-width: 200vw; */
  height: 6vw;
  background-image: url("@/assets/img/Selectmodel/智能体 拷贝.png");
  background-size: 100% 100%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  width: 100vw;
}

.footer-text2 {
  width: 70vw;
  max-width: 360px;
  height: 30px;
  /* margin-bottom: 60px; */
  background-image: url("@/assets/img/Selectmodel/-s-弘历团队.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

/* 手机适配 */
@media screen and (max-width: 768px) {
  .homepage {
    background-image: url("@/assets/img/Selectmodel/手机bg.png");
    /* height: auto; */
    /* 解决底部留白 */
    /* width: 100%; */
    min-height: 100%;
    background-size: 100% 100%;
    overflow-x: hidden;
  }

  .main-icon {
    background-image: url("@/assets/img/Selectmodel/机器人手机.png");
    width: 70%;
    height: auto;
    background-repeat: no-repeat;
    background-size: 100% 100%;
  }

  .buttons-container {
    margin-top: 8rem;
    gap: 10vw;
    position: relative;
    flex-wrap: nowrap;
  }

  .btn-item {
    width: 40vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding-bottom: 20px;
  }

  .btn-icon {
    height: 80px;
    margin-bottom: -10px;
  }

  .btn-ball {
    height: 80px;
    margin-top: -10px;
    position: relative;
    z-index: 1;
  }

  .btn-text {
    position: absolute;
    bottom: 45px;
    width: 90%;
    height: 40px;
    z-index: 2;
  }

  .footer-text1 {
    background-image: url("@/assets/img/Selectmodel/智能体.png");
    width: 100vw;
    height: 60px;
    margin-top: 10px;
    background-size: 100% 100%;
    /* 保证全宽显示 */
  }

  .footer-text2 {
    width: 70vw;
    height: 24px;
    margin-top: 10px;
  }
}

/* 平板适配 */
/* @media screen and (min-width: 769px) and (max-width: 1024px) {
  .homepage {
    background-image: url("@/assets/img/Selectmodel/手机bg.png");
  }


  .btn-item {
    padding-top: 20px;
    width: 300vw;
    position: relative;
  }

  .buttons-container {
    gap: 30vw;
    margin-top: 5vh;
  }

  .btn-icon,
  .btn-ball {
    height: 100px;
    width: 300px;
  }

  .btn-text {
    height: 90px;
    width: 100%;
    top: 70%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
} */
</style>