headerBi.vue
4.93 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<template>
<a-row class="template-head-view" display="flex" align="center">
<a-col :span="6">
<div class="template-head-date" v-if="headerData.date">
{{ getCurrentDateTime }}
</div>
</a-col>
<a-col :span="12">
<div class="template-head-title" :class="{ fontLab: pageTemplate == '2' }">
{{ title || '能源管理中心' }}
</div>
</a-col>
<a-col :span="6">
<div class="template-head-weather">
<template v-if="headerData.weather">
<img v-if="currentWeather.text.includes('雨')" src="@/assets/bi/icon-rain.png" alt=""/>
<img v-else-if="currentWeather.text.includes('多云')" src="@/assets/bi/icon-cloudy.png" alt=""/>
<img v-else-if="currentWeather.text.includes('阴')" src="@/assets/bi/icon-cloud.png" alt=""/>
<img v-else src="@/assets/bi/icon-weather.png" alt=""/>
{{ currentWeather.text }}
<img src="@/assets/bi/icon-temperature.png" alt=""/>
{{ currentWeather.temp }}
<img src="@/assets/bi/icon-humidness.png" alt=""/>
{{ currentWeather.humidity }}
<span>{{ currentTime || '' }}</span>
</template>
<icon-wifi v-if="headerData.network" :class="['wifi-status', network===true?'green':network===false?'red':'wifi-status']"/>
</div>
</a-col>
</a-row>
</template>
<script setup lang="ts">
import {computed, onBeforeUnmount, onMounted, ref} from 'vue';
import dayjs from 'dayjs';
import {getStation, getWeather, getNetwork} from '@/api/public';
import {useIntervalFn} from '@vueuse/core';
import {useRoute, useRouter} from "vue-router";
const router = useRouter();
const route = useRoute();
const props = defineProps({
headerData: {
type: Object,
default: () => {
return {
date: '',
weather: '',
network: false,
};
},
},
pageTemplate: {
type: String,
default: '0',
},
title: {
type: String,
default: '',
},
});
const currentWeather = ref({
text: '',
temp: '',
humidity: '',
});
const currentTime = ref('');
const network = ref('');
/**
* @desc 获取当前时间 YYYY年MM月DD日
*/
const getCurrentDateTime = computed(() => {
const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
const day = dayjs();
const curTime = day.format('YYYY年MM月DD日');
const week = Number(day.format('d'));
return `${curTime} ${weekDays[week]}`;
});
/**
* 获取天气
*/
const fetchWeather = async () => {
let resStation = await getStation();
if (resStation.code != 200) {
return;
}
//默认获取当前站点的位置信息
let res: any = await getWeather(resStation.data.coordinate || '122.13,37.42');
if (res.code == 200) {
currentWeather.value = {
text: res.data.now.text,
temp: res.data.now.temp + '℃',
humidity: res.data.now.humidity + '%',
};
}
};
/**
* @desc 每秒执行一次 获取当前时分秒
*/
const {resume: startInterval, pause: stopInterval} = useIntervalFn(async () => {
currentTime.value = dayjs().format('HH:mm:ss');
}, 1000);
const fetchNetwork = async (stationId: number) => {
const res: any = await getNetwork(stationId);
try {
if (res.code == 200) {
network.value = res.data;
}
} catch (e) {
console.error(e);
} finally {
}
}
onMounted(async () => {
if (props.headerData.weather) {
startInterval();
await fetchWeather();
}
if (props.headerData.network) {
if (route.query.stationId) await fetchNetwork(route.query.stationId);
}
});
onBeforeUnmount(() => {
stopInterval();
})
</script>
<style lang="less" scoped>
@font-size: 16px;
@font-size-mini: 14px;
@font-size-medium: 18px;
@font-size-large: 20px;
@color-w: white;
.template-head-view {
width: 100%;
height: 100%;
}
.template-head {
height: 100%;
display: flex;
align-items: center;
}
.template-head-date {
font-size: @font-size-medium;
letter-spacing: 1px;
//padding-left: 70px;
padding-left: 38px;
padding-bottom: 30px;
line-height: 40px;
box-sizing: border-box;
}
.template-head-title {
font-size: 48px;
text-align: center;
font-weight: bold;
}
.fontLab {
background: linear-gradient(180deg, #ffffff 100%, #0f8dff 20%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-shadow: 0 0 40px rgba(15, 141, 255, 0.8);
}
.template-head-weather {
font-size: @font-size-medium;
padding-right: 38px;
padding-bottom: 30px;
line-height: 50px;
display: flex;
align-items: center;
justify-content: flex-end;
box-sizing: border-box;
.wifi-status {
font-size: 28px;
color: #fff;
margin-left: 10px;
}
.red{
color: rgb(245, 34, 45);
}
.green{
color: rgb(82, 196, 26);
}
img {
margin-left: 10px;
margin-right: 2px;
width: 32px;
&:nth-child(2) {
width: 16px;
}
&:nth-child(3) {
width: 17px;
}
}
span {
margin-left: 14px;
}
}
</style>