-
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
Anastasia th9
authored and
Anastasia th9
committed
Jan 1, 2025
1 parent
820fd6a
commit 019fd2f
Showing
8 changed files
with
226 additions
and
57 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,46 @@ | ||
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()) | ||
|
||
const kelvinToCelsius = temp => { | ||
return (temp - 273.15).toFixed(1) | ||
} | ||
|
||
const isNightTime = (currentDt, sunrise, sunset) => { | ||
return currentDt < sunrise || currentDt >= sunset | ||
} | ||
|
||
return { | ||
weatherData, | ||
kelvinToCelsius, | ||
WeatherConditionIcons, | ||
isNightTime, | ||
} | ||
}, | ||
|
||
template: ` | ||
<div> | ||
<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> | ||
<h1 class="title">Погода в Средиземье</h1> | ||
<ul class="weather-list unstyled-list"> | ||
<WeatherList | ||
v-for="(region, index) in weatherData" | ||
:key="index" | ||
:region="region" | ||
:kelvinToCelsius="kelvinToCelsius" | ||
:isNightTime="isNightTime" | ||
:WeatherConditionIcons="WeatherConditionIcons" | ||
/> | ||
</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,67 @@ | ||
<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> | ||
|
||
<script> | ||
export default { | ||
name: "WeatherList", | ||
props: { | ||
region: { | ||
required: true, | ||
type: Object, | ||
}, | ||
kelvinToCelsius: { | ||
type: Function, | ||
required: true, | ||
}, | ||
isNightTime: { | ||
type: Function, | ||
required: true, | ||
}, | ||
WeatherConditionIcons: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
</style> |