-
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.
Merge pull request #5 from SergeyKalabin/master
Решил 5 задач из раздела компонеты
- Loading branch information
Showing
17 changed files
with
342 additions
and
163 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 timeData = new Intl.DateTimeFormat(navigator.language, { timeStyle: 'medium' }); | ||
|
||
template: `<div class="clock">10:12:02</div>`, | ||
const timeActual = ref(''); | ||
|
||
let intervalCount = 0; | ||
|
||
onMounted(() => { | ||
timeActual.value = timeData.format(new Date()); | ||
|
||
intervalCount = setInterval(() => { | ||
timeActual.value = timeData.format(new Date()); | ||
}, 1000); | ||
}) | ||
|
||
onUnmounted(() => { | ||
clearInterval( intervalCount ) | ||
}); | ||
|
||
return { | ||
timeActual, | ||
} | ||
}, | ||
|
||
template: `<div class="clock">{{ timeActual }}</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
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,92 @@ | ||
import { computed, defineComponent } from 'vue'; | ||
import { WeatherConditionIcons } from './weather.service.ts' | ||
import WeatherCardAlert from './WeatherCardAlert.js'; | ||
|
||
export default defineComponent({ | ||
name: 'WeatherCard', | ||
|
||
components: { | ||
WeatherCardAlert, | ||
}, | ||
|
||
props: { | ||
cards: { | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
|
||
setup( props ) { | ||
|
||
const weatherIcons = WeatherConditionIcons; | ||
|
||
function roundCelcium ( num ) { | ||
// return Math.round( num * 10 ) / 10; // плюс в том, что получаем чило, но при целых числах нет нулей после точки | ||
return num.toFixed( 1 ); // получаем строку | ||
}; | ||
|
||
function getTemperature( kelvin ) { | ||
let celsius = kelvin - 273.15; | ||
let result = `${roundCelcium ( celsius )} °C`; | ||
return result; | ||
}; | ||
|
||
function getPressure( value ) { | ||
let algoritm = value * 0.75; | ||
let result = Math.round( algoritm ); | ||
return result; | ||
}; | ||
|
||
function findSunDay( actualTime, sunriseTime, sunsetTime ) { | ||
return actualTime > sunriseTime && actualTime < sunsetTime; | ||
}; | ||
|
||
return { | ||
|
||
weatherIcons, | ||
|
||
getTemperature, | ||
|
||
getPressure, | ||
|
||
findSunDay, | ||
} | ||
}, | ||
|
||
template: ` | ||
<li class="weather-card" :class="{ 'weather-card--night': !findSunDay( cards.current.dt, cards.current.sunrise, cards.current.sunset ) }"> | ||
<WeatherCardAlert v-if="cards.alert" :sender-name="cards.alert.sender_name" :description="cards.alert.description" /> | ||
<div> | ||
<h2 class="weather-card__name"> | ||
{{ cards.geographic_name }} | ||
</h2> | ||
<div class="weather-card__time"> | ||
{{ cards.current.dt }} | ||
</div> | ||
</div> | ||
<div class="weather-conditions"> | ||
<div class="weather-conditions__icon" key:="weatherIcons" :title="cards.current.weather.description">{{ weatherIcons[cards.current.weather.id] }}</div> | ||
<div class="weather-conditions__temp">{{ getTemperature( cards.current.temp ) }}</div> | ||
</div> | ||
<div class="weather-details"> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Давление, мм рт. ст.</div> | ||
<div class="weather-details__item-value">{{ getPressure( cards.current.pressure ) }}</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Влажность, %</div> | ||
<div class="weather-details__item-value">{{ cards.current.humidity }}</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Облачность, %</div> | ||
<div class="weather-details__item-value">{{ cards.current.clouds }}</div> | ||
</div> | ||
<div class="weather-details__item"> | ||
<div class="weather-details__item-label">Ветер, м/с</div> | ||
<div class="weather-details__item-value">{{ cards.current.wind_speed }}</div> | ||
</div> | ||
</div> | ||
</li> | ||
` | ||
|
||
}); |
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,24 @@ | ||
import { defineComponent } from 'vue'; | ||
|
||
export default defineComponent({ | ||
name: 'WeatherCardAlert', | ||
|
||
props: { | ||
senderName: { | ||
type: String, | ||
required: true | ||
}, | ||
|
||
description: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
|
||
template: ` | ||
<div class="weather-alert"> | ||
<span class="weather-alert__icon">⚠️</span> | ||
<span class="weather-alert__description">{{ senderName }}: {{ description }}</span> | ||
</div> | ||
` | ||
}) |
Oops, something went wrong.