Vmenu.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <ul class="menu">
  3. <li @click="onClickItem(item)" v-for="item in list" :key="item.id">
  4. <img
  5. :src="`${config.cdn_url}images/${
  6. routeName == item.id ? item.active : item.normal
  7. }.png`"
  8. alt=""
  9. />
  10. </li>
  11. </ul>
  12. </template>
  13. <script setup>
  14. import { reactive, computed } from "vue";
  15. import { useRoute, useRouter } from "vue-router";
  16. const route = useRoute();
  17. const router = useRouter();
  18. const emit = defineEmits(["clickIntro"]);
  19. const routeName = computed(() => route.name);
  20. const list = reactive([
  21. {
  22. id: "Introduce",
  23. name: "文物介绍",
  24. normal: "icon_introduction_normal",
  25. active: "icon_introduction_active",
  26. },
  27. {
  28. id: "Courtyard",
  29. name: "我的庭院",
  30. normal: "icon_mine_normal",
  31. active: "icon_mine_active",
  32. },
  33. {
  34. id: "Integral",
  35. name: "到处逛逛",
  36. normal: "icon_hangout_normal",
  37. active: "icon_hangout_active",
  38. },
  39. ]);
  40. let ifrDom = document.querySelector("#ifr");
  41. const postMsg = (source, data) => {
  42. ifrDom.contentWindow.postMessage(
  43. {
  44. source,
  45. data,
  46. },
  47. "*"
  48. );
  49. };
  50. const onClickItem = (item) => {
  51. if (item.id == "Introduce") {
  52. emit("clickIntro");
  53. } else {
  54. // 每次点击我的庄园 拿到自己的模型数据
  55. if (item.id === "Courtyard") {
  56. const userInfo = JSON.parse(
  57. localStorage.getItem("HN_GAME_USER_INFO") || "{}"
  58. );
  59. postMsg("ShowUserData", userInfo.id);
  60. }
  61. router.push({ name: item.id });
  62. }
  63. };
  64. </script>
  65. <style lang="scss" scoped>
  66. .menu {
  67. position: absolute;
  68. right: 20px;
  69. top: 2%;
  70. z-index: 9;
  71. display: flex;
  72. flex-direction: column;
  73. width: 10%;
  74. > li {
  75. width: 100%;
  76. margin: 2px 0;
  77. > img {
  78. width: 100%;
  79. }
  80. }
  81. }
  82. </style>