codevdesign 1.0.36 → 1.0.38
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/csqcAide.vue +55 -55
- package/composants/csqcAlerteErreur.vue +87 -87
- package/composants/csqcChaise/chaiseConteneur.vue +367 -367
- package/composants/csqcChaise/chaiseItem.vue +54 -54
- package/composants/csqcCodeBudgetaireGenerique.vue +336 -336
- package/composants/csqcConfirmation.vue +75 -75
- package/composants/csqcDate.vue +57 -57
- package/composants/csqcDialogue.vue +118 -118
- package/composants/csqcEditeurTexteRiche.vue +380 -380
- package/composants/csqcEntete.vue +163 -163
- package/composants/csqcImportCSV.vue +125 -125
- package/composants/csqcModaleSaisie.vue +97 -95
- package/composants/csqcOptionSwitch.vue +120 -120
- package/composants/csqcRecherche.vue +213 -213
- package/composants/csqcSnackbar.vue +88 -88
- package/composants/csqcTable/csqcTable.vue +383 -383
- package/composants/csqcTable/csqcTableModaleChoixColonnes.vue +586 -586
- package/composants/csqcTexteBilingue.vue +175 -175
- package/composants/csqcTiroir.vue +156 -156
- package/composants/gabarit/csqcMenu.vue +281 -281
- package/composants/gabarit/pivEntete.vue +205 -205
- package/index.ts +75 -75
- package/modeles/composants/csqcMenuModele.ts +18 -18
- package/modeles/composants/datatableColonne.ts +31 -31
- package/outils/appAxios.ts +116 -116
- package/outils/rafraichisseurToken.ts +187 -187
- package/package.json +1 -1
|
@@ -1,336 +1,336 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<v-form
|
|
4
|
-
ref="form"
|
|
5
|
-
v-model="formValide"
|
|
6
|
-
@submit.prevent
|
|
7
|
-
>
|
|
8
|
-
<v-combobox
|
|
9
|
-
v-model="codeBudgetaire"
|
|
10
|
-
:items="itemsCombobox"
|
|
11
|
-
item-value="code"
|
|
12
|
-
item-title="code"
|
|
13
|
-
:return-object="false"
|
|
14
|
-
v-bind="$attrs"
|
|
15
|
-
persistent-hint
|
|
16
|
-
variant="outlined"
|
|
17
|
-
hide-details="auto"
|
|
18
|
-
:error="!estValideComplet"
|
|
19
|
-
:rules="reglesVuetify"
|
|
20
|
-
:hint="afficherHint ? placeholder : ''"
|
|
21
|
-
@blur="sauvegarder"
|
|
22
|
-
@keydown.enter="sauvegarder"
|
|
23
|
-
@keydown="caractereAutorises"
|
|
24
|
-
@update:modelValue="gererChangement"
|
|
25
|
-
@paste="gererPaste"
|
|
26
|
-
>
|
|
27
|
-
<template #item="{ props, item }">
|
|
28
|
-
<v-list-item
|
|
29
|
-
v-bind="props"
|
|
30
|
-
:title="item.raw.nom || item.raw.code"
|
|
31
|
-
:subtitle="item.raw.nom ? item.raw.code : undefined"
|
|
32
|
-
/>
|
|
33
|
-
</template>
|
|
34
|
-
</v-combobox>
|
|
35
|
-
</v-form>
|
|
36
|
-
</div>
|
|
37
|
-
</template>
|
|
38
|
-
|
|
39
|
-
<script setup lang="ts">
|
|
40
|
-
import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
|
41
|
-
import type { VForm } from 'vuetify/components'
|
|
42
|
-
|
|
43
|
-
const emit = defineEmits<{
|
|
44
|
-
'update:modelValue': [string | null]
|
|
45
|
-
'update:codeBudgetairesProp': [CodeBudgetaireItem[]]
|
|
46
|
-
'update:valide': [boolean]
|
|
47
|
-
}>()
|
|
48
|
-
type CodeBudgetaireItem = string | [string, string]
|
|
49
|
-
|
|
50
|
-
const props = withDefaults(
|
|
51
|
-
defineProps<{
|
|
52
|
-
codeBudgetairesProp: CodeBudgetaireItem[]
|
|
53
|
-
modelValue: string | null
|
|
54
|
-
afficherHint?: boolean
|
|
55
|
-
regleMessageErreur: string
|
|
56
|
-
format?: string
|
|
57
|
-
activerExtension?: boolean
|
|
58
|
-
reglesSupp?: ((v: string) => true | string)[]
|
|
59
|
-
}>(),
|
|
60
|
-
{
|
|
61
|
-
afficherHint: false,
|
|
62
|
-
format: '999-9-99999-999',
|
|
63
|
-
activerExtension: false,
|
|
64
|
-
reglesSupp: () => [],
|
|
65
|
-
},
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
const formValide = ref(false)
|
|
69
|
-
const form = ref<VForm | null>(null)
|
|
70
|
-
const codeBudgetaire = ref(props.modelValue ?? '')
|
|
71
|
-
const derniereValeurSauvegardee = ref<string | null>(null)
|
|
72
|
-
const format = props.format
|
|
73
|
-
const activerExtension = props.activerExtension
|
|
74
|
-
|
|
75
|
-
onMounted(() => {
|
|
76
|
-
derniereValeurSauvegardee.value = codeBudgetaire.value
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
const itemsCombobox = computed(() => {
|
|
80
|
-
return props.codeBudgetairesProp.map(item => {
|
|
81
|
-
if (typeof item === 'string') {
|
|
82
|
-
return {
|
|
83
|
-
code: item,
|
|
84
|
-
nom: '', // pas de nom
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const [code, nomBrut] = item
|
|
89
|
-
const nom = (nomBrut ?? '').toString().trim()
|
|
90
|
-
|
|
91
|
-
return { code, nom }
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
const placeholder = computed(() => {
|
|
96
|
-
const base = format.replace(/9/g, '0')
|
|
97
|
-
const extension = activerExtension ? '-XXX/XXX' : ''
|
|
98
|
-
return base + extension
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
const estValide = computed(() => {
|
|
102
|
-
const val = codeBudgetaire.value?.toUpperCase().trim() || ''
|
|
103
|
-
const base = val.slice(0, 15)
|
|
104
|
-
const extension = val.slice(15)
|
|
105
|
-
|
|
106
|
-
if (!/^\d{3}-\d{1}-\d{5}-\d{3}$/.test(base)) return false
|
|
107
|
-
|
|
108
|
-
if (!activerExtension) return val.length === 15
|
|
109
|
-
|
|
110
|
-
if (val.length === 15) return true
|
|
111
|
-
if (val.length !== 22) return false
|
|
112
|
-
if (extension.length !== 7) return false
|
|
113
|
-
|
|
114
|
-
if (extension[3] !== '/') return false
|
|
115
|
-
if (!/^[A-Z0-9/]$/i.test(extension[0]!)) return false
|
|
116
|
-
|
|
117
|
-
const alphanumAt = [1, 2, 4, 5, 6]
|
|
118
|
-
return alphanumAt.every(i => /^[A-Z0-9]$/i.test(extension[i]!))
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
// Règles Vuetify combinées (interne + supplémentaires)
|
|
122
|
-
const reglesVuetify = computed(() => [
|
|
123
|
-
// règle interne
|
|
124
|
-
() => (estValide.value ? true : props.regleMessageErreur),
|
|
125
|
-
|
|
126
|
-
// règles supplémentaires venant du parent
|
|
127
|
-
...props.reglesSupp.map(rule => {
|
|
128
|
-
return () => rule(codeBudgetaire.value) // on passe la valeur formatée
|
|
129
|
-
}),
|
|
130
|
-
])
|
|
131
|
-
|
|
132
|
-
// Validité globale du composant (interne + toutes les règles supp)
|
|
133
|
-
const estValideComplet = computed(() => {
|
|
134
|
-
if (!estValide.value) return false
|
|
135
|
-
return props.reglesSupp.every(rule => rule(codeBudgetaire.value) === true)
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
const caractereAutorises = (e: KeyboardEvent) => {
|
|
139
|
-
if (e.ctrlKey || e.metaKey) return
|
|
140
|
-
|
|
141
|
-
const touchesSpecifiques = ['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Tab', 'Home', 'End']
|
|
142
|
-
if (touchesSpecifiques.includes(e.key)) return
|
|
143
|
-
|
|
144
|
-
const input = e.target as HTMLInputElement
|
|
145
|
-
let position = input.selectionStart ?? 0
|
|
146
|
-
|
|
147
|
-
// Gestion de la partie de base (15 premiers caractères)
|
|
148
|
-
if (position < 15) {
|
|
149
|
-
if (!/^\d$/.test(e.key)) {
|
|
150
|
-
e.preventDefault()
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Insérer chiffre et auto-ajout des tirets
|
|
155
|
-
e.preventDefault()
|
|
156
|
-
|
|
157
|
-
const value = codeBudgetaire.value.replace(/-/g, '')
|
|
158
|
-
const clean = value.slice(0, 12) + e.key
|
|
159
|
-
|
|
160
|
-
let formatted = ''
|
|
161
|
-
if (clean.length > 0) formatted += clean.slice(0, 3)
|
|
162
|
-
if (clean.length > 3) formatted += '-' + clean.slice(3, 4)
|
|
163
|
-
if (clean.length > 4) formatted += '-' + clean.slice(4, 9)
|
|
164
|
-
if (clean.length > 9) formatted += '-' + clean.slice(9, 12)
|
|
165
|
-
|
|
166
|
-
codeBudgetaire.value = formatted.slice(0, 15)
|
|
167
|
-
|
|
168
|
-
nextTick(() => {
|
|
169
|
-
const newPos = codeBudgetaire.value.length
|
|
170
|
-
input.selectionStart = input.selectionEnd = newPos
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
return
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// --- Gestion de l'extension ---
|
|
177
|
-
if (!activerExtension || position >= 22 || codeBudgetaire.value.length >= 22) {
|
|
178
|
-
e.preventDefault()
|
|
179
|
-
return
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const extensionPos = position - 15
|
|
183
|
-
|
|
184
|
-
// Règle 1 : extension[0] = alphanum ou /
|
|
185
|
-
if (extensionPos === 0) {
|
|
186
|
-
if (!/^[A-Z0-9/]$/i.test(e.key)) {
|
|
187
|
-
e.preventDefault()
|
|
188
|
-
return
|
|
189
|
-
}
|
|
190
|
-
return
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Règle 2 : extension[1,2,4,5,6] = alphanum
|
|
194
|
-
if ([1, 2, 4, 5, 6].includes(extensionPos)) {
|
|
195
|
-
if (!/^[A-Z0-9]$/i.test(e.key)) {
|
|
196
|
-
e.preventDefault()
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
return
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Règle 3 : slash automatique à position 3 (index 18)
|
|
203
|
-
if (extensionPos === 3) {
|
|
204
|
-
e.preventDefault()
|
|
205
|
-
const before = codeBudgetaire.value.slice(0, position)
|
|
206
|
-
const after = codeBudgetaire.value.slice(position)
|
|
207
|
-
codeBudgetaire.value = before + '/' + after
|
|
208
|
-
nextTick(() => {
|
|
209
|
-
input.selectionStart = input.selectionEnd = position + 1
|
|
210
|
-
})
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Tout autre cas = bloqué
|
|
215
|
-
e.preventDefault()
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const formaterCodeBudgetaire = (valeur: string): string => {
|
|
219
|
-
if (!valeur) return ''
|
|
220
|
-
|
|
221
|
-
const upper = valeur.toUpperCase().replace(/[^A-Z0-9/]/g, '')
|
|
222
|
-
const chiffres = upper.replace(/[^0-9]/g, '').slice(0, 12)
|
|
223
|
-
|
|
224
|
-
let base = ''
|
|
225
|
-
if (chiffres.length > 0) base += chiffres.slice(0, 3)
|
|
226
|
-
if (chiffres.length > 3) base += '-' + chiffres.slice(3, 4)
|
|
227
|
-
if (chiffres.length > 4) base += '-' + chiffres.slice(4, 9)
|
|
228
|
-
if (chiffres.length > 9) base += '-' + chiffres.slice(9, 12)
|
|
229
|
-
|
|
230
|
-
if (!activerExtension || base.length < 15) return base
|
|
231
|
-
|
|
232
|
-
const reste = upper.slice(chiffres.length).replace(/[^A-Z0-9/]/gi, '')
|
|
233
|
-
|
|
234
|
-
// Extraire les 7 premiers caractères restants pour l’extension
|
|
235
|
-
let ext = reste.slice(0, 7).split('')
|
|
236
|
-
|
|
237
|
-
// Ne garder que le premier slash s’il est à l’index 0 ou 3
|
|
238
|
-
ext = ext.filter((c, i) => {
|
|
239
|
-
if (c !== '/') return true
|
|
240
|
-
return i === 0 || i === 3
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
// Enlever les slash non autorisés
|
|
244
|
-
ext = ext.map((c, i) => {
|
|
245
|
-
if (c === '/' && i !== 0 && i !== 3) return ''
|
|
246
|
-
if (c !== '/' && !/^[A-Z0-9]$/i.test(c)) return ''
|
|
247
|
-
return c
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
// Forcer le slash à la 4e position
|
|
251
|
-
if (ext.length > 3) {
|
|
252
|
-
ext[3] = '/'
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Réduire à 7 caractères
|
|
256
|
-
ext = ext.slice(0, 7)
|
|
257
|
-
|
|
258
|
-
return (base + ext.join('')).slice(0, 22)
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const gererPaste = (e: ClipboardEvent) => {
|
|
262
|
-
e.preventDefault()
|
|
263
|
-
const clipboardData = e.clipboardData
|
|
264
|
-
if (!clipboardData) return
|
|
265
|
-
let pasted = clipboardData.getData('text') || ''
|
|
266
|
-
codeBudgetaire.value = formaterCodeBudgetaire(pasted)
|
|
267
|
-
|
|
268
|
-
setTimeout(() => {
|
|
269
|
-
const input = e.target as HTMLInputElement
|
|
270
|
-
input.selectionStart = input.selectionEnd = codeBudgetaire.value.length
|
|
271
|
-
}, 0)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const sauvegarder = () => {
|
|
275
|
-
codeBudgetaire.value = formaterCodeBudgetaire(codeBudgetaire.value)
|
|
276
|
-
|
|
277
|
-
if (!estValideComplet.value) return
|
|
278
|
-
if (codeBudgetaire.value === derniereValeurSauvegardee.value) return
|
|
279
|
-
|
|
280
|
-
const codeNormalise = codeBudgetaire.value.trim().toUpperCase()
|
|
281
|
-
|
|
282
|
-
const existe = props.codeBudgetairesProp.some(item => {
|
|
283
|
-
const code = typeof item === 'string' ? item : item[0]
|
|
284
|
-
return code.trim().toUpperCase() === codeNormalise
|
|
285
|
-
})
|
|
286
|
-
|
|
287
|
-
if (!existe) {
|
|
288
|
-
const nouvelleListe = [...props.codeBudgetairesProp, codeBudgetaire.value]
|
|
289
|
-
emit('update:codeBudgetairesProp', nouvelleListe)
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
derniereValeurSauvegardee.value = codeBudgetaire.value
|
|
293
|
-
emit('update:modelValue', codeBudgetaire.value)
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
const extraireCode = (val: unknown): string => {
|
|
297
|
-
if (val == null) return ''
|
|
298
|
-
if (typeof val === 'string') return val
|
|
299
|
-
|
|
300
|
-
// Cas où Vuetify enverrait { code, label }
|
|
301
|
-
if (typeof val === 'object' && 'code' in (val as Record<string, unknown>)) {
|
|
302
|
-
const obj = val as { code?: unknown }
|
|
303
|
-
return typeof obj.code === 'string' ? obj.code : String(obj.code ?? '')
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return String(val)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const gererChangement = (val: unknown) => {
|
|
310
|
-
const code = extraireCode(val)
|
|
311
|
-
codeBudgetaire.value = formaterCodeBudgetaire(code)
|
|
312
|
-
|
|
313
|
-
const valeurFormatee = codeBudgetaire.value.trim().toUpperCase()
|
|
314
|
-
|
|
315
|
-
const estDansListe = props.codeBudgetairesProp.some(item => {
|
|
316
|
-
const codeItem = typeof item === 'string' ? item : item[0]
|
|
317
|
-
return codeItem.trim().toUpperCase() === valeurFormatee
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
estDansListe &&
|
|
322
|
-
valeurFormatee !== (derniereValeurSauvegardee.value ?? '').toUpperCase() &&
|
|
323
|
-
estValideComplet.value
|
|
324
|
-
) {
|
|
325
|
-
sauvegarder()
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
watch(
|
|
330
|
-
() => codeBudgetaire.value,
|
|
331
|
-
() => {
|
|
332
|
-
emit('update:valide', estValideComplet.value)
|
|
333
|
-
},
|
|
334
|
-
{ immediate: true },
|
|
335
|
-
)
|
|
336
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<v-form
|
|
4
|
+
ref="form"
|
|
5
|
+
v-model="formValide"
|
|
6
|
+
@submit.prevent
|
|
7
|
+
>
|
|
8
|
+
<v-combobox
|
|
9
|
+
v-model="codeBudgetaire"
|
|
10
|
+
:items="itemsCombobox"
|
|
11
|
+
item-value="code"
|
|
12
|
+
item-title="code"
|
|
13
|
+
:return-object="false"
|
|
14
|
+
v-bind="$attrs"
|
|
15
|
+
persistent-hint
|
|
16
|
+
variant="outlined"
|
|
17
|
+
hide-details="auto"
|
|
18
|
+
:error="!estValideComplet"
|
|
19
|
+
:rules="reglesVuetify"
|
|
20
|
+
:hint="afficherHint ? placeholder : ''"
|
|
21
|
+
@blur="sauvegarder"
|
|
22
|
+
@keydown.enter="sauvegarder"
|
|
23
|
+
@keydown="caractereAutorises"
|
|
24
|
+
@update:modelValue="gererChangement"
|
|
25
|
+
@paste="gererPaste"
|
|
26
|
+
>
|
|
27
|
+
<template #item="{ props, item }">
|
|
28
|
+
<v-list-item
|
|
29
|
+
v-bind="props"
|
|
30
|
+
:title="item.raw.nom || item.raw.code"
|
|
31
|
+
:subtitle="item.raw.nom ? item.raw.code : undefined"
|
|
32
|
+
/>
|
|
33
|
+
</template>
|
|
34
|
+
</v-combobox>
|
|
35
|
+
</v-form>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<script setup lang="ts">
|
|
40
|
+
import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
|
41
|
+
import type { VForm } from 'vuetify/components'
|
|
42
|
+
|
|
43
|
+
const emit = defineEmits<{
|
|
44
|
+
'update:modelValue': [string | null]
|
|
45
|
+
'update:codeBudgetairesProp': [CodeBudgetaireItem[]]
|
|
46
|
+
'update:valide': [boolean]
|
|
47
|
+
}>()
|
|
48
|
+
type CodeBudgetaireItem = string | [string, string]
|
|
49
|
+
|
|
50
|
+
const props = withDefaults(
|
|
51
|
+
defineProps<{
|
|
52
|
+
codeBudgetairesProp: CodeBudgetaireItem[]
|
|
53
|
+
modelValue: string | null
|
|
54
|
+
afficherHint?: boolean
|
|
55
|
+
regleMessageErreur: string
|
|
56
|
+
format?: string
|
|
57
|
+
activerExtension?: boolean
|
|
58
|
+
reglesSupp?: ((v: string) => true | string)[]
|
|
59
|
+
}>(),
|
|
60
|
+
{
|
|
61
|
+
afficherHint: false,
|
|
62
|
+
format: '999-9-99999-999',
|
|
63
|
+
activerExtension: false,
|
|
64
|
+
reglesSupp: () => [],
|
|
65
|
+
},
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const formValide = ref(false)
|
|
69
|
+
const form = ref<VForm | null>(null)
|
|
70
|
+
const codeBudgetaire = ref(props.modelValue ?? '')
|
|
71
|
+
const derniereValeurSauvegardee = ref<string | null>(null)
|
|
72
|
+
const format = props.format
|
|
73
|
+
const activerExtension = props.activerExtension
|
|
74
|
+
|
|
75
|
+
onMounted(() => {
|
|
76
|
+
derniereValeurSauvegardee.value = codeBudgetaire.value
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
const itemsCombobox = computed(() => {
|
|
80
|
+
return props.codeBudgetairesProp.map(item => {
|
|
81
|
+
if (typeof item === 'string') {
|
|
82
|
+
return {
|
|
83
|
+
code: item,
|
|
84
|
+
nom: '', // pas de nom
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const [code, nomBrut] = item
|
|
89
|
+
const nom = (nomBrut ?? '').toString().trim()
|
|
90
|
+
|
|
91
|
+
return { code, nom }
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
const placeholder = computed(() => {
|
|
96
|
+
const base = format.replace(/9/g, '0')
|
|
97
|
+
const extension = activerExtension ? '-XXX/XXX' : ''
|
|
98
|
+
return base + extension
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const estValide = computed(() => {
|
|
102
|
+
const val = codeBudgetaire.value?.toUpperCase().trim() || ''
|
|
103
|
+
const base = val.slice(0, 15)
|
|
104
|
+
const extension = val.slice(15)
|
|
105
|
+
|
|
106
|
+
if (!/^\d{3}-\d{1}-\d{5}-\d{3}$/.test(base)) return false
|
|
107
|
+
|
|
108
|
+
if (!activerExtension) return val.length === 15
|
|
109
|
+
|
|
110
|
+
if (val.length === 15) return true
|
|
111
|
+
if (val.length !== 22) return false
|
|
112
|
+
if (extension.length !== 7) return false
|
|
113
|
+
|
|
114
|
+
if (extension[3] !== '/') return false
|
|
115
|
+
if (!/^[A-Z0-9/]$/i.test(extension[0]!)) return false
|
|
116
|
+
|
|
117
|
+
const alphanumAt = [1, 2, 4, 5, 6]
|
|
118
|
+
return alphanumAt.every(i => /^[A-Z0-9]$/i.test(extension[i]!))
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// Règles Vuetify combinées (interne + supplémentaires)
|
|
122
|
+
const reglesVuetify = computed(() => [
|
|
123
|
+
// règle interne
|
|
124
|
+
() => (estValide.value ? true : props.regleMessageErreur),
|
|
125
|
+
|
|
126
|
+
// règles supplémentaires venant du parent
|
|
127
|
+
...props.reglesSupp.map(rule => {
|
|
128
|
+
return () => rule(codeBudgetaire.value) // on passe la valeur formatée
|
|
129
|
+
}),
|
|
130
|
+
])
|
|
131
|
+
|
|
132
|
+
// Validité globale du composant (interne + toutes les règles supp)
|
|
133
|
+
const estValideComplet = computed(() => {
|
|
134
|
+
if (!estValide.value) return false
|
|
135
|
+
return props.reglesSupp.every(rule => rule(codeBudgetaire.value) === true)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
const caractereAutorises = (e: KeyboardEvent) => {
|
|
139
|
+
if (e.ctrlKey || e.metaKey) return
|
|
140
|
+
|
|
141
|
+
const touchesSpecifiques = ['Backspace', 'Delete', 'ArrowLeft', 'ArrowRight', 'Tab', 'Home', 'End']
|
|
142
|
+
if (touchesSpecifiques.includes(e.key)) return
|
|
143
|
+
|
|
144
|
+
const input = e.target as HTMLInputElement
|
|
145
|
+
let position = input.selectionStart ?? 0
|
|
146
|
+
|
|
147
|
+
// Gestion de la partie de base (15 premiers caractères)
|
|
148
|
+
if (position < 15) {
|
|
149
|
+
if (!/^\d$/.test(e.key)) {
|
|
150
|
+
e.preventDefault()
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Insérer chiffre et auto-ajout des tirets
|
|
155
|
+
e.preventDefault()
|
|
156
|
+
|
|
157
|
+
const value = codeBudgetaire.value.replace(/-/g, '')
|
|
158
|
+
const clean = value.slice(0, 12) + e.key
|
|
159
|
+
|
|
160
|
+
let formatted = ''
|
|
161
|
+
if (clean.length > 0) formatted += clean.slice(0, 3)
|
|
162
|
+
if (clean.length > 3) formatted += '-' + clean.slice(3, 4)
|
|
163
|
+
if (clean.length > 4) formatted += '-' + clean.slice(4, 9)
|
|
164
|
+
if (clean.length > 9) formatted += '-' + clean.slice(9, 12)
|
|
165
|
+
|
|
166
|
+
codeBudgetaire.value = formatted.slice(0, 15)
|
|
167
|
+
|
|
168
|
+
nextTick(() => {
|
|
169
|
+
const newPos = codeBudgetaire.value.length
|
|
170
|
+
input.selectionStart = input.selectionEnd = newPos
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// --- Gestion de l'extension ---
|
|
177
|
+
if (!activerExtension || position >= 22 || codeBudgetaire.value.length >= 22) {
|
|
178
|
+
e.preventDefault()
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const extensionPos = position - 15
|
|
183
|
+
|
|
184
|
+
// Règle 1 : extension[0] = alphanum ou /
|
|
185
|
+
if (extensionPos === 0) {
|
|
186
|
+
if (!/^[A-Z0-9/]$/i.test(e.key)) {
|
|
187
|
+
e.preventDefault()
|
|
188
|
+
return
|
|
189
|
+
}
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Règle 2 : extension[1,2,4,5,6] = alphanum
|
|
194
|
+
if ([1, 2, 4, 5, 6].includes(extensionPos)) {
|
|
195
|
+
if (!/^[A-Z0-9]$/i.test(e.key)) {
|
|
196
|
+
e.preventDefault()
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Règle 3 : slash automatique à position 3 (index 18)
|
|
203
|
+
if (extensionPos === 3) {
|
|
204
|
+
e.preventDefault()
|
|
205
|
+
const before = codeBudgetaire.value.slice(0, position)
|
|
206
|
+
const after = codeBudgetaire.value.slice(position)
|
|
207
|
+
codeBudgetaire.value = before + '/' + after
|
|
208
|
+
nextTick(() => {
|
|
209
|
+
input.selectionStart = input.selectionEnd = position + 1
|
|
210
|
+
})
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Tout autre cas = bloqué
|
|
215
|
+
e.preventDefault()
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const formaterCodeBudgetaire = (valeur: string): string => {
|
|
219
|
+
if (!valeur) return ''
|
|
220
|
+
|
|
221
|
+
const upper = valeur.toUpperCase().replace(/[^A-Z0-9/]/g, '')
|
|
222
|
+
const chiffres = upper.replace(/[^0-9]/g, '').slice(0, 12)
|
|
223
|
+
|
|
224
|
+
let base = ''
|
|
225
|
+
if (chiffres.length > 0) base += chiffres.slice(0, 3)
|
|
226
|
+
if (chiffres.length > 3) base += '-' + chiffres.slice(3, 4)
|
|
227
|
+
if (chiffres.length > 4) base += '-' + chiffres.slice(4, 9)
|
|
228
|
+
if (chiffres.length > 9) base += '-' + chiffres.slice(9, 12)
|
|
229
|
+
|
|
230
|
+
if (!activerExtension || base.length < 15) return base
|
|
231
|
+
|
|
232
|
+
const reste = upper.slice(chiffres.length).replace(/[^A-Z0-9/]/gi, '')
|
|
233
|
+
|
|
234
|
+
// Extraire les 7 premiers caractères restants pour l’extension
|
|
235
|
+
let ext = reste.slice(0, 7).split('')
|
|
236
|
+
|
|
237
|
+
// Ne garder que le premier slash s’il est à l’index 0 ou 3
|
|
238
|
+
ext = ext.filter((c, i) => {
|
|
239
|
+
if (c !== '/') return true
|
|
240
|
+
return i === 0 || i === 3
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
// Enlever les slash non autorisés
|
|
244
|
+
ext = ext.map((c, i) => {
|
|
245
|
+
if (c === '/' && i !== 0 && i !== 3) return ''
|
|
246
|
+
if (c !== '/' && !/^[A-Z0-9]$/i.test(c)) return ''
|
|
247
|
+
return c
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
// Forcer le slash à la 4e position
|
|
251
|
+
if (ext.length > 3) {
|
|
252
|
+
ext[3] = '/'
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Réduire à 7 caractères
|
|
256
|
+
ext = ext.slice(0, 7)
|
|
257
|
+
|
|
258
|
+
return (base + ext.join('')).slice(0, 22)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const gererPaste = (e: ClipboardEvent) => {
|
|
262
|
+
e.preventDefault()
|
|
263
|
+
const clipboardData = e.clipboardData
|
|
264
|
+
if (!clipboardData) return
|
|
265
|
+
let pasted = clipboardData.getData('text') || ''
|
|
266
|
+
codeBudgetaire.value = formaterCodeBudgetaire(pasted)
|
|
267
|
+
|
|
268
|
+
setTimeout(() => {
|
|
269
|
+
const input = e.target as HTMLInputElement
|
|
270
|
+
input.selectionStart = input.selectionEnd = codeBudgetaire.value.length
|
|
271
|
+
}, 0)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const sauvegarder = () => {
|
|
275
|
+
codeBudgetaire.value = formaterCodeBudgetaire(codeBudgetaire.value)
|
|
276
|
+
|
|
277
|
+
if (!estValideComplet.value) return
|
|
278
|
+
if (codeBudgetaire.value === derniereValeurSauvegardee.value) return
|
|
279
|
+
|
|
280
|
+
const codeNormalise = codeBudgetaire.value.trim().toUpperCase()
|
|
281
|
+
|
|
282
|
+
const existe = props.codeBudgetairesProp.some(item => {
|
|
283
|
+
const code = typeof item === 'string' ? item : item[0]
|
|
284
|
+
return code.trim().toUpperCase() === codeNormalise
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
if (!existe) {
|
|
288
|
+
const nouvelleListe = [...props.codeBudgetairesProp, codeBudgetaire.value]
|
|
289
|
+
emit('update:codeBudgetairesProp', nouvelleListe)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
derniereValeurSauvegardee.value = codeBudgetaire.value
|
|
293
|
+
emit('update:modelValue', codeBudgetaire.value)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const extraireCode = (val: unknown): string => {
|
|
297
|
+
if (val == null) return ''
|
|
298
|
+
if (typeof val === 'string') return val
|
|
299
|
+
|
|
300
|
+
// Cas où Vuetify enverrait { code, label }
|
|
301
|
+
if (typeof val === 'object' && 'code' in (val as Record<string, unknown>)) {
|
|
302
|
+
const obj = val as { code?: unknown }
|
|
303
|
+
return typeof obj.code === 'string' ? obj.code : String(obj.code ?? '')
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return String(val)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const gererChangement = (val: unknown) => {
|
|
310
|
+
const code = extraireCode(val)
|
|
311
|
+
codeBudgetaire.value = formaterCodeBudgetaire(code)
|
|
312
|
+
|
|
313
|
+
const valeurFormatee = codeBudgetaire.value.trim().toUpperCase()
|
|
314
|
+
|
|
315
|
+
const estDansListe = props.codeBudgetairesProp.some(item => {
|
|
316
|
+
const codeItem = typeof item === 'string' ? item : item[0]
|
|
317
|
+
return codeItem.trim().toUpperCase() === valeurFormatee
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
if (
|
|
321
|
+
estDansListe &&
|
|
322
|
+
valeurFormatee !== (derniereValeurSauvegardee.value ?? '').toUpperCase() &&
|
|
323
|
+
estValideComplet.value
|
|
324
|
+
) {
|
|
325
|
+
sauvegarder()
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
watch(
|
|
330
|
+
() => codeBudgetaire.value,
|
|
331
|
+
() => {
|
|
332
|
+
emit('update:valide', estValideComplet.value)
|
|
333
|
+
},
|
|
334
|
+
{ immediate: true },
|
|
335
|
+
)
|
|
336
|
+
</script>
|