fix
13404089107
2025-03-27 4875efb4d957a81b0d7314398424bd23be333a63
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
  <div class="header">
    <div class="time-weather">
      <span class="time">{{ currentTime }}</span>
      <span class="date">{{ currentDate }}</span>
      <span class="weather">
        <div class="weather-box"></div>
        <iframe allowtransparency="true" frameborder="0" width="100" height="36" scrolling="no"
          src="//tianqi.2345.com/plugin/widget/index.htm?s=3&z=3&t=1&v=0&d=3&bd=0&k=&f=ffffff&ltf=ffffff&htf=ffffff&q=1&e=1&a=1&c=55591&w=100&h=36&align=left"></iframe>
      </span>
    </div>
  </div>
</template>
 
<script>
import dayjs from 'dayjs'
 
export default {
  name: 'Header',
  data() {
    return {
      currentTime: '',
      currentDate: '',
      temperature: '--'
    }
  },
  mounted() {
    this.startTimeUpdate()
    this.startWeatherUpdate()
  },
  methods: {
    startTimeUpdate() {
      const updateTime = () => {
        this.currentTime = dayjs().format('HH:mm:ss')
        this.currentDate = dayjs().format('YYYY/MM/DD')
      }
      updateTime()
      setInterval(updateTime, 1000)
    },
    startWeatherUpdate() {
      const updateWeather = async () => {
        try {
          const response = await fetch('https://api.open-meteo.com/v1/forecast?latitude=29.6487&longitude=91.1172&current=temperature_2m&timezone=Asia%2FShanghai')
          const data = await response.json()
          if (data.current) {
            this.temperature = Math.round(data.current.temperature_2m)
          }
        } catch (error) {
          console.error('获取天气数据失败:', error)
        }
      }
 
      updateWeather()
      setInterval(updateWeather, 30 * 60 * 1000)
    }
  }
}
</script>
 
<style scoped>
.header {
  height: 120px;
  display: flex;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(to bottom, rgba(1, 85, 121, 0.8) 0%, rgba(1, 85, 121, 0.4) 40%, rgba(151, 190, 192, 0) 100%);
  z-index: 1000;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 20px;
  backdrop-filter: blur(10px);
  pointer-events: none;
}
 
.time-weather {
  color: #fff;
  display: flex;
  gap: 20px;
  align-items: center;
  pointer-events: auto;
}
 
.time {
  font-size: 24px;
  font-weight: bold;
}
 
.weather {
  position: relative;
}
 
.weather-box {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 36px;
  z-index: 1000;
}
</style>