WeatherInfo.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="weather-container">
  3. <div class="background-effects" v-if="type">
  4. <Lightning v-if="isThunderstorm" />
  5. <Snow v-else-if="isSnow" />
  6. <Rain v-else-if="isRain" />
  7. <Sunshine v-else-if="isSunny" />
  8. <Wind v-else-if="isWindy" />
  9. <Clouds v-else />
  10. </div>
  11. <div class="weather-icon-container">
  12. <img :src="weatherIcon" alt="" class="weather-icon" />
  13. </div>
  14. <div class="weather-details">
  15. <div v-if="warning" class="weather-warning">{{ warning }}</div>
  16. <div v-if="type" class="weather-type">{{ weatherKeyToChinese[type as WeatherType] }}</div>
  17. <div v-if="temperature" class="details">
  18. <div class="temperature">
  19. {{ temperature }}
  20. <span class="tem-unit">°C</span>
  21. </div>
  22. <div v-if="humidity || windSpeed" class="other-info">
  23. <div>湿度:{{ humidity }}%</div>
  24. <div>风速:{{ windSpeed }}</div>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script setup lang="ts">
  31. import { computed } from 'vue';
  32. import { WeatherType, weatherIcons, weatherKeyToChinese } from './weatherIcons';
  33. import Lightning from '@/components/weather-effects/Lightning.vue';
  34. import Snow from '@/components/weather-effects/Snow.vue';
  35. import Rain from '@/components/weather-effects/Rain.vue';
  36. import Sunshine from '@/components/weather-effects/Sunshine.vue';
  37. import Wind from '@/components/weather-effects/Wind.vue';
  38. import Clouds from '@/components/weather-effects/Clouds.vue';
  39. interface WeatherProps {
  40. type?: string;
  41. temperature?: number | undefined;
  42. humidity?: number | undefined;
  43. windSpeed?: string;
  44. warning?: string;
  45. }
  46. const props = defineProps<WeatherProps>();
  47. const weatherIcon = computed(() => {
  48. return weatherIcons[props.type as WeatherType] || weatherIcons.defaultIcon;
  49. });
  50. const isThunderstorm = computed(() => weatherKeyToChinese[props.type as WeatherType].includes('雷'));
  51. const isSnow = computed(() => weatherKeyToChinese[props.type as WeatherType].includes('雪'));
  52. const isRain = computed(() => weatherKeyToChinese[props.type as WeatherType].includes('雨'));
  53. const isSunny = computed(() => weatherKeyToChinese[props.type as WeatherType].includes('晴'));
  54. const isWindy = computed(() => weatherKeyToChinese[props.type as WeatherType].includes('风'));
  55. </script>
  56. <style scoped lang="scss">
  57. .weather-container {
  58. width: 500px;
  59. display: flex;
  60. align-items: center;
  61. margin: 20px 0 0 0;
  62. position: relative;
  63. overflow: hidden;
  64. transition: background-color 0.5s ease;
  65. }
  66. .background-effects {
  67. position: absolute;
  68. top: 0;
  69. left: 0;
  70. right: 0;
  71. bottom: 0;
  72. pointer-events: none;
  73. z-index: 0;
  74. }
  75. .weather-icon-container {
  76. width: 200px;
  77. height: 200px;
  78. margin-right: 20px;
  79. }
  80. .weather-icon {
  81. width: 100%;
  82. height: 100%;
  83. object-fit: contain;
  84. animation: float 3s ease-in-out infinite;
  85. }
  86. .weather-details {
  87. .weather-warning {
  88. font-size: 40px;
  89. font-family: YouSheBiaoTiYuan;
  90. color: #f56c6c;
  91. margin-bottom: 15px;
  92. }
  93. .weather-type {
  94. font-size: 20px;
  95. color: #111;
  96. }
  97. .details {
  98. display: flex;
  99. align-items: center;
  100. .temperature {
  101. font-size: 63px;
  102. font-family: DINAlternate;
  103. color: #1d2541;
  104. margin-right: 20px;
  105. display: flex;
  106. align-items: baseline;
  107. .tem-unit {
  108. font-size: 30px;
  109. margin-left: 5px;
  110. }
  111. }
  112. .other-info {
  113. font-size: 16px;
  114. color: #333333;
  115. }
  116. }
  117. }
  118. @keyframes float {
  119. 0%,
  120. 100% {
  121. transform: translateY(0);
  122. }
  123. 50% {
  124. transform: translateY(-10px);
  125. }
  126. }
  127. </style>