-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
229 lines (213 loc) · 6.27 KB
/
app.vue
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
220
221
222
223
224
225
226
227
228
229
<script setup>
const runtime = useRuntimeConfig()
const state = reactive({
hasError: false,
hasResponse: false,
errorMessage: "",
local: "",
response: {}
})
async function searchLocal(){
state.hasError = false
state.hasResponse = false
await $fetch(`https://api.openweathermap.org/data/2.5/weather?q=${state.local}&units=metric&appid=${runtime.public.API_KEY}`).then(response => {
state.hasResponse = true
state.response = {
name: response.name,
temperature: response.main.temp,
min: response.main.temp_min,
max: response.main.temp_max,
feels: response.main.feels_like,
humidity: response.main.humidity,
description: response.weather[0].description,
wind: response.wind.speed,
image: ""
}
switch(response.weather[0].main){
case "Clouds": state.response.image = "/images/cloud.png"
break
case "Rain": state.response.image = "/images/rain.png"
break
case "Drizzle": state.response.image = "/images/rain.png"
break
case "Mist": state.response.image = "/images/mist.png"
break
case "Clear": state.response.image = "/images/clear.png"
break
case "Snow": state.response.image = "/images/snow.png"
break
}
})
.catch(error => {
if(error.status != 200){
state.hasError = true
if(error.status){
if(error.status === 404){
state.errorMessage = 'City Not Found'
throw new Error(state.errorMessage)
}
if(error.status === 401){
state.errorMessage = 'Unauthorized'
throw new Error(state.errorMessage)
}
if(error.status === 400){
state.errorMessage = 'Bad request'
throw new Error(state.errorMessage)
}
} else {
state.errorMessage = 'Erro na requisição'
throw new Error(state.errorMessage)
}
}
})
}
</script>
<template>
<main class="grid-cols-1">
<div class="container w-96 lg:w-1/3 y-2/5">
<!--pesquisar cidade-->
<div class="search-box">
<font-awesome-icon icon="fa-solid fa-location-dot" class="icon"/>
<input type="text" v-model="state.local" placeholder="insert the local" class="text-left"/>
<div id="search-local"
@click="searchLocal"
class="button-container">
<font-awesome-icon icon="fa-solid fa-magnifying-glass" class="button"/>
</div>
</div>
<!--cidade nao encontrada-->
<div
v-if="state.hasError && !state.hasResponse"
class="not-found flex grid grid-cols-1 y-2/5 items-center justify-center content-center place-items-center place-content-center">
<img class="py-5" src="/images/404.png" alt="imagem de local não encontrado">
<p class="text-base">Ooops! This local {{state.local}} not found....</p>
<p class="text-xs">{{ state.errorMessage }}</p>
</div>
<!--previsao do tempo -->
<div v-if="state.hasResponse "
class="flex grid grid-cols-2 y-1/4 items-center justify-center content-center place-items-center place-content-center">
<!--weather-box-->
<div class="weather-box space-y-2 place-content-center align-middle">
<img :src="state.response.image" alt="previsão do tempo" class="h-auto w-full items-center"/>
<p class="temperature text-4xl items-center px-auto ">{{ state.response.temperature }} Cº</p>
<p class="description text-xl">{{ state.response.description }}</p>
</div>
<!--weather-details-->
<div class="weather-details space-y-8 place-content-center text-lg align-middle h-auto w-full">
<div class="flex items-center justify-items-center content-center">
<font-awesome-icon icon="fa-solid fa-water" class="icon w-auto"/>
<div class="text">
<span>{{ Math.round(state.response.humidity) }} %</span>
<p class="">Humidity</p>
</div>
</div>
<div class="flex items-center justify-items-center content-center">
<font-awesome-icon icon="fa-solid fa-wind" class="icon w-auto"/>
<div class="text">
<span class="">{{ Math.round(state.response.wind) }} km/h</span>
<p class="">Wind Speed</p>
</div>
</div>
<div class="flex items-center justify-items-center content-center">
<font-awesome-icon icon="fa-solid fa-temperature-half" class="icon w-auto"/>
<div class="text">
<span>Feels {{ Math.round(state.response.feels) }} Cº</span>
<p class="">Min {{ Math.round(state.response.min) }} Cº</p>
<p class="">Max {{ Math.round(state.response.max) }} Cº</p>
</div>
</div>
</div>
</div>
</div>
</main>
</template>
<style lang="postcss" scoped>
*{
margin: 0;
padding: 0;
border: 0;
box-sizing: border-box;
outline: none;
}
main{
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #06283d;
}
.container{
position: relative;
background: #fff;
padding: 28px 32px;
overflow: hidden;
border-radius: 18px;
font-family: 'Roboto', sans-serif;
transition: 0.6s ease-out;
}
.search-box{
width: 100%;
height: min-content;
display: flex;
align-items: center;
justify-content: space-between;
}
.search-box input{
color: #06283D;
width: 80%;
font-size: 24px;
font-weight: 500;
text-transform: uppercase;
padding-left: 32px;
}
.search-box input::placeholder{
font-size: 20px;
font-weight: 500;
color: #06283D;
text-transform: capitalize;
}
.button-container{
cursor: pointer;
width: 50px;
height: 50px;
background: #dff6ff;
border-radius: 50%;
transition: 0.4s ease;
}
.button-container:hover{
background: #06283D;
}
.button{
color: #06283D;
font-size: 22px;
padding: 25%;
}
.button:hover{
color: #fff;
}
.icon{
position: absolute;
color: #06283D;
margin-left: 8px;
font-size: 28px;
text-align: center;
align-items: center;
}
.weather-box .temperature{
/* position: relative;*/
color: #06283D;
font-weight: 800;
text-align: center;
}
.weather-box .description{
color: #06283D;
font-weight: 500;
text-transform: capitalize;
text-align: center;
}
.text{
/* padding-left: 38px;*/
margin-left: 50px;
color: #06283D;
}
</style>