-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
412827f
commit bd17987
Showing
14 changed files
with
257 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,31 @@ | ||
import { defineComponent } from 'vue' | ||
import { defineComponent, ref, onMounted, onUnmounted } from 'vue'; | ||
|
||
export default defineComponent({ | ||
name: 'UiClock', | ||
|
||
setup() {}, | ||
setup() { | ||
const time = ref(''); | ||
|
||
template: `<div class="clock">10:12:02</div>`, | ||
}) | ||
const updateTime = () => { | ||
const currentTime = new Date(); | ||
time.value = currentTime.toLocaleTimeString(navigator.language, { timeStyle: 'medium' }); | ||
}; | ||
|
||
let intervalId; | ||
|
||
onMounted(() => { | ||
updateTime(); | ||
intervalId = setInterval(updateTime, 1000); | ||
}); | ||
|
||
onUnmounted(() => { | ||
clearInterval(intervalId); | ||
}); | ||
|
||
return { | ||
time, | ||
}; | ||
}, | ||
|
||
template: `<div class="clock">{{ time }}</div>`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,32 @@ | ||
import { defineComponent } from 'vue' | ||
import { defineComponent, ref} from 'vue' | ||
import { getWeatherData, WeatherConditionIcons } from './weather.service.ts' | ||
import './WeatherApp.css' | ||
import WeatherList from './WeatherList.vue' | ||
|
||
export default defineComponent({ | ||
name: 'WeatherApp', | ||
|
||
components: { WeatherList }, | ||
|
||
setup() { | ||
const weatherData = ref(getWeatherData()) | ||
|
||
return { | ||
weatherData, | ||
} | ||
}, | ||
|
||
template: ` | ||
<div> | ||
<h1 class="title">Погода в Средиземье</h1> | ||
<h1 class="title">Погода в Средиземье</h1> | ||
<ul class="weather-list unstyled-list"> | ||
<li class="weather-card weather-card--night"> | ||
<div class="weather-alert"> | ||
<span class="weather-alert__icon">⚠️</span> | ||
<span class="weather-alert__description">Королевская метеослужба короля Арагорна II: Предвещается наступление сильного шторма.</span> | ||
</div> | ||
<div> | ||
<h2 class="weather-card__name"> | ||
Гондор | ||
</h2> | ||
<div class="weather-card__time"> | ||
07:17 | ||
</div> | ||
</div> | ||
<div class="weather-conditions"> | ||
<div class="weather-conditions__icon" title="thunderstorm with heavy rain">⛈️</div> | ||
<div class="weather-conditions__temp">15.0 °C</div> | ||
</div> | ||
<div class="weather-details"> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Давление, мм рт. ст.</div> | ||
<div class="weather-details__item-value">754</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Влажность, %</div> | ||
<div class="weather-details__item-value">90</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Облачность, %</div> | ||
<div class="weather-details__item-value">100</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Ветер, м/с</div> | ||
<div class="weather-details__item-value">10.5</div> | ||
</div> | ||
</div> | ||
</li> | ||
</ul> | ||
<ul class="weather-list unstyled-list"> | ||
<WeatherList | ||
v-for="(region, index) in weatherData" | ||
:key="index" | ||
:region="region" | ||
/> | ||
</ul> | ||
</div> | ||
`, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<script> | ||
import { WeatherConditionIcons } from './weather.service.ts' | ||
export default { | ||
name: "WeatherList", | ||
props: { | ||
region: { | ||
required: true, | ||
type: Object, | ||
}, | ||
}, | ||
setup(props) { | ||
const weatherConditionIcons = WeatherConditionIcons || {}; | ||
const kelvinToCelsius = (temp) => { | ||
return (temp - 273.15).toFixed(1); | ||
}; | ||
const isNightTime = (currentTime, sunrise, sunset) => { | ||
return currentTime < sunrise || currentTime > sunset; | ||
}; | ||
return { | ||
weatherConditionIcons, | ||
kelvinToCelsius, | ||
isNightTime, | ||
region: props.region, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
|
||
<template> | ||
<li class="weather-card" | ||
:class="{ 'weather-card--night': isNightTime(region.current.dt, region.current.sunrise, region.current.sunset) }"> | ||
<div class="weather-alert" v-if="region.alert"> | ||
<span class="weather-alert__icon">⚠️</span> | ||
<span class="weather-alert__description">{{ region.alert.sender_name }} {{ region.alert.description }}</span> | ||
</div> | ||
<div> | ||
<h2 class="weather-card__name">{{ region.geographic_name }}</h2> | ||
<div class="weather-card__time">{{ region.current.dt }}</div> | ||
</div> | ||
<div class="weather-conditions"> | ||
<div class="weather-conditions__icon" :title="region.current.weather.description"> | ||
{{ weatherConditionIcons[region.current.weather.id] || '' }} | ||
</div> | ||
<div class="weather-conditions__temp">{{ kelvinToCelsius(region.current.temp) }} °C</div> | ||
</div> | ||
<div class="weather-details"> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Давление, мм рт. ст.</div> | ||
<div class="weather-details__item-value">{{ (region.current.pressure / 1.333).toFixed(0) }}</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Влажность, %</div> | ||
<div class="weather-details__item-value">{{ region.current.humidity }}</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Облачность, %</div> | ||
<div class="weather-details__item-value">{{ region.current.clouds }}</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Ветер, м/с</div> | ||
<div class="weather-details__item-value">{{ region.current.wind_speed }}</div> | ||
</div> | ||
</div> | ||
</li> | ||
</template> | ||
|
||
<style scoped></style> |
Oops, something went wrong.