<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<f=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¤t=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>
|