Skip to content

Commit e542be2

Browse files
committed
feat: counter
1 parent 1d1532c commit e542be2

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineStore } from 'pinia';
2+
3+
export const useCounterStore = defineStore('counter', {
4+
persist: true,
5+
state: () => ({
6+
countCurrent: 0,
7+
countGlobal: 0,
8+
}),
9+
actions: {
10+
increment() {
11+
this.countCurrent++
12+
this.countGlobal++
13+
},
14+
decrement() {
15+
this.countCurrent--
16+
},
17+
}
18+
});

src/modules/counter/counter.vue

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<script lang="ts" setup>
2+
import { useMediaQuery, useNow } from '@vueuse/core';
3+
import { useCounterStore } from './counter.store';
4+
5+
const store = useCounterStore()
6+
const isMobile = useMediaQuery('(max-width: 440px)')
7+
const now = useNow()
8+
</script>
9+
10+
<template>
11+
<div class="page-wrapper">
12+
<div class="content-wrapper">
13+
<n-space justify="center">
14+
<n-time :time="now" format="hh:mm:ss" class="time" />
15+
</n-space>
16+
<br>
17+
<br>
18+
<n-space item-style="flex:1 1 0">
19+
<n-card style="width: 100%">
20+
<n-statistic tabular-nums label="Actuellement">
21+
<n-space justify="center" class="timer timer-current">
22+
{{ store.countCurrent }}
23+
</n-space>
24+
</n-statistic>
25+
</n-card>
26+
27+
<n-card style="width: 100%">
28+
<n-statistic tabular-nums label="Au total">
29+
<n-space justify="center" class="timer timer-global">
30+
{{ store.countGlobal }}
31+
</n-space>
32+
</n-statistic>
33+
</n-card>
34+
</n-space>
35+
<br>
36+
<n-space vertical>
37+
<n-button class="button" secondary @click="store.increment">
38+
+1
39+
</n-button>
40+
<n-button class="button" secondary @click="store.decrement">
41+
-1
42+
</n-button>
43+
44+
<n-space item-style="flex:1 1 0" :vertical="isMobile">
45+
<n-popconfirm
46+
positive-text="Reset"
47+
negative-text="Annuler"
48+
@positive-click="() => store.countCurrent = 0"
49+
>
50+
<template #trigger>
51+
<n-button tertiary style="width: 100%">
52+
Reset le compteur actuel
53+
</n-button>
54+
</template>
55+
Êtes-vous sûr·e·s de vouloir reset le compteur actuel ?
56+
</n-popconfirm>
57+
<n-popconfirm
58+
positive-text="Reset"
59+
negative-text="Annuler"
60+
@positive-click="() => store.countGlobal = 0"
61+
>
62+
<template #trigger>
63+
<n-button tertiary style="width: 100%">
64+
Reset le compteur global
65+
</n-button>
66+
</template>
67+
Êtes-vous sûr·e·s de vouloir reset le compteur global ?
68+
</n-popconfirm>
69+
</n-space>
70+
</n-space>
71+
</div>
72+
</div>
73+
</template>
74+
75+
<style scoped lang="less">
76+
.page-wrapper {
77+
width: 100%;
78+
min-height: 100vh;
79+
background-color: #f5f5fb;
80+
padding: 60px 25px;
81+
box-sizing: border-box;
82+
83+
.content-wrapper {
84+
max-width: 550px;
85+
margin: 0 auto;
86+
}
87+
88+
89+
.time {
90+
opacity: 0.6;
91+
font-size: 25px;
92+
}
93+
94+
.button {
95+
width: 100%;
96+
padding: 35px 0;
97+
font-size: 25px;
98+
}
99+
.timer {
100+
font-size: 60px;
101+
102+
}
103+
}
104+
</style>

src/plugins/naive.plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ import {
3535
NDropdown,
3636
NEllipsis,
3737
NDivider,
38+
NStatistic,
39+
NTime
3840
} from 'naive-ui';
3941

4042
const components = [
43+
NTime,
44+
NStatistic,
4145
NDivider,
4246
NEllipsis,
4347
NDropdown,

src/router.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Dashboard from '@/modules/dashboard/dashboard.vue';
44
import Controls from '@/modules/controls/controls.vue';
55
import Create from '@/modules/create/create.vue';
66
import Boards from '@/modules/boards/board.vue';
7+
import Counter from '@/modules/counter/counter.vue';
78
import NotFound from '/src/pages/404.vue';
89
import About from '/src/pages/about.vue';
910
import { layouts } from '@/layouts';
@@ -53,6 +54,14 @@ export const router = createRouter({
5354
layout: layouts.navbar,
5455
},
5556
},
57+
{
58+
path: '/counter',
59+
name: 'Counter',
60+
component: Counter,
61+
meta: {
62+
layout: layouts.navbar,
63+
},
64+
},
5665
{
5766
path: '/:pathMatch(.*)*',
5867
name: '404',

0 commit comments

Comments
 (0)