Skip to content

Commit a0f64cd

Browse files
committed
Adicionando Vue Router | Adicionando novas funcionalidades: Calendário, feriados e views | Modificando resposta da API
1 parent c5cbc64 commit a0f64cd

File tree

14 files changed

+281
-62
lines changed

14 files changed

+281
-62
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
```
2626

2727
- Baixe as requisições do projeto com o comando `npm install`
28-
- Configure a requisição `fetch` no componente `Months.vue` para o endereço da API Holid (`localhost:3000`)
28+
- Altere os endpoints da API web para a API local em `@/views/MonthView.vue` e `@/components/Months.vue`
2929
- Inicialize o projeto com o comando `npm run serve`

package-lock.json

Lines changed: 35 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
},
99
"dependencies": {
1010
"core-js": "^3.8.3",
11-
"vue": "^3.2.13"
11+
"vue": "^3.2.13",
12+
"vue-router": "^4.0.3"
1213
},
1314
"devDependencies": {
1415
"@vue/cli-plugin-babel": "~5.0.0",
16+
"@vue/cli-plugin-router": "~5.0.0",
1517
"@vue/cli-service": "~5.0.0"
1618
}
1719
}

src/App.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
<template>
22
<h1 class="main-title">Calend</h1>
3-
<Today />
4-
<Months />
5-
<Footer />
3+
<Clock />
4+
<router-view />
65
</template>
76

87
<script>
9-
import Today from "@/components/Today.vue";
10-
import Months from "@/components/Months.vue";
11-
import Footer from "@/components/Footer.vue";
8+
import Clock from "@/components/Clock.vue";
129
export default {
13-
name: "App",
14-
components: { Today, Months, Footer },
10+
components: { Clock },
1511
};
1612
</script>
1713

1814
<style>
19-
@import url("https://fonts.googleapis.com/css2?family=Uchen&display=swap");
15+
@import url("https://fonts.googleapis.com/css2?family=Mukta&display=swap");
2016
2117
* {
22-
font-family: "Uchen", serif;
18+
font-family: "Mukta", sans-serif;
2319
}
2420
2521
#app {
2622
font-family: Avenir, Helvetica, Arial, sans-serif;
2723
-webkit-font-smoothing: antialiased;
2824
-moz-osx-font-smoothing: grayscale;
2925
text-align: center;
30-
max-width: 1200px;
26+
color: #2c3e50;
27+
max-width: 1000px;
3128
color: #4d4d4d;
3229
margin: 0 auto;
3330
}

src/components/Calendar.vue

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<template>
2+
<div class="calendar">
3+
<span class="day" :class="{ 'holiday-color': day.name && !day.changes }" v-for="day in daysWithHolidays" :key="day">
4+
{{ day.day || day }}
5+
<p class="holiday-desc" v-if="day.name && !day.changes">
6+
<span>{{ day.name }}</span>
7+
</p>
8+
</span>
9+
</div>
10+
</template>
11+
12+
<script>
13+
import { computed } from "@vue/runtime-core";
14+
export default {
15+
props: ["month"],
16+
setup(props) {
17+
console.log(props);
18+
const daysWithHolidays = computed(() => {
19+
const days = [];
20+
21+
for (let i = 1; i <= props.month.days; i++) days.push(i);
22+
23+
props.month.holidays.map((item) => {
24+
for (let i in days) {
25+
if (item.day == days[i]) days[i] = item;
26+
}
27+
});
28+
return days;
29+
});
30+
31+
return { daysWithHolidays };
32+
},
33+
};
34+
</script>
35+
36+
<style scoped>
37+
.calendar {
38+
display: grid;
39+
grid-template: 1fr / 1fr 1fr 1fr 1fr 1fr 1fr 1fr;
40+
gap: 10px;
41+
margin-bottom: 20px;
42+
}
43+
.day {
44+
display: grid;
45+
place-items: center;
46+
border: 3px solid #eee;
47+
padding: 10px;
48+
width: 100px;
49+
height: 100px;
50+
transition: 0.1s all;
51+
position: relative;
52+
}
53+
.day:hover {
54+
transform: translate(-10px, -10px);
55+
box-shadow: 10px 10px 0 0 #dddddd;
56+
}
57+
.holiday-color {
58+
color: #ff0000;
59+
}
60+
.holiday-desc {
61+
opacity: 0;
62+
background: #fff;
63+
position: absolute;
64+
top: 50%;
65+
transform: translateY(-50%);
66+
width: 100%;
67+
transition: 0.1s all;
68+
margin: 0;
69+
}
70+
.day:hover .holiday-desc {
71+
opacity: 1;
72+
}
73+
</style>

src/components/Clock.vue

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<div class="clock">
3+
<span>Hoje é {{ clock.day }}/{{ clock.month }}/{{ clock.year }}</span>
4+
<span> às {{ clock.hours }}:{{ clock.minutes }}:{{ clock.seconds }}</span>
5+
</div>
6+
</template>
7+
8+
<script>
9+
import { onMounted, ref } from "@vue/runtime-core";
10+
import runClock from "@/functions/runClock";
11+
export default {
12+
setup() {
13+
const clock = ref({});
14+
onMounted(() => {
15+
runClock(clock);
16+
setInterval(() => {
17+
runClock(clock);
18+
}, 1000);
19+
});
20+
21+
return { clock };
22+
},
23+
};
24+
</script>
25+
26+
<style scoped>
27+
.clock {
28+
margin: 20px;
29+
}
30+
</style>

src/components/Months.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
<template>
22
<div class="grid" v-if="months">
3-
<div v-for="month in months" :key="month.id">
4-
<h2>{{ month.name }}, {{ month.id }}</h2>
5-
<p>Total de dias: {{ month.days }}</p>
6-
<h4>Feriados</h4>
7-
<ul v-if="month.holidays.length > 0">
8-
<li v-for="holiday in month.holidays" :key="holiday.name">{{ holiday.name }}, {{ holiday.duration }} dia(s)</li>
9-
</ul>
10-
<ul v-else>
11-
<li style="color: #fc5a5a">Sem feriados definidos</li>
12-
</ul>
13-
</div>
3+
<router-link v-for="month in months" :key="month.id" :to="{ name: 'month', params: { id: month.id } }">
4+
<div>
5+
<h2>{{ month.name }}</h2>
6+
<p>Total de dias: {{ month.days }}</p>
7+
</div>
8+
</router-link>
149
</div>
1510
<Spinner v-else />
1611
</template>
@@ -35,11 +30,18 @@ export default {
3530
</script>
3631

3732
<style scoped>
33+
a {
34+
color: #2c3e50;
35+
text-decoration: none;
36+
}
3837
.grid {
3938
display: grid;
4039
grid-template: 1fr / 1fr 1fr 1fr;
4140
gap: 20px;
4241
}
42+
.grid h2 {
43+
color: #5189c0;
44+
}
4345
.grid div {
4446
border: 3px solid #eee;
4547
border-radius: 10px;

src/components/Today.vue

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/functions/runClock.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import format from "./format";
2+
3+
const runClock = (c) => {
4+
const d = new Date();
5+
c.value = {
6+
hours: format(d.getHours()),
7+
minutes: format(d.getMinutes()),
8+
seconds: format(d.getSeconds()),
9+
day: format(d.getDay()),
10+
month: format(d.getMonth() + 1),
11+
year: d.getFullYear(),
12+
};
13+
};
14+
15+
export default runClock;

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createApp } from 'vue'
22
import App from './App.vue'
3+
import router from './router'
34

4-
createApp(App).mount('#app')
5+
createApp(App).use(router).mount('#app')

0 commit comments

Comments
 (0)