codevdesign 1.0.38 → 1.0.40
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 -97
- package/composants/csqcOptionSwitch.vue +120 -120
- package/composants/csqcRecherche.vue +213 -213
- package/composants/csqcRechercheUtilisateur.vue +198 -197
- 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,163 +1,163 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<v-app-bar
|
|
3
|
-
:color="barreCouleur"
|
|
4
|
-
class="px-0 mx-0"
|
|
5
|
-
:style="{
|
|
6
|
-
position: 'sticky',
|
|
7
|
-
// variables CSS pour les couleurs dynamiques
|
|
8
|
-
'--entete-texte': texteCouleur,
|
|
9
|
-
'--entete-icone': iconeCouleur,
|
|
10
|
-
}"
|
|
11
|
-
height="82px"
|
|
12
|
-
>
|
|
13
|
-
<v-row
|
|
14
|
-
class="pt-2"
|
|
15
|
-
@resize="controlAffichage"
|
|
16
|
-
>
|
|
17
|
-
<v-col
|
|
18
|
-
:cols="titreCol"
|
|
19
|
-
class="pr-0 mr-0 pl-5"
|
|
20
|
-
>
|
|
21
|
-
<v-toolbar-title class="titre">
|
|
22
|
-
<!-- Barre de retour -->
|
|
23
|
-
<slot name="retour">
|
|
24
|
-
<v-icon
|
|
25
|
-
v-if="retour"
|
|
26
|
-
size="large"
|
|
27
|
-
start
|
|
28
|
-
:color="iconeCouleur"
|
|
29
|
-
icon="mdi-arrow-left-thin"
|
|
30
|
-
@click="retournerMenu"
|
|
31
|
-
/>
|
|
32
|
-
</slot>
|
|
33
|
-
|
|
34
|
-
<div class="titre-bloc">
|
|
35
|
-
<!-- Titre -->
|
|
36
|
-
<slot name="titre">
|
|
37
|
-
<span class="pl-3 titre-texte">{{ props.titre }}</span>
|
|
38
|
-
</slot>
|
|
39
|
-
|
|
40
|
-
<!-- État -->
|
|
41
|
-
<slot name="etat">
|
|
42
|
-
<span
|
|
43
|
-
v-if="monEtat?.afficher"
|
|
44
|
-
class="pl-10"
|
|
45
|
-
>
|
|
46
|
-
<v-btn
|
|
47
|
-
size="small"
|
|
48
|
-
:color="monEtat.couleur"
|
|
49
|
-
variant="tonal"
|
|
50
|
-
>
|
|
51
|
-
{{ monEtat.texte }}
|
|
52
|
-
</v-btn>
|
|
53
|
-
</span>
|
|
54
|
-
</slot>
|
|
55
|
-
|
|
56
|
-
<!-- État secondaire -->
|
|
57
|
-
<slot name="etatSecondaire">
|
|
58
|
-
<span
|
|
59
|
-
v-if="monEtatSecondaire?.afficher"
|
|
60
|
-
class="pl-3"
|
|
61
|
-
>
|
|
62
|
-
<v-btn
|
|
63
|
-
size="small"
|
|
64
|
-
:color="monEtatSecondaire.couleur"
|
|
65
|
-
variant="tonal"
|
|
66
|
-
>
|
|
67
|
-
{{ monEtatSecondaire.texte }}
|
|
68
|
-
</v-btn>
|
|
69
|
-
</span>
|
|
70
|
-
</slot>
|
|
71
|
-
|
|
72
|
-
<!-- Sous-titre -->
|
|
73
|
-
<slot name="soustitre">
|
|
74
|
-
<span class="pl-3 soustitre-texte">{{ props.soustitre }}</span>
|
|
75
|
-
</slot>
|
|
76
|
-
</div>
|
|
77
|
-
</v-toolbar-title>
|
|
78
|
-
</v-col>
|
|
79
|
-
</v-row>
|
|
80
|
-
|
|
81
|
-
<!-- Barre en bas -->
|
|
82
|
-
<div style="position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background-color: #808a9d" />
|
|
83
|
-
</v-app-bar>
|
|
84
|
-
</template>
|
|
85
|
-
|
|
86
|
-
<script setup lang="ts">
|
|
87
|
-
import { useRouter } from 'vue-router'
|
|
88
|
-
import { ref, computed } from 'vue'
|
|
89
|
-
|
|
90
|
-
interface EnteteEtat {
|
|
91
|
-
afficher: boolean
|
|
92
|
-
couleur: string
|
|
93
|
-
texte: string
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
interface EnteteEtatSecondaire {
|
|
97
|
-
afficher: boolean
|
|
98
|
-
couleur: string
|
|
99
|
-
texte: string
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const router = useRouter()
|
|
103
|
-
|
|
104
|
-
const props = defineProps<{
|
|
105
|
-
titre: string
|
|
106
|
-
soustitre?: string
|
|
107
|
-
retour?: string
|
|
108
|
-
etat?: EnteteEtat
|
|
109
|
-
couleur?: string // couleur de la barre (Vuetify color/hex)
|
|
110
|
-
couleurTexte?: string
|
|
111
|
-
couleurIcone?: string
|
|
112
|
-
etatSecondaire?: EnteteEtatSecondaire
|
|
113
|
-
}>()
|
|
114
|
-
|
|
115
|
-
const titreCol = ref(12)
|
|
116
|
-
|
|
117
|
-
// Fallbacks (tes valeurs actuelles)
|
|
118
|
-
const barreCouleur = computed(() => props.couleur ?? 'white')
|
|
119
|
-
const texteCouleur = computed(() => props.couleurTexte ?? '#223654')
|
|
120
|
-
const iconeCouleur = computed(() => props.couleurIcone ?? 'grisMoyen') // peut être un nom de couleur Vuetify ou un hex
|
|
121
|
-
|
|
122
|
-
const monEtat = computed<EnteteEtat>(() => props.etat ?? { afficher: false, couleur: 'primary', texte: 'test' })
|
|
123
|
-
const monEtatSecondaire = computed<EnteteEtatSecondaire>(
|
|
124
|
-
() => props.etatSecondaire ?? { afficher: false, couleur: 'primary', texte: 'test' },
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
function retournerMenu() {
|
|
128
|
-
if (props.retour) router.push({ name: props.retour })
|
|
129
|
-
}
|
|
130
|
-
function controlAffichage() {
|
|
131
|
-
/* logique resize */
|
|
132
|
-
}
|
|
133
|
-
</script>
|
|
134
|
-
|
|
135
|
-
<style scoped>
|
|
136
|
-
.titre {
|
|
137
|
-
font-size: 1.85rem;
|
|
138
|
-
font-weight: bold;
|
|
139
|
-
margin-bottom: 15px;
|
|
140
|
-
}
|
|
141
|
-
.titre-texte {
|
|
142
|
-
color: var(--entete-texte, #223654);
|
|
143
|
-
}
|
|
144
|
-
.soustitre-texte {
|
|
145
|
-
display: block;
|
|
146
|
-
font-size: 1rem;
|
|
147
|
-
font-weight: normal;
|
|
148
|
-
color: var(--entete-texte, #223654);
|
|
149
|
-
}
|
|
150
|
-
.titre-bloc {
|
|
151
|
-
display: inline-block;
|
|
152
|
-
vertical-align: middle;
|
|
153
|
-
padding-left: 12px;
|
|
154
|
-
}
|
|
155
|
-
/* Couleur de l’icône (retour) + hover */
|
|
156
|
-
.v-icon {
|
|
157
|
-
color: var(--entete-icone, #6b7280); /* grisMoyen approx si hex */
|
|
158
|
-
}
|
|
159
|
-
.v-icon:hover {
|
|
160
|
-
/* tu peux garder une couleur fixe ou calculer une teinte plus foncée si besoin */
|
|
161
|
-
filter: brightness(0.85);
|
|
162
|
-
}
|
|
163
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<v-app-bar
|
|
3
|
+
:color="barreCouleur"
|
|
4
|
+
class="px-0 mx-0"
|
|
5
|
+
:style="{
|
|
6
|
+
position: 'sticky',
|
|
7
|
+
// variables CSS pour les couleurs dynamiques
|
|
8
|
+
'--entete-texte': texteCouleur,
|
|
9
|
+
'--entete-icone': iconeCouleur,
|
|
10
|
+
}"
|
|
11
|
+
height="82px"
|
|
12
|
+
>
|
|
13
|
+
<v-row
|
|
14
|
+
class="pt-2"
|
|
15
|
+
@resize="controlAffichage"
|
|
16
|
+
>
|
|
17
|
+
<v-col
|
|
18
|
+
:cols="titreCol"
|
|
19
|
+
class="pr-0 mr-0 pl-5"
|
|
20
|
+
>
|
|
21
|
+
<v-toolbar-title class="titre">
|
|
22
|
+
<!-- Barre de retour -->
|
|
23
|
+
<slot name="retour">
|
|
24
|
+
<v-icon
|
|
25
|
+
v-if="retour"
|
|
26
|
+
size="large"
|
|
27
|
+
start
|
|
28
|
+
:color="iconeCouleur"
|
|
29
|
+
icon="mdi-arrow-left-thin"
|
|
30
|
+
@click="retournerMenu"
|
|
31
|
+
/>
|
|
32
|
+
</slot>
|
|
33
|
+
|
|
34
|
+
<div class="titre-bloc">
|
|
35
|
+
<!-- Titre -->
|
|
36
|
+
<slot name="titre">
|
|
37
|
+
<span class="pl-3 titre-texte">{{ props.titre }}</span>
|
|
38
|
+
</slot>
|
|
39
|
+
|
|
40
|
+
<!-- État -->
|
|
41
|
+
<slot name="etat">
|
|
42
|
+
<span
|
|
43
|
+
v-if="monEtat?.afficher"
|
|
44
|
+
class="pl-10"
|
|
45
|
+
>
|
|
46
|
+
<v-btn
|
|
47
|
+
size="small"
|
|
48
|
+
:color="monEtat.couleur"
|
|
49
|
+
variant="tonal"
|
|
50
|
+
>
|
|
51
|
+
{{ monEtat.texte }}
|
|
52
|
+
</v-btn>
|
|
53
|
+
</span>
|
|
54
|
+
</slot>
|
|
55
|
+
|
|
56
|
+
<!-- État secondaire -->
|
|
57
|
+
<slot name="etatSecondaire">
|
|
58
|
+
<span
|
|
59
|
+
v-if="monEtatSecondaire?.afficher"
|
|
60
|
+
class="pl-3"
|
|
61
|
+
>
|
|
62
|
+
<v-btn
|
|
63
|
+
size="small"
|
|
64
|
+
:color="monEtatSecondaire.couleur"
|
|
65
|
+
variant="tonal"
|
|
66
|
+
>
|
|
67
|
+
{{ monEtatSecondaire.texte }}
|
|
68
|
+
</v-btn>
|
|
69
|
+
</span>
|
|
70
|
+
</slot>
|
|
71
|
+
|
|
72
|
+
<!-- Sous-titre -->
|
|
73
|
+
<slot name="soustitre">
|
|
74
|
+
<span class="pl-3 soustitre-texte">{{ props.soustitre }}</span>
|
|
75
|
+
</slot>
|
|
76
|
+
</div>
|
|
77
|
+
</v-toolbar-title>
|
|
78
|
+
</v-col>
|
|
79
|
+
</v-row>
|
|
80
|
+
|
|
81
|
+
<!-- Barre en bas -->
|
|
82
|
+
<div style="position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background-color: #808a9d" />
|
|
83
|
+
</v-app-bar>
|
|
84
|
+
</template>
|
|
85
|
+
|
|
86
|
+
<script setup lang="ts">
|
|
87
|
+
import { useRouter } from 'vue-router'
|
|
88
|
+
import { ref, computed } from 'vue'
|
|
89
|
+
|
|
90
|
+
interface EnteteEtat {
|
|
91
|
+
afficher: boolean
|
|
92
|
+
couleur: string
|
|
93
|
+
texte: string
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface EnteteEtatSecondaire {
|
|
97
|
+
afficher: boolean
|
|
98
|
+
couleur: string
|
|
99
|
+
texte: string
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const router = useRouter()
|
|
103
|
+
|
|
104
|
+
const props = defineProps<{
|
|
105
|
+
titre: string
|
|
106
|
+
soustitre?: string
|
|
107
|
+
retour?: string
|
|
108
|
+
etat?: EnteteEtat
|
|
109
|
+
couleur?: string // couleur de la barre (Vuetify color/hex)
|
|
110
|
+
couleurTexte?: string
|
|
111
|
+
couleurIcone?: string
|
|
112
|
+
etatSecondaire?: EnteteEtatSecondaire
|
|
113
|
+
}>()
|
|
114
|
+
|
|
115
|
+
const titreCol = ref(12)
|
|
116
|
+
|
|
117
|
+
// Fallbacks (tes valeurs actuelles)
|
|
118
|
+
const barreCouleur = computed(() => props.couleur ?? 'white')
|
|
119
|
+
const texteCouleur = computed(() => props.couleurTexte ?? '#223654')
|
|
120
|
+
const iconeCouleur = computed(() => props.couleurIcone ?? 'grisMoyen') // peut être un nom de couleur Vuetify ou un hex
|
|
121
|
+
|
|
122
|
+
const monEtat = computed<EnteteEtat>(() => props.etat ?? { afficher: false, couleur: 'primary', texte: 'test' })
|
|
123
|
+
const monEtatSecondaire = computed<EnteteEtatSecondaire>(
|
|
124
|
+
() => props.etatSecondaire ?? { afficher: false, couleur: 'primary', texte: 'test' },
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
function retournerMenu() {
|
|
128
|
+
if (props.retour) router.push({ name: props.retour })
|
|
129
|
+
}
|
|
130
|
+
function controlAffichage() {
|
|
131
|
+
/* logique resize */
|
|
132
|
+
}
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<style scoped>
|
|
136
|
+
.titre {
|
|
137
|
+
font-size: 1.85rem;
|
|
138
|
+
font-weight: bold;
|
|
139
|
+
margin-bottom: 15px;
|
|
140
|
+
}
|
|
141
|
+
.titre-texte {
|
|
142
|
+
color: var(--entete-texte, #223654);
|
|
143
|
+
}
|
|
144
|
+
.soustitre-texte {
|
|
145
|
+
display: block;
|
|
146
|
+
font-size: 1rem;
|
|
147
|
+
font-weight: normal;
|
|
148
|
+
color: var(--entete-texte, #223654);
|
|
149
|
+
}
|
|
150
|
+
.titre-bloc {
|
|
151
|
+
display: inline-block;
|
|
152
|
+
vertical-align: middle;
|
|
153
|
+
padding-left: 12px;
|
|
154
|
+
}
|
|
155
|
+
/* Couleur de l’icône (retour) + hover */
|
|
156
|
+
.v-icon {
|
|
157
|
+
color: var(--entete-icone, #6b7280); /* grisMoyen approx si hex */
|
|
158
|
+
}
|
|
159
|
+
.v-icon:hover {
|
|
160
|
+
/* tu peux garder une couleur fixe ou calculer une teinte plus foncée si besoin */
|
|
161
|
+
filter: brightness(0.85);
|
|
162
|
+
}
|
|
163
|
+
</style>
|
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<v-btn
|
|
4
|
-
color="success"
|
|
5
|
-
variant="outlined"
|
|
6
|
-
:loading="chargement"
|
|
7
|
-
class="elevation-0"
|
|
8
|
-
@click="importCsv"
|
|
9
|
-
>
|
|
10
|
-
{{ boutonTexte }}
|
|
11
|
-
<template #append>
|
|
12
|
-
<v-icon icon="mdi-microsoft-excel"></v-icon>
|
|
13
|
-
</template>
|
|
14
|
-
</v-btn>
|
|
15
|
-
|
|
16
|
-
<input
|
|
17
|
-
ref="fileInput"
|
|
18
|
-
type="file"
|
|
19
|
-
accept=".csv"
|
|
20
|
-
style="display: none"
|
|
21
|
-
@change="handleFileUpload"
|
|
22
|
-
/>
|
|
23
|
-
</div>
|
|
24
|
-
</template>
|
|
25
|
-
|
|
26
|
-
<script setup lang="ts">
|
|
27
|
-
import { ref, computed } from 'vue'
|
|
28
|
-
import { useI18n } from 'vue-i18n'
|
|
29
|
-
|
|
30
|
-
// Props
|
|
31
|
-
const props = withDefaults(
|
|
32
|
-
defineProps<{
|
|
33
|
-
boutonTexte?: string
|
|
34
|
-
erreurTexte?: string
|
|
35
|
-
chargement?: boolean
|
|
36
|
-
}>(),
|
|
37
|
-
{
|
|
38
|
-
chargement: false, // défaut
|
|
39
|
-
},
|
|
40
|
-
)
|
|
41
|
-
const emit = defineEmits(['import', 'import-erreur'])
|
|
42
|
-
|
|
43
|
-
const { t } = useI18n()
|
|
44
|
-
|
|
45
|
-
const boutonTexte = computed(() => props.boutonTexte ?? t('csqc.bouton.importer'))
|
|
46
|
-
const erreurTexte = computed(() => props.erreurTexte ?? t('csqc.csqcImportCSV.erreur.lectureFichier'))
|
|
47
|
-
|
|
48
|
-
// Références
|
|
49
|
-
const fileInput = ref<HTMLInputElement | null>(null)
|
|
50
|
-
const csvFile = ref<File | null>(null)
|
|
51
|
-
|
|
52
|
-
// Méthodes
|
|
53
|
-
function importCsv() {
|
|
54
|
-
fileInput.value?.click()
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function handleFileUpload(event: Event) {
|
|
58
|
-
const target = event.target as HTMLInputElement
|
|
59
|
-
const file = target.files?.[0]
|
|
60
|
-
|
|
61
|
-
if (file?.name.toLowerCase().endsWith('.csv')) {
|
|
62
|
-
csvFile.value = file
|
|
63
|
-
|
|
64
|
-
const reader = new FileReader()
|
|
65
|
-
|
|
66
|
-
reader.onload = () => {
|
|
67
|
-
try {
|
|
68
|
-
let text = reader.result as string
|
|
69
|
-
|
|
70
|
-
// Supprime BOM UTF-8 si présent
|
|
71
|
-
if (text.charCodeAt(0) === 0xfeff) {
|
|
72
|
-
text = text.slice(1)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const lignes = text
|
|
76
|
-
.trim()
|
|
77
|
-
.split(/\r?\n/)
|
|
78
|
-
.filter(row => row.trim() !== '') // ignore lignes vides
|
|
79
|
-
|
|
80
|
-
if (lignes.length === 0) {
|
|
81
|
-
emit('import-erreur', 'Le fichier CSV est vide.')
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Détection automatique du séparateur
|
|
86
|
-
const separateur = detecterSeparateur(lignes[0]!)
|
|
87
|
-
|
|
88
|
-
// Découpage des lignes
|
|
89
|
-
const data: string[][] = lignes.map(row => row.split(separateur).map(cell => cell.trim()))
|
|
90
|
-
|
|
91
|
-
emit('import', data)
|
|
92
|
-
} catch (error) {
|
|
93
|
-
emit('import-erreur', erreurTexte || t('csqc.csqcImportCSV.erreur.lectureFichier'))
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
reader.onerror = () => {
|
|
98
|
-
emit('import-erreur', t('csqc.csqcImportCSV.erreur.lectureFichier'))
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
reader.readAsText(file)
|
|
102
|
-
} else {
|
|
103
|
-
const message = erreurTexte || t('csqc.csqcImportCSV.erreur.erreur')
|
|
104
|
-
emit('import-erreur', message)
|
|
105
|
-
csvFile.value = null
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Fonction pour détecter le séparateur le plus probable
|
|
110
|
-
function detecterSeparateur(ligne: string): string {
|
|
111
|
-
const separateursTestés = [',', ';', '\t', '|']
|
|
112
|
-
let meilleurSeparateur = ','
|
|
113
|
-
let maxColonnes = 0
|
|
114
|
-
|
|
115
|
-
for (const sep of separateursTestés) {
|
|
116
|
-
const nb = ligne.split(sep).length
|
|
117
|
-
if (nb > maxColonnes) {
|
|
118
|
-
maxColonnes = nb
|
|
119
|
-
meilleurSeparateur = sep
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return meilleurSeparateur
|
|
124
|
-
}
|
|
125
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<v-btn
|
|
4
|
+
color="success"
|
|
5
|
+
variant="outlined"
|
|
6
|
+
:loading="chargement"
|
|
7
|
+
class="elevation-0"
|
|
8
|
+
@click="importCsv"
|
|
9
|
+
>
|
|
10
|
+
{{ boutonTexte }}
|
|
11
|
+
<template #append>
|
|
12
|
+
<v-icon icon="mdi-microsoft-excel"></v-icon>
|
|
13
|
+
</template>
|
|
14
|
+
</v-btn>
|
|
15
|
+
|
|
16
|
+
<input
|
|
17
|
+
ref="fileInput"
|
|
18
|
+
type="file"
|
|
19
|
+
accept=".csv"
|
|
20
|
+
style="display: none"
|
|
21
|
+
@change="handleFileUpload"
|
|
22
|
+
/>
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script setup lang="ts">
|
|
27
|
+
import { ref, computed } from 'vue'
|
|
28
|
+
import { useI18n } from 'vue-i18n'
|
|
29
|
+
|
|
30
|
+
// Props
|
|
31
|
+
const props = withDefaults(
|
|
32
|
+
defineProps<{
|
|
33
|
+
boutonTexte?: string
|
|
34
|
+
erreurTexte?: string
|
|
35
|
+
chargement?: boolean
|
|
36
|
+
}>(),
|
|
37
|
+
{
|
|
38
|
+
chargement: false, // défaut
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
const emit = defineEmits(['import', 'import-erreur'])
|
|
42
|
+
|
|
43
|
+
const { t } = useI18n()
|
|
44
|
+
|
|
45
|
+
const boutonTexte = computed(() => props.boutonTexte ?? t('csqc.bouton.importer'))
|
|
46
|
+
const erreurTexte = computed(() => props.erreurTexte ?? t('csqc.csqcImportCSV.erreur.lectureFichier'))
|
|
47
|
+
|
|
48
|
+
// Références
|
|
49
|
+
const fileInput = ref<HTMLInputElement | null>(null)
|
|
50
|
+
const csvFile = ref<File | null>(null)
|
|
51
|
+
|
|
52
|
+
// Méthodes
|
|
53
|
+
function importCsv() {
|
|
54
|
+
fileInput.value?.click()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function handleFileUpload(event: Event) {
|
|
58
|
+
const target = event.target as HTMLInputElement
|
|
59
|
+
const file = target.files?.[0]
|
|
60
|
+
|
|
61
|
+
if (file?.name.toLowerCase().endsWith('.csv')) {
|
|
62
|
+
csvFile.value = file
|
|
63
|
+
|
|
64
|
+
const reader = new FileReader()
|
|
65
|
+
|
|
66
|
+
reader.onload = () => {
|
|
67
|
+
try {
|
|
68
|
+
let text = reader.result as string
|
|
69
|
+
|
|
70
|
+
// Supprime BOM UTF-8 si présent
|
|
71
|
+
if (text.charCodeAt(0) === 0xfeff) {
|
|
72
|
+
text = text.slice(1)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const lignes = text
|
|
76
|
+
.trim()
|
|
77
|
+
.split(/\r?\n/)
|
|
78
|
+
.filter(row => row.trim() !== '') // ignore lignes vides
|
|
79
|
+
|
|
80
|
+
if (lignes.length === 0) {
|
|
81
|
+
emit('import-erreur', 'Le fichier CSV est vide.')
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Détection automatique du séparateur
|
|
86
|
+
const separateur = detecterSeparateur(lignes[0]!)
|
|
87
|
+
|
|
88
|
+
// Découpage des lignes
|
|
89
|
+
const data: string[][] = lignes.map(row => row.split(separateur).map(cell => cell.trim()))
|
|
90
|
+
|
|
91
|
+
emit('import', data)
|
|
92
|
+
} catch (error) {
|
|
93
|
+
emit('import-erreur', erreurTexte || t('csqc.csqcImportCSV.erreur.lectureFichier'))
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
reader.onerror = () => {
|
|
98
|
+
emit('import-erreur', t('csqc.csqcImportCSV.erreur.lectureFichier'))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
reader.readAsText(file)
|
|
102
|
+
} else {
|
|
103
|
+
const message = erreurTexte || t('csqc.csqcImportCSV.erreur.erreur')
|
|
104
|
+
emit('import-erreur', message)
|
|
105
|
+
csvFile.value = null
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Fonction pour détecter le séparateur le plus probable
|
|
110
|
+
function detecterSeparateur(ligne: string): string {
|
|
111
|
+
const separateursTestés = [',', ';', '\t', '|']
|
|
112
|
+
let meilleurSeparateur = ','
|
|
113
|
+
let maxColonnes = 0
|
|
114
|
+
|
|
115
|
+
for (const sep of separateursTestés) {
|
|
116
|
+
const nb = ligne.split(sep).length
|
|
117
|
+
if (nb > maxColonnes) {
|
|
118
|
+
maxColonnes = nb
|
|
119
|
+
meilleurSeparateur = sep
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return meilleurSeparateur
|
|
124
|
+
}
|
|
125
|
+
</script>
|