home.uvue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <script lang="ts" setup>
  2. import { computed, onMounted, ref } from 'vue'
  3. import { dict } from '@/.cool/store'
  4. import { router } from '@/.cool'
  5. import { user } from '@/.cool'
  6. import Physics from './components/physics.uvue'
  7. import Chinese from './components/chinese.uvue'
  8. import English from './components/english.uvue'
  9. import Mix from './components/mix.uvue'
  10. import Game from './components/game.uvue'
  11. const menuList = computed(() => {
  12. return [
  13. ...dict.getChildrenList('index_subject_id'),
  14. {
  15. label: '兑换',
  16. code: 'exchange'
  17. },
  18. {
  19. label: '个人中心',
  20. code: 'user'
  21. },
  22. ]
  23. })
  24. const icons = {
  25. physics: "https://oss.xiaoxiongcode.com/static/home/wl.png",
  26. chinese: "https://oss.xiaoxiongcode.com/static/home/语文.png",
  27. english: "https://oss.xiaoxiongcode.com/static/home/英语.png",
  28. mix: "https://oss.xiaoxiongcode.com/static/home/百度百科.png",
  29. game: "https://oss.xiaoxiongcode.com/static/home/娱乐.png",
  30. exchange: "https://oss.xiaoxiongcode.com/static/home/图层 5.png",
  31. user: "https://oss.xiaoxiongcode.com/static/home/个人中心.png",
  32. }
  33. const selected = ref<string>('physics')
  34. function handlePage(val: any) {
  35. selected.value = val.code
  36. if (val.code === 'user') {
  37. router.push({ path: '/pages/user/info' })
  38. }
  39. }
  40. onMounted(() => {
  41. console.log(menuList.value)
  42. })
  43. function handleView(url) {
  44. router.push({ path: url })
  45. }
  46. const userInfo = computed(() => user.info.value?.userInfo)
  47. </script>
  48. <template>
  49. <cl-page>
  50. <img src="https://oss.xiaoxiongcode.com/static/home/11.png" alt="" class="w-full h-full object-cover" />
  51. <view class="menus ">
  52. <view v-for="item in menuList" :key="item.code"
  53. class="flex flex-col items-center p-1 px-4 justify-center gap-1 active:scale-[.9] transition-all duration-300"
  54. @tap="handlePage(item)" :class="{ 'selected': item.code === selected }">
  55. <cl-image :src="icons[item.code]" mode="aspectFill" width="40" height="40"></cl-image>
  56. <text class="text-[12px]">{{ item.label }}</text>
  57. </view>
  58. </view>
  59. <Physics v-if="selected === 'physics'" />
  60. <Chinese v-else-if="selected === 'chinese'" />
  61. <English v-else-if="selected === 'english'" />
  62. <Mix v-else-if="selected === 'mix'" />
  63. <Game v-else-if="selected === 'game'" />
  64. </cl-page>
  65. </template>
  66. <style lang="scss" scoped>
  67. .menus {
  68. @apply absolute top-[5vh] left-1/2 bg-white rounded-[20px] p-2 px-3 flex flex-row items-center justify-center gap-2;
  69. transform: translateX(-50%);
  70. }
  71. .selected {
  72. @apply scale-[1.1] bg-[#f0f0f0] rounded-xl;
  73. }
  74. </style>