Header.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div
  3. class="header"
  4. :style="{ background: `url(${headImg}) no-repeat center` }"
  5. >
  6. <img class="logo" :src="headLogo" alt="" />
  7. <div class="title">智慧教室IOC平台</div>
  8. <!-- <img :src="headImg" alt="" /> -->
  9. <!-- <div></div> -->
  10. <div class="weather">
  11. <div class="left-time">
  12. <div class="time">{{ currentTime }}</div>
  13. <div class="year">{{ getCurrentYMD }}</div>
  14. </div>
  15. <el-divider direction="vertical" />
  16. <div class="right-weatherInfo">
  17. <img class="weather-icon" :src="sun" alt="" />
  18. <div class="info">
  19. <div class="text">{{ weatherInfo.text }}</div>
  20. <div class="temp">{{ weatherInfo.temp }} <span>°C</span></div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { ref, computed, onBeforeUnmount, onUnmounted, onMounted } from "vue";
  28. import axios from "axios";
  29. onMounted(() => {
  30. // 开启时间定时器获取当前时间
  31. starttimeInterval();
  32. // 获取天气信息
  33. // getWeatherInfo();
  34. });
  35. // 获取当前年月日计算属性
  36. const getCurrentYMD = computed(() => {
  37. const now = new Date();
  38. const year = now.getFullYear();
  39. const month = String(now.getMonth() + 1).padStart(2, "0");
  40. const day = String(now.getDate()).padStart(2, "0");
  41. return `${year}-${month}-${day}`;
  42. });
  43. // 获取当前时间 umbRQyjXTsyAsbzT4zLI3GNgnPrTBYGD
  44. let currentTime = ref(new Date().toLocaleTimeString());
  45. let timeInterval = ref(null);
  46. const starttimeInterval = () => {
  47. clearTimeout(timeInterval.value);
  48. timeInterval.value = setInterval(() => {
  49. currentTime.value = new Date().toLocaleTimeString();
  50. }, 1000);
  51. };
  52. let weatherInfo = ref({});
  53. const getWeatherInfo = (latitude, Longitude) => {
  54. const key = "UFwchof57SfCeYaiWXj1F2XBx0w8hKtB";
  55. //https://api.map.baidu.com/weather/v1/?location=${latitude},${Longitude}&data_type=all&ak=${key}
  56. axios
  57. .get(
  58. `https://api.map.baidu.com/weather/v1/?district_id=222405&data_type=all&ak=${key}`
  59. )
  60. .then((res) => {
  61. weatherInfo.value = res.data.result.now;
  62. console.log("天气信息", res.data.result.now);
  63. });
  64. };
  65. onBeforeUnmount(() => {
  66. clearTimeout(timeInterval.value);
  67. });
  68. onUnmounted(() => {
  69. clearTimeout(timeInterval.value);
  70. });
  71. const headImg = ref("./img/head.png");
  72. const headLogo = ref("./img/logo.png");
  73. const sun = ref("./img/sun.png");
  74. </script>
  75. <style scoped lang="scss">
  76. .header {
  77. position: absolute;
  78. z-index: 555;
  79. margin-bottom: 20px;
  80. height: 70px;
  81. width: 100%;
  82. display: flex;
  83. background-size: cover !important;
  84. background-position: center !important;
  85. background-repeat: no-repeat !important;
  86. .logo {
  87. width: 162px;
  88. height: 50px;
  89. position: absolute;
  90. left: 28px;
  91. top: 50%;
  92. transform: translateY(-50%);
  93. }
  94. .title {
  95. flex: 1;
  96. text-align: center;
  97. color: #fff;
  98. font-family: FZCuHeiSongS-B-GB;
  99. font-size: 40px;
  100. font-weight: 400;
  101. line-height: 70px;
  102. letter-spacing: 8px;
  103. }
  104. .weather {
  105. position: absolute;
  106. right: 10px;
  107. top: 50%;
  108. transform: translateY(-50%);
  109. display: flex;
  110. align-items: center;
  111. height: 38px;
  112. .left-time {
  113. margin-right: 12px;
  114. height: 38px;
  115. .time {
  116. color: #bfdfff;
  117. text-shadow: 0px 1px 3px rgba(5, 12, 25, 0.54);
  118. font-family: PangMenZhengDao;
  119. font-size: 24px;
  120. font-style: normal;
  121. font-weight: 600;
  122. }
  123. .year {
  124. color: #bfdfff;
  125. text-align: right;
  126. text-shadow: 0px 1px 3px rgba(5, 12, 25, 0.54);
  127. font-family: PangMenZhengDao;
  128. font-size: 12px;
  129. font-style: normal;
  130. font-weight: 400;
  131. line-height: normal;
  132. }
  133. }
  134. .right-weatherInfo {
  135. display: flex;
  136. align-items: center;
  137. height: 38px;
  138. .weather-icon {
  139. width: 30px;
  140. height: 30px;
  141. }
  142. .info {
  143. flex: 1;
  144. margin-left: 12px;
  145. height: 38px;
  146. .text {
  147. color: #bfdfff;
  148. text-shadow: 0px 1px 3px rgba(5, 12, 25, 0.54);
  149. /* text/pc/03-55-Regular */
  150. font-family: "Alibaba PuHuiTi 2.0";
  151. font-size: 12px;
  152. font-style: normal;
  153. font-weight: 400;
  154. line-height: normal;
  155. }
  156. .temp {
  157. color: #bfdfff;
  158. text-shadow: 0px 1px 3px rgba(5, 12, 25, 0.54);
  159. font-family: PangMenZhengDao;
  160. font-size: 16px;
  161. font-style: normal;
  162. font-weight: 400;
  163. line-height: normal;
  164. span {
  165. color: #bfdfff;
  166. font-family: "Alibaba PuHuiTi 2.0";
  167. font-size: 16px;
  168. font-style: normal;
  169. font-weight: 400;
  170. line-height: normal;
  171. }
  172. }
  173. }
  174. }
  175. }
  176. }
  177. :deep(.el-divider--vertical){
  178. height: 34px;
  179. }
  180. </style>