Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Решение 2х задач по 2му занятию #2

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 01-basics/10-create-app/script.js
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
import { defineComponent, createApp } from 'vue'

const App = defineComponent({
name: 'App',

setup() {
const getDateLocal = new Date().toLocaleDateString(navigator.language, { dateStyle: 'long' });

return {
getDateLocal
}
},

template: `<div>Сегодня {{ getDateLocal }}</div>`
});

const app = createApp(App);
app.mount('#app');
136 changes: 88 additions & 48 deletions 01-basics/20-weather/WeatherApp.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,91 @@
import { defineComponent } from 'vue'
import { getWeatherData, WeatherConditionIcons } from './weather.service.ts'
import {defineComponent} from 'vue'
import {getWeatherData, WeatherConditionIcons} from './weather.service.ts'

function getIconByConditionId(id) {
return WeatherConditionIcons[parseInt(id)] || '';
}

Comment on lines +4 to +6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vue сам приводит undefined к пустой строке при выводе

function timeToSeconds(time) {
return time.split(':')[0]*60 + time.split(':')[1]*1;
}

function isDayNow(currientTime, sunriseTime, sunsetTime) {
return timeToSeconds(sunriseTime) < timeToSeconds(currientTime) && timeToSeconds(currientTime) < timeToSeconds(sunsetTime);
}

Comment on lines +8 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Строки в формате HH:MM можно сравнивать просто лексикографически как строки без преобразований. '08:30' < '09:12'

function kelvinToCelsius(tempK) {
return (tempK - 273.15).toFixed(1);
}

function pressureConvert(pressure) {
return Math.round(pressure * 0.75 );
}

export default defineComponent({
name: 'WeatherApp',

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>
</div>
`,
name: 'WeatherApp',

setup() {
const weatherData = getWeatherData();

return {
weatherData,
isDayNow,
getIconByConditionId,
kelvinToCelsius,
pressureConvert
}
},

template: `
<div>
<h1 class="title">Погода в Средиземье</h1>

<ul class="weather-list unstyled-list">
<li
v-for="(weatherItem, index) in weatherData"
:key="index"
class="weather-card"
:class="{'weather-card--night': !isDayNow(weatherItem.current.dt, weatherItem.current.sunrise, weatherItem.current.sunset)}"
>
<div v-if="weatherItem.alert" class="weather-alert">
<span class="weather-alert__icon">⚠️</span>
<span class="weather-alert__description">{{ weatherItem.alert.sender_name }}:
{{ weatherItem.alert.description }}</span>
</div>
<div>
<h2 class="weather-card__name">
{{ weatherItem.geographic_name }}
</h2>
<div class="weather-card__time">
{{ weatherItem.current.dt }}
</div>
</div>
<div class="weather-conditions">
<div class="weather-conditions__icon" :title="weatherItem.current.weather.description">
{{ getIconByConditionId(weatherItem.current.weather.id) }}
</div>
<div class="weather-conditions__temp">{{ kelvinToCelsius(weatherItem.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">{{ pressureConvert(weatherItem.current.pressure) }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Влажность, %</div>
<div class="weather-details__item-value">{{ weatherItem.current.humidity }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Облачность, %</div>
<div class="weather-details__item-value">{{ weatherItem.current.clouds }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Ветер, м/с</div>
<div class="weather-details__item-value">{{ weatherItem.current.wind_speed }}</div>
</div>
</div>
</li>
</ul>
</div>
`,
})
Loading