Skip to content

Commit

Permalink
Посмотрел запись дополнительной лекции от 07.01.25 и немного передела…
Browse files Browse the repository at this point in the history
…л задание 50-weather-components
  • Loading branch information
iKopturevskiy committed Jan 9, 2025
1 parent ede3b02 commit 1fb0040
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 25 deletions.
18 changes: 10 additions & 8 deletions 03-components/50-weather-components/WeatherApp.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { defineComponent } from 'vue'
import { defineComponent, computed } from 'vue'
import { getWeatherData, WeatherConditionIcons } from './weather.service.ts'
import WeatherAppList from './WeatherAppList.js'
import WeatherAppCard from './WeatherAppCard.js'
import WeatherMainData from "./WeatherMainData.js";

export default defineComponent({
name: 'WeatherApp',

components: {
WeatherAppList,
WeatherMainData,
WeatherAppCard,
},

setup () {
const icons = computed(() => WeatherConditionIcons);
const weatherData = computed(() => getWeatherData())
return {
weatherData: getWeatherData(),
icons: WeatherConditionIcons,
weatherData,
icons,
}
},

Expand All @@ -21,9 +25,7 @@ export default defineComponent({
<h1 class="title">Погода в Средиземье</h1>
<ul class="weather-list unstyled-list">
<WeatherAppList
:weatherData="weatherData"
:icons="icons"/>
<WeatherAppCard v-for="card in weatherData" :card :icons/>
</ul>
</div>
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import WeatherSecondaryData from "./WeatherSecondaryData.js";
import GeographicInfo from "./GeographicInfo.js";

export default defineComponent({
name: 'WeatherAppList',
name: 'WeatherAppCard',

components: {
WeatherCardIfAlert,
Expand All @@ -16,8 +16,8 @@ export default defineComponent({
},

props: {
weatherData: {
type: Array,
card: {
type: Object,
required: true,
},

Expand All @@ -39,14 +39,15 @@ export default defineComponent({

template: `
<li
v-for="card in weatherData"
class="weather-card"
:class="{ 'weather-card--night' : checkIfNight(card) }">
<WeatherCardIfAlert :card="card"/>
<GeographicInfo :card="card"/>
<WeatherMainData :card="card" :icons="icons"/>
<WeatherSecondaryData :card="card"/>
<WeatherCardIfAlert v-if="card.alert">
{{ card.alert.sender_name + ". " + card.alert.description }}
</WeatherCardIfAlert>
<GeographicInfo :card/>
<WeatherMainData :card :icons/>
<WeatherSecondaryData :card/>
</li>`
})
11 changes: 6 additions & 5 deletions 03-components/50-weather-components/WeatherCardIfAlert.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ export default defineComponent( {
name: 'WeatherCardIfAlert',

props: {
card: {
type: Object,
required: true,
text: {
type: String,
}
},

template: `
<div v-if="card.alert" class="weather-alert">
<div class="weather-alert">
<span class="weather-alert__icon">⚠️</span>
<span class="weather-alert__description">{{ card.alert.sender_name + ". " + card.alert.description }}</span>
<span class="weather-alert__description">
<slot>{{ text }}</slot>
</span>
</div>
`
})
11 changes: 9 additions & 2 deletions 03-components/50-weather-components/WeatherMainData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent } from 'vue'
import { defineComponent, computed } from 'vue'


export default defineComponent({
Expand All @@ -15,10 +15,17 @@ export default defineComponent({
}
},

setup(props) {
const temperature = computed(() => Number(props.card.current.temp - 273.15).toFixed(1))
return {
temperature,
}
},

template: `
<div class="weather-conditions">
<div class="weather-conditions__icon" :title="card.current.weather.description">{{ icons[card.current.weather.id] }}</div>
<div class="weather-conditions__temp">{{ Number(card.current.temp - 273.15).toFixed(1) }} °C</div>
<div class="weather-conditions__temp">{{ temperature }} °C</div>
</div>
`
})
11 changes: 9 additions & 2 deletions 03-components/50-weather-components/WeatherSecondaryData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent } from 'vue'
import { defineComponent, computed } from 'vue'

export default defineComponent({
name: 'WeatherSecondaryData',
Expand All @@ -10,11 +10,18 @@ export default defineComponent({
}
},

setup (props) {
const pressure = computed(() => Number(props.card.current.pressure * 0.75).toFixed(0))
return {
pressure,
}
},

template: `
<div class="weather-details">
<div class="weather-details__item">
<div class="weather-details__item-label">Давление, мм рт. ст.</div>
<div class="weather-details__item-value">{{ Number(card.current.pressure * 0.75).toFixed(0) }}</div>
<div class="weather-details__item-value">{{ pressure }}</div>
</div>
<div class="weather-details__item">
<div class="weather-details__item-label">Влажность, %</div>
Expand Down

0 comments on commit 1fb0040

Please sign in to comment.