codevdesign 1.0.52 → 1.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/composants/csqcDate.vue +56 -35
- package/package.json +1 -1
package/composants/csqcDate.vue
CHANGED
|
@@ -1,58 +1,79 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<v-date-input
|
|
3
|
-
v-model="
|
|
3
|
+
v-model="dateInterne"
|
|
4
4
|
v-bind="$attrs"
|
|
5
5
|
input-format="yyyy-MM-dd"
|
|
6
6
|
variant="outlined"
|
|
7
7
|
prepend-icon=""
|
|
8
8
|
prepend-inner-icon="$calendar"
|
|
9
9
|
density="comfortable"
|
|
10
|
-
@update:model-value="
|
|
11
|
-
|
|
10
|
+
@update:model-value="choixUtilisateur"
|
|
11
|
+
/>
|
|
12
12
|
</template>
|
|
13
13
|
|
|
14
14
|
<script setup lang="ts">
|
|
15
|
-
import {
|
|
15
|
+
import { computed } from 'vue'
|
|
16
16
|
import { VDateInput } from 'vuetify/labs/VDateInput'
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
dateValeur.value = null
|
|
31
|
-
emit('update:modelValue', null)
|
|
32
|
-
return
|
|
33
|
-
}
|
|
18
|
+
type Model = string | Date | null
|
|
19
|
+
|
|
20
|
+
const props = defineProps<{ modelValue: Model }>()
|
|
21
|
+
|
|
22
|
+
const emit = defineEmits<{
|
|
23
|
+
(e: 'update:model-value', v: string | null): void
|
|
24
|
+
(e: 'change', v: string | null): void
|
|
25
|
+
}>()
|
|
26
|
+
|
|
27
|
+
// Normalisation, TOUJOURS "YYYY-MM-DD" ou null
|
|
28
|
+
const normalizeToYmd = (v: Date | string | null | undefined): string | null => {
|
|
29
|
+
if (v == null || v === '') return null
|
|
34
30
|
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
if (v instanceof Date) {
|
|
32
|
+
if (isNaN(v.getTime())) return null
|
|
33
|
+
const yyyy = v.getFullYear()
|
|
34
|
+
const mm = String(v.getMonth() + 1).padStart(2, '0')
|
|
35
|
+
const dd = String(v.getDate()).padStart(2, '0')
|
|
36
|
+
return `${yyyy}-${mm}-${dd}`
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
const
|
|
39
|
+
const s = String(v).trim()
|
|
40
|
+
|
|
41
|
+
// si ça commence par YYYY-MM-DD, on prend les 10 premiers chars
|
|
42
|
+
const m = s.match(/^(\d{4}-\d{2}-\d{2})/)
|
|
43
|
+
if (m) return m[1]
|
|
44
|
+
|
|
45
|
+
// Sinon, on tente un fallback
|
|
46
|
+
const d = new Date(s)
|
|
47
|
+
if (isNaN(d.getTime())) return null
|
|
42
48
|
const yyyy = d.getFullYear()
|
|
43
49
|
const mm = String(d.getMonth() + 1).padStart(2, '0')
|
|
44
50
|
const dd = String(d.getDate()).padStart(2, '0')
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
dateValeur.value = formatte
|
|
48
|
-
emit('update:modelValue', formatte)
|
|
51
|
+
return `${yyyy}-${mm}-${dd}`
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
()
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
// UI: VDateInput stable avec Date|null
|
|
55
|
+
const dateInterne = computed<Date | null>({
|
|
56
|
+
get() {
|
|
57
|
+
const ymd = normalizeToYmd(props.modelValue as any)
|
|
58
|
+
if (!ymd) return null
|
|
59
|
+
|
|
60
|
+
// Construire une Date locale sans décalage timezone (évite UTC shift)
|
|
61
|
+
const [y, m, d] = ymd.split('-').map(Number)
|
|
62
|
+
return new Date(y, m - 1, d)
|
|
63
|
+
},
|
|
64
|
+
set() {
|
|
65
|
+
// rien: on émet seulement dans choixUtilisateur
|
|
56
66
|
},
|
|
57
|
-
)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const choixUtilisateur = (v: Date | string | null) => {
|
|
70
|
+
const next = normalizeToYmd(v)
|
|
71
|
+
const current = normalizeToYmd(props.modelValue as any)
|
|
72
|
+
|
|
73
|
+
// Bloque la 2e émission au blur (même si type diffère Date/string)
|
|
74
|
+
if (next === current) return
|
|
75
|
+
|
|
76
|
+
emit('update:model-value', next)
|
|
77
|
+
emit('change', next)
|
|
78
|
+
}
|
|
58
79
|
</script>
|