codevdesign 1.0.54 → 1.0.55
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 +79 -79
- package/package.json +1 -1
package/composants/csqcDate.vue
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<v-date-input
|
|
3
|
-
|
|
4
|
-
v-bind="$attrs"
|
|
5
|
-
input-format="yyyy-MM-dd"
|
|
6
|
-
variant="outlined"
|
|
7
|
-
prepend-icon=""
|
|
8
|
-
prepend-inner-icon="$calendar"
|
|
9
|
-
density="comfortable"
|
|
10
|
-
@update:model-value="choixUtilisateur"
|
|
11
|
-
/>
|
|
12
|
-
</template>
|
|
13
|
-
|
|
14
|
-
<script setup lang="ts">
|
|
15
|
-
import { computed } from 'vue'
|
|
16
|
-
import { VDateInput } from 'vuetify/labs/VDateInput'
|
|
17
|
-
|
|
18
|
-
type Model = string | Date | null
|
|
19
|
-
|
|
20
|
-
const props = defineProps<{ modelValue: Model }>()
|
|
21
|
-
|
|
22
|
-
const emit = defineEmits<{
|
|
23
|
-
(e: 'update:
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const m = s.match(/^(\d{4}
|
|
43
|
-
if (m) return
|
|
44
|
-
|
|
45
|
-
//
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return `${
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// UI: VDateInput stable avec Date|null
|
|
55
|
-
const dateInterne = computed<Date | null>({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
emit('update:
|
|
77
|
-
emit('change', next)
|
|
78
|
-
}
|
|
79
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<v-date-input
|
|
3
|
+
:model-value="dateInterne"
|
|
4
|
+
v-bind="$attrs"
|
|
5
|
+
input-format="yyyy-MM-dd"
|
|
6
|
+
variant="outlined"
|
|
7
|
+
prepend-icon=""
|
|
8
|
+
prepend-inner-icon="$calendar"
|
|
9
|
+
density="comfortable"
|
|
10
|
+
@update:model-value="choixUtilisateur"
|
|
11
|
+
/>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script setup lang="ts">
|
|
15
|
+
import { computed, ref } from 'vue'
|
|
16
|
+
import { VDateInput } from 'vuetify/labs/VDateInput'
|
|
17
|
+
|
|
18
|
+
type Model = string | Date | null
|
|
19
|
+
|
|
20
|
+
const props = defineProps<{ modelValue: Model }>()
|
|
21
|
+
|
|
22
|
+
const emit = defineEmits<{
|
|
23
|
+
(e: 'update:modelValue', 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
|
|
30
|
+
|
|
31
|
+
// Date -> YYYY-MM-DD (local)
|
|
32
|
+
if (v instanceof Date) {
|
|
33
|
+
if (isNaN(v.getTime())) return null
|
|
34
|
+
const yyyy = v.getFullYear()
|
|
35
|
+
const mm = String(v.getMonth() + 1).padStart(2, '0')
|
|
36
|
+
const dd = String(v.getDate()).padStart(2, '0')
|
|
37
|
+
return `${yyyy}-${mm}-${dd}`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// String -> accepte seulement YYYY-MM-DD
|
|
41
|
+
const s = String(v).trim()
|
|
42
|
+
const m = s.match(/^(\d{4})-(\d{2})-(\d{2})$/)
|
|
43
|
+
if (!m) return null
|
|
44
|
+
|
|
45
|
+
// Optionnel: validation simple (évite 2026-99-99)
|
|
46
|
+
const y = Number(m[1]),
|
|
47
|
+
mo = Number(m[2]),
|
|
48
|
+
d = Number(m[3])
|
|
49
|
+
if (mo < 1 || mo > 12 || d < 1 || d > 31) return null
|
|
50
|
+
|
|
51
|
+
return `${m[1]}-${m[2]}-${m[3]}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// UI: VDateInput stable avec Date|null
|
|
55
|
+
const dateInterne = computed<Date | null>(() => {
|
|
56
|
+
const ymd = normalizeToYmd(props.modelValue as any)
|
|
57
|
+
if (!ymd) return null
|
|
58
|
+
const [y, m, d] = ymd.split('-').map(Number)
|
|
59
|
+
return new Date(y, m - 1, d) // local, stable
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const prevBeforeEmit = ref<string | null>(null)
|
|
63
|
+
|
|
64
|
+
const choixUtilisateur = (v: Date | string | null) => {
|
|
65
|
+
const next = normalizeToYmd(v)
|
|
66
|
+
const current = normalizeToYmd(props.modelValue as any)
|
|
67
|
+
|
|
68
|
+
// rollback: on reçoit l'ancienne valeur (celle qu'on avait avant)
|
|
69
|
+
if (prevBeforeEmit.value && next === prevBeforeEmit.value && current !== prevBeforeEmit.value) {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (next === current) return
|
|
74
|
+
|
|
75
|
+
prevBeforeEmit.value = current
|
|
76
|
+
emit('update:modelValue', next)
|
|
77
|
+
emit('change', next)
|
|
78
|
+
}
|
|
79
|
+
</script>
|