codevdesign 1.0.30 → 1.0.32
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/csqcEditeurTexteRiche.vue +1 -1
- package/composants/csqcRechercheUtilisateur.vue +197 -197
- package/enums/choixLangue.ts +10 -0
- package/index.ts +39 -75
- package/outils/appAxios.ts +116 -116
- package/package.json +1 -1
- package/vite.config.ts +31 -0
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
langue: 'fr_FR',
|
|
77
77
|
interdireRedimension: false,
|
|
78
78
|
desactiver: false,
|
|
79
|
-
plugins: 'autoresize table image link fullscreen advlist lists autolink code
|
|
79
|
+
plugins: 'autoresize table image link fullscreen advlist lists autolink code',
|
|
80
80
|
autoriserImage: false,
|
|
81
81
|
imageTailleMaximale: 5,
|
|
82
82
|
cacherBarreMenu: false,
|
|
@@ -1,197 +1,197 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<v-autocomplete
|
|
4
|
-
v-model="selection"
|
|
5
|
-
v-model:search="search"
|
|
6
|
-
:items="items"
|
|
7
|
-
:loading="chargementInterne"
|
|
8
|
-
density="compact"
|
|
9
|
-
:hide-no-data="!doitAfficherAucunResultat"
|
|
10
|
-
:no-data-text="$t('csqc.csqcRechercheUtilisateur.aucunResultat')"
|
|
11
|
-
:item-title="formatterUtilisateur"
|
|
12
|
-
item-value="id"
|
|
13
|
-
:placeholder="$t('csqc.csqcRechercheUtilisateur.placeholderRechercheUtilisateur')"
|
|
14
|
-
return-object
|
|
15
|
-
autofocus
|
|
16
|
-
auto-select-first
|
|
17
|
-
variant="outlined"
|
|
18
|
-
/>
|
|
19
|
-
</div>
|
|
20
|
-
</template>
|
|
21
|
-
|
|
22
|
-
<script setup lang="ts">
|
|
23
|
-
import { ref, watch, computed } from 'vue'
|
|
24
|
-
import { useI18n } from 'vue-i18n'
|
|
25
|
-
import appAxios from '../outils/appAxios'
|
|
26
|
-
import type { EmployeMinsLsCodev } from '../modeles/employeMinsLsCodev'
|
|
27
|
-
|
|
28
|
-
const props = defineProps<{
|
|
29
|
-
matriculeDefaut?: string | null
|
|
30
|
-
chargement?: boolean
|
|
31
|
-
urlBase: string
|
|
32
|
-
}>()
|
|
33
|
-
|
|
34
|
-
const emit = defineEmits<{
|
|
35
|
-
(e: 'selection', value: string | null): void
|
|
36
|
-
(e: 'selectionPlus', utilisateur: EmployeMinsLsCodev | null): void
|
|
37
|
-
(e: 'erreur', message: string): void
|
|
38
|
-
}>()
|
|
39
|
-
|
|
40
|
-
const { t } = useI18n({ useScope: 'global' })
|
|
41
|
-
|
|
42
|
-
/** État interne */
|
|
43
|
-
const selection = ref<EmployeMinsLsCodev | null>(null)
|
|
44
|
-
const utilisateurs = ref<EmployeMinsLsCodev[]>([])
|
|
45
|
-
const search = ref<string>('')
|
|
46
|
-
const erreur = ref<string | null>(null)
|
|
47
|
-
|
|
48
|
-
/** Charge interne : on combine le chargement externe (prop) et l’interne */
|
|
49
|
-
const chargementInterne = ref(false)
|
|
50
|
-
const chargementEffectif = computed(() => props.chargement === true || chargementInterne.value)
|
|
51
|
-
|
|
52
|
-
/** Items sécurisés pour l’autocomplete */
|
|
53
|
-
const items = computed<EmployeMinsLsCodev[]>(() => (Array.isArray(utilisateurs.value) ? utilisateurs.value : []))
|
|
54
|
-
|
|
55
|
-
/** Cache clé→liste (toujours des arrays valides) */
|
|
56
|
-
const cache = ref<Record<string, EmployeMinsLsCodev[]>>({})
|
|
57
|
-
|
|
58
|
-
/** Détection d’un terme valide (limite les calls) */
|
|
59
|
-
const estTermeValide = (terme?: string): boolean => !!terme && terme.trim().length >= 4 && !terme.includes('(')
|
|
60
|
-
|
|
61
|
-
/** Affichage “aucun résultat” contrôlé */
|
|
62
|
-
const doitAfficherAucunResultat = computed(
|
|
63
|
-
() => estTermeValide(search.value) && !chargementEffectif.value && items.value.length === 0,
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
/** Formattage d’un employé en ligne lisible */
|
|
67
|
-
const formatterUtilisateur = (item: EmployeMinsLsCodev): string => {
|
|
68
|
-
const lieu = [item.numeroLieuPrincipal, item.nomLieuPrincipal].filter(Boolean).join('-')
|
|
69
|
-
const corps = [item.corpsEmploiPrincipal, item.corpsEmploiPrincipalDescription].filter(Boolean).join('-')
|
|
70
|
-
return `${item.prenom} ${item.nom} (${item.matricule}), ${item.courrielProfessionnel}${lieu ? `, ${lieu}` : ''}${corps ? `, ${corps}` : ''}`
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** Type guard: on s’assure qu’on a bien un tableau d’employés */
|
|
74
|
-
function isEmployeArray(x: unknown): x is EmployeMinsLsCodev[] {
|
|
75
|
-
return (
|
|
76
|
-
Array.isArray(x) && x.every(u => u && typeof u === 'object' && 'prenom' in u && 'nom' in u && 'matricule' in u)
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Réinitialise proprement la liste + émet une erreur optionnelle */
|
|
81
|
-
function safeClearUsers(msg?: string) {
|
|
82
|
-
utilisateurs.value = []
|
|
83
|
-
if (msg) {
|
|
84
|
-
erreur.value = msg
|
|
85
|
-
emit('erreur', msg)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** Anti-race condition: on ne retient le résultat que si l’ID correspond */
|
|
90
|
-
let lastQueryId = 0
|
|
91
|
-
|
|
92
|
-
async function rechercherUtilisateurs(terme?: string) {
|
|
93
|
-
if (!estTermeValide(terme)) {
|
|
94
|
-
utilisateurs.value = []
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const queryId = ++lastQueryId
|
|
99
|
-
const termeLower = terme!.toLowerCase()
|
|
100
|
-
|
|
101
|
-
// Cache prefix-match: on prend la plus longue clé qui matche le début
|
|
102
|
-
const cachedKey = Object.keys(cache.value)
|
|
103
|
-
.filter(k => termeLower.startsWith(k))
|
|
104
|
-
.sort((a, b) => b.length - a.length)[0]
|
|
105
|
-
|
|
106
|
-
if (cachedKey) {
|
|
107
|
-
const cached = cache.value[cachedKey]
|
|
108
|
-
if (isEmployeArray(cached)) {
|
|
109
|
-
// Filtre côté client pour les affiner
|
|
110
|
-
const tl = termeLower
|
|
111
|
-
utilisateurs.value = cached.filter(user => formatterUtilisateur(user).toLowerCase().includes(tl))
|
|
112
|
-
return
|
|
113
|
-
} else {
|
|
114
|
-
// Cache corrompu (théorique)
|
|
115
|
-
delete cache.value[cachedKey]
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
chargementInterne.value = true
|
|
121
|
-
const url = `${props.urlBase}/api/ComposantUI/Utilisateurs/${encodeURIComponent(terme as string)}`
|
|
122
|
-
const reponse = await appAxios.getAxios().get<unknown>(url)
|
|
123
|
-
const data = (reponse as any)?.data ?? reponse
|
|
124
|
-
|
|
125
|
-
if (queryId !== lastQueryId) {
|
|
126
|
-
// Une requête plus récente est arrivée, on ignore
|
|
127
|
-
return
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (!isEmployeArray(data)) {
|
|
131
|
-
// Probable HTML/redirect login/erreur
|
|
132
|
-
safeClearUsers(t('csqc.csqcRechercheUtilisateur.erreur'))
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
utilisateurs.value = data
|
|
137
|
-
cache.value[termeLower] = data
|
|
138
|
-
} catch (e: unknown) {
|
|
139
|
-
let message = t('csqc.csqcRechercheUtilisateur.erreur')
|
|
140
|
-
if (e instanceof Error) message = e.message
|
|
141
|
-
else if (typeof e === 'string') message = e
|
|
142
|
-
safeClearUsers(message)
|
|
143
|
-
} finally {
|
|
144
|
-
chargementInterne.value = false
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** Debounce recherche */
|
|
149
|
-
let timer: number | undefined
|
|
150
|
-
watch(
|
|
151
|
-
search,
|
|
152
|
-
terme => {
|
|
153
|
-
if (chargementEffectif.value) return
|
|
154
|
-
window.clearTimeout(timer)
|
|
155
|
-
timer = window.setTimeout(() => rechercherUtilisateurs(terme), 250)
|
|
156
|
-
},
|
|
157
|
-
{ flush: 'post' },
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
/** Émettre la sélection (email & objet complet) */
|
|
161
|
-
watch(selection, utilisateur => {
|
|
162
|
-
emit('selection', utilisateur?.courrielProfessionnel ?? null)
|
|
163
|
-
emit('selectionPlus', utilisateur ?? null)
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
/** Préchargement par matricule par défaut */
|
|
167
|
-
watch(
|
|
168
|
-
() => props.matriculeDefaut,
|
|
169
|
-
async (nv, ov) => {
|
|
170
|
-
// Si vide / nul → on nettoie
|
|
171
|
-
if (!nv || nv.trim() === '') {
|
|
172
|
-
selection.value = null
|
|
173
|
-
search.value = ''
|
|
174
|
-
utilisateurs.value = []
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Si la même valeur est déjà sélectionnée → rien à faire
|
|
179
|
-
if (selection.value?.matricule === nv) return
|
|
180
|
-
|
|
181
|
-
// Recherche par matricule par défaut
|
|
182
|
-
await rechercherUtilisateurs(nv)
|
|
183
|
-
if (utilisateurs.value.length > 0) {
|
|
184
|
-
const utilisateur = utilisateurs.value.find(u => u.matricule === nv) ?? null
|
|
185
|
-
if (utilisateur) {
|
|
186
|
-
search.value = formatterUtilisateur(utilisateur)
|
|
187
|
-
selection.value = utilisateur
|
|
188
|
-
} else {
|
|
189
|
-
// Pas trouvé → reset “propre”
|
|
190
|
-
selection.value = null
|
|
191
|
-
search.value = nv // ou ''
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
{ immediate: true },
|
|
196
|
-
)
|
|
197
|
-
</script>
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<v-autocomplete
|
|
4
|
+
v-model="selection"
|
|
5
|
+
v-model:search="search"
|
|
6
|
+
:items="items"
|
|
7
|
+
:loading="chargementInterne"
|
|
8
|
+
density="compact"
|
|
9
|
+
:hide-no-data="!doitAfficherAucunResultat"
|
|
10
|
+
:no-data-text="$t('csqc.csqcRechercheUtilisateur.aucunResultat')"
|
|
11
|
+
:item-title="formatterUtilisateur"
|
|
12
|
+
item-value="id"
|
|
13
|
+
:placeholder="$t('csqc.csqcRechercheUtilisateur.placeholderRechercheUtilisateur')"
|
|
14
|
+
return-object
|
|
15
|
+
autofocus
|
|
16
|
+
auto-select-first
|
|
17
|
+
variant="outlined"
|
|
18
|
+
/>
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
import { ref, watch, computed } from 'vue'
|
|
24
|
+
import { useI18n } from 'vue-i18n'
|
|
25
|
+
import appAxios from '../outils/appAxios'
|
|
26
|
+
import type { EmployeMinsLsCodev } from '../modeles/employeMinsLsCodev'
|
|
27
|
+
|
|
28
|
+
const props = defineProps<{
|
|
29
|
+
matriculeDefaut?: string | null
|
|
30
|
+
chargement?: boolean
|
|
31
|
+
urlBase: string
|
|
32
|
+
}>()
|
|
33
|
+
|
|
34
|
+
const emit = defineEmits<{
|
|
35
|
+
(e: 'selection', value: string | null): void
|
|
36
|
+
(e: 'selectionPlus', utilisateur: EmployeMinsLsCodev | null): void
|
|
37
|
+
(e: 'erreur', message: string): void
|
|
38
|
+
}>()
|
|
39
|
+
|
|
40
|
+
const { t } = useI18n({ useScope: 'global' })
|
|
41
|
+
|
|
42
|
+
/** État interne */
|
|
43
|
+
const selection = ref<EmployeMinsLsCodev | null>(null)
|
|
44
|
+
const utilisateurs = ref<EmployeMinsLsCodev[]>([])
|
|
45
|
+
const search = ref<string>('')
|
|
46
|
+
const erreur = ref<string | null>(null)
|
|
47
|
+
|
|
48
|
+
/** Charge interne : on combine le chargement externe (prop) et l’interne */
|
|
49
|
+
const chargementInterne = ref(false)
|
|
50
|
+
const chargementEffectif = computed(() => props.chargement === true || chargementInterne.value)
|
|
51
|
+
|
|
52
|
+
/** Items sécurisés pour l’autocomplete */
|
|
53
|
+
const items = computed<EmployeMinsLsCodev[]>(() => (Array.isArray(utilisateurs.value) ? utilisateurs.value : []))
|
|
54
|
+
|
|
55
|
+
/** Cache clé→liste (toujours des arrays valides) */
|
|
56
|
+
const cache = ref<Record<string, EmployeMinsLsCodev[]>>({})
|
|
57
|
+
|
|
58
|
+
/** Détection d’un terme valide (limite les calls) */
|
|
59
|
+
const estTermeValide = (terme?: string): boolean => !!terme && terme.trim().length >= 4 && !terme.includes('(')
|
|
60
|
+
|
|
61
|
+
/** Affichage “aucun résultat” contrôlé */
|
|
62
|
+
const doitAfficherAucunResultat = computed(
|
|
63
|
+
() => estTermeValide(search.value) && !chargementEffectif.value && items.value.length === 0,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
/** Formattage d’un employé en ligne lisible */
|
|
67
|
+
const formatterUtilisateur = (item: EmployeMinsLsCodev): string => {
|
|
68
|
+
const lieu = [item.numeroLieuPrincipal, item.nomLieuPrincipal].filter(Boolean).join('-')
|
|
69
|
+
const corps = [item.corpsEmploiPrincipal, item.corpsEmploiPrincipalDescription].filter(Boolean).join('-')
|
|
70
|
+
return `${item.prenom} ${item.nom} (${item.matricule}), ${item.courrielProfessionnel}${lieu ? `, ${lieu}` : ''}${corps ? `, ${corps}` : ''}`
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Type guard: on s’assure qu’on a bien un tableau d’employés */
|
|
74
|
+
function isEmployeArray(x: unknown): x is EmployeMinsLsCodev[] {
|
|
75
|
+
return (
|
|
76
|
+
Array.isArray(x) && x.every(u => u && typeof u === 'object' && 'prenom' in u && 'nom' in u && 'matricule' in u)
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Réinitialise proprement la liste + émet une erreur optionnelle */
|
|
81
|
+
function safeClearUsers(msg?: string) {
|
|
82
|
+
utilisateurs.value = []
|
|
83
|
+
if (msg) {
|
|
84
|
+
erreur.value = msg
|
|
85
|
+
emit('erreur', msg)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Anti-race condition: on ne retient le résultat que si l’ID correspond */
|
|
90
|
+
let lastQueryId = 0
|
|
91
|
+
|
|
92
|
+
async function rechercherUtilisateurs(terme?: string) {
|
|
93
|
+
if (!estTermeValide(terme)) {
|
|
94
|
+
utilisateurs.value = []
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const queryId = ++lastQueryId
|
|
99
|
+
const termeLower = terme!.toLowerCase()
|
|
100
|
+
|
|
101
|
+
// Cache prefix-match: on prend la plus longue clé qui matche le début
|
|
102
|
+
const cachedKey = Object.keys(cache.value)
|
|
103
|
+
.filter(k => termeLower.startsWith(k))
|
|
104
|
+
.sort((a, b) => b.length - a.length)[0]
|
|
105
|
+
|
|
106
|
+
if (cachedKey) {
|
|
107
|
+
const cached = cache.value[cachedKey]
|
|
108
|
+
if (isEmployeArray(cached)) {
|
|
109
|
+
// Filtre côté client pour les affiner
|
|
110
|
+
const tl = termeLower
|
|
111
|
+
utilisateurs.value = cached.filter(user => formatterUtilisateur(user).toLowerCase().includes(tl))
|
|
112
|
+
return
|
|
113
|
+
} else {
|
|
114
|
+
// Cache corrompu (théorique)
|
|
115
|
+
delete cache.value[cachedKey]
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
chargementInterne.value = true
|
|
121
|
+
const url = `${props.urlBase}/api/ComposantUI/Utilisateurs/${encodeURIComponent(terme as string)}`
|
|
122
|
+
const reponse = await appAxios.getAxios().get<unknown>(url)
|
|
123
|
+
const data = (reponse as any)?.data ?? reponse
|
|
124
|
+
|
|
125
|
+
if (queryId !== lastQueryId) {
|
|
126
|
+
// Une requête plus récente est arrivée, on ignore
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!isEmployeArray(data)) {
|
|
131
|
+
// Probable HTML/redirect login/erreur
|
|
132
|
+
safeClearUsers(t('csqc.csqcRechercheUtilisateur.erreur'))
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
utilisateurs.value = data
|
|
137
|
+
cache.value[termeLower] = data
|
|
138
|
+
} catch (e: unknown) {
|
|
139
|
+
let message = t('csqc.csqcRechercheUtilisateur.erreur')
|
|
140
|
+
if (e instanceof Error) message = e.message
|
|
141
|
+
else if (typeof e === 'string') message = e
|
|
142
|
+
safeClearUsers(message)
|
|
143
|
+
} finally {
|
|
144
|
+
chargementInterne.value = false
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Debounce recherche */
|
|
149
|
+
let timer: number | undefined
|
|
150
|
+
watch(
|
|
151
|
+
search,
|
|
152
|
+
terme => {
|
|
153
|
+
if (chargementEffectif.value) return
|
|
154
|
+
window.clearTimeout(timer)
|
|
155
|
+
timer = window.setTimeout(() => rechercherUtilisateurs(terme), 250)
|
|
156
|
+
},
|
|
157
|
+
{ flush: 'post' },
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
/** Émettre la sélection (email & objet complet) */
|
|
161
|
+
watch(selection, utilisateur => {
|
|
162
|
+
emit('selection', utilisateur?.courrielProfessionnel ?? null)
|
|
163
|
+
emit('selectionPlus', utilisateur ?? null)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
/** Préchargement par matricule par défaut */
|
|
167
|
+
watch(
|
|
168
|
+
() => props.matriculeDefaut,
|
|
169
|
+
async (nv, ov) => {
|
|
170
|
+
// Si vide / nul → on nettoie
|
|
171
|
+
if (!nv || nv.trim() === '') {
|
|
172
|
+
selection.value = null
|
|
173
|
+
search.value = ''
|
|
174
|
+
utilisateurs.value = []
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Si la même valeur est déjà sélectionnée → rien à faire
|
|
179
|
+
if (selection.value?.matricule === nv) return
|
|
180
|
+
|
|
181
|
+
// Recherche par matricule par défaut
|
|
182
|
+
await rechercherUtilisateurs(nv)
|
|
183
|
+
if (utilisateurs.value.length > 0) {
|
|
184
|
+
const utilisateur = utilisateurs.value.find(u => u.matricule === nv) ?? null
|
|
185
|
+
if (utilisateur) {
|
|
186
|
+
search.value = formatterUtilisateur(utilisateur)
|
|
187
|
+
selection.value = utilisateur
|
|
188
|
+
} else {
|
|
189
|
+
// Pas trouvé → reset “propre”
|
|
190
|
+
selection.value = null
|
|
191
|
+
search.value = nv // ou ''
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{ immediate: true },
|
|
196
|
+
)
|
|
197
|
+
</script>
|
package/index.ts
CHANGED
|
@@ -1,75 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
csqcFr,
|
|
44
|
-
csqcEn,
|
|
45
|
-
csqcAlerteErreur,
|
|
46
|
-
csqcDialogue,
|
|
47
|
-
csqcConfirmation,
|
|
48
|
-
csqcSaisie,
|
|
49
|
-
csqcDate,
|
|
50
|
-
csqcOptionSwitch,
|
|
51
|
-
csqcRecherche,
|
|
52
|
-
csqcSnackbar,
|
|
53
|
-
csqcTable,
|
|
54
|
-
csqcTiroir,
|
|
55
|
-
csqcMenu,
|
|
56
|
-
csqcCodeBudgetaire,
|
|
57
|
-
csqcChaise,
|
|
58
|
-
pivFooter,
|
|
59
|
-
pivEntete,
|
|
60
|
-
csqcAide,
|
|
61
|
-
csqcEntete,
|
|
62
|
-
csqcTexteBilingue,
|
|
63
|
-
csqcEditeurTexteRiche,
|
|
64
|
-
validateurs,
|
|
65
|
-
csqcImportCSV,
|
|
66
|
-
csqcRechercheUtilisateur,
|
|
67
|
-
csqcRafraichisseurToken,
|
|
68
|
-
csqcOutils,
|
|
69
|
-
modeleSnackbar,
|
|
70
|
-
modeleDatatableColonne as colonne,
|
|
71
|
-
apiReponse,
|
|
72
|
-
data,
|
|
73
|
-
response,
|
|
74
|
-
NotificationGabaritDefaut,
|
|
75
|
-
}
|
|
1
|
+
// i18n
|
|
2
|
+
export { default as csqcFr } from './locales/fr.json'
|
|
3
|
+
export { default as csqcEn } from './locales/en.json'
|
|
4
|
+
|
|
5
|
+
// Composants
|
|
6
|
+
export { default as csqcAlerteErreur } from './composants/csqcAlerteErreur.vue'
|
|
7
|
+
export { default as csqcDialogue } from './composants/csqcDialogue.vue'
|
|
8
|
+
export { default as csqcOptionSwitch } from './composants/csqcOptionSwitch.vue'
|
|
9
|
+
export { default as csqcRecherche } from './composants/csqcRecherche.vue'
|
|
10
|
+
export { default as csqcSnackbar } from './composants/csqcSnackbar.vue'
|
|
11
|
+
export { default as csqcTiroir } from './composants/csqcTiroir.vue'
|
|
12
|
+
export { default as pivEntete } from './composants/gabarit/pivEntete.vue'
|
|
13
|
+
export { default as pivFooter } from './composants/gabarit/pivPiedPage.vue'
|
|
14
|
+
export { default as csqcMenu } from './composants/gabarit/csqcMenu.vue'
|
|
15
|
+
export { default as csqcConfirmation } from './composants/csqcConfirmation.vue'
|
|
16
|
+
export { default as csqcSaisie } from './composants/csqcModaleSaisie.vue'
|
|
17
|
+
export { default as csqcDate } from './composants/csqcDate.vue'
|
|
18
|
+
export { default as csqcTable } from './composants/csqcTable/csqcTable.vue'
|
|
19
|
+
export { default as csqcCodeBudgetaire } from './composants/csqcCodeBudgetaireGenerique.vue'
|
|
20
|
+
export { default as csqcChaise } from './composants/csqcChaise/chaiseConteneur.vue'
|
|
21
|
+
export { default as csqcAide } from './composants/csqcAide.vue'
|
|
22
|
+
export { default as csqcEntete } from './composants/csqcEntete.vue'
|
|
23
|
+
export { default as csqcTexteBilingue } from './composants/csqcTexteBilingue.vue'
|
|
24
|
+
export { default as csqcEditeurTexteRiche } from './composants/csqcEditeurTexteRiche.vue'
|
|
25
|
+
export { default as csqcImportCSV } from './composants/csqcImportCSV.vue'
|
|
26
|
+
export { default as csqcRechercheUtilisateur } from './composants/csqcRechercheUtilisateur.vue'
|
|
27
|
+
export { default as validateurs } from './composants/validateurs'
|
|
28
|
+
|
|
29
|
+
// Modèles
|
|
30
|
+
export { default as NotificationGabaritDefaut } from './modeles/notificationGabaritDefaut'
|
|
31
|
+
export { default as modeleSnackbar } from './modeles/composants/snackbar'
|
|
32
|
+
export { default as colonne } from './modeles/composants/datatableColonne'
|
|
33
|
+
export { default as apiReponse } from './modeles/apiReponse'
|
|
34
|
+
export { default as data } from './modeles/data'
|
|
35
|
+
export { default as response } from './modeles/response'
|
|
36
|
+
|
|
37
|
+
// Outils
|
|
38
|
+
export { default as csqcRafraichisseurToken } from './outils/rafraichisseurToken'
|
|
39
|
+
export { default as csqcOutils } from './outils/csqcOutils'
|
package/outils/appAxios.ts
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import axios, { type AxiosInstance, type AxiosError, type AxiosResponse } from 'axios'
|
|
2
|
-
import { useAppStore } from '@/store/appStore'
|
|
3
|
-
import router from '@/router'
|
|
4
|
-
|
|
5
|
-
type ApiReponse<T = unknown> =
|
|
6
|
-
// Succès
|
|
7
|
-
| {
|
|
8
|
-
succes: true
|
|
9
|
-
resultat: T
|
|
10
|
-
status?: number
|
|
11
|
-
message?: string
|
|
12
|
-
location?: string
|
|
13
|
-
parametres?: unknown
|
|
14
|
-
[k: string]: unknown
|
|
15
|
-
}
|
|
16
|
-
// Échec (le backend peut quand même renvoyer resultat null/absent)
|
|
17
|
-
| {
|
|
18
|
-
succes: false
|
|
19
|
-
resultat?: unknown
|
|
20
|
-
status?: number
|
|
21
|
-
message?: string
|
|
22
|
-
location?: string
|
|
23
|
-
parametres?: unknown
|
|
24
|
-
[k: string]: unknown
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
let client: AxiosInstance | null = null
|
|
28
|
-
let cachedBaseUrl = '' // pour éviter de régénérer une instance axios si rien n’a changé
|
|
29
|
-
|
|
30
|
-
export default {
|
|
31
|
-
clearCache: false,
|
|
32
|
-
|
|
33
|
-
getAxios(): AxiosInstance {
|
|
34
|
-
// Singleton + clearCache
|
|
35
|
-
if (client && !this.clearCache) return client
|
|
36
|
-
|
|
37
|
-
const appStore = useAppStore()
|
|
38
|
-
|
|
39
|
-
const rawUrl = appStore.modeleCharger
|
|
40
|
-
? appStore.appModele!.urlBase
|
|
41
|
-
: window.location.origin + import.meta.env.BASE_URL
|
|
42
|
-
|
|
43
|
-
const urlBase = rawUrl.endsWith('/') ? rawUrl.slice(0, -1) : rawUrl
|
|
44
|
-
|
|
45
|
-
// Si la base URL n'a pas changé et qu'on a déjà un client, on le renvoie
|
|
46
|
-
if (client && cachedBaseUrl === urlBase && !this.clearCache) return client
|
|
47
|
-
cachedBaseUrl = urlBase
|
|
48
|
-
|
|
49
|
-
client = axios.create({
|
|
50
|
-
baseURL: `${urlBase}/api`,
|
|
51
|
-
withCredentials: true,
|
|
52
|
-
timeout: 30_000,
|
|
53
|
-
headers: {
|
|
54
|
-
Accept: 'application/json',
|
|
55
|
-
'Content-Type': 'application/json',
|
|
56
|
-
'X-Requested-With': 'XMLHttpRequest',
|
|
57
|
-
},
|
|
58
|
-
// validateStatus: (s) => s >= 200 && s < 300, // défaut axios
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
client.interceptors.response.use(
|
|
62
|
-
(response: AxiosResponse<any>) => {
|
|
63
|
-
const data = response.data
|
|
64
|
-
|
|
65
|
-
// Détection de la réponse { succes, resultat }
|
|
66
|
-
if (data && typeof data === 'object' && 'succes' in data) {
|
|
67
|
-
const env = data as ApiReponse
|
|
68
|
-
return env.succes === true ? env.resultat : Promise.reject(env)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Sinon, renvoyer data si présent, sinon la réponse complète
|
|
72
|
-
return data ?? response
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
(error: AxiosError<any>) => {
|
|
76
|
-
const status = error.response?.status
|
|
77
|
-
const payload = error.response?.data?.resultat ?? { message: error.message }
|
|
78
|
-
|
|
79
|
-
// 403 / 404
|
|
80
|
-
if (status === 403 || status === 404) {
|
|
81
|
-
try {
|
|
82
|
-
appStore.lancerErreur(payload)
|
|
83
|
-
if (router.currentRoute.value.name !== '403') {
|
|
84
|
-
router.push({ name: '403' })
|
|
85
|
-
}
|
|
86
|
-
} catch {
|
|
87
|
-
// no-op
|
|
88
|
-
}
|
|
89
|
-
return Promise.reject(payload)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// gérer les autres 4XX ici
|
|
93
|
-
|
|
94
|
-
// Log minimal
|
|
95
|
-
console.error('HTTP error', {
|
|
96
|
-
status,
|
|
97
|
-
url: error.config?.url,
|
|
98
|
-
payload,
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
// Remonter l’erreur normalisée dans appstore
|
|
102
|
-
try {
|
|
103
|
-
if (payload?.resultat) appStore.lancerErreur(payload)
|
|
104
|
-
else if (payload) appStore.lancerErreur(payload)
|
|
105
|
-
} catch {
|
|
106
|
-
// no-op
|
|
107
|
-
}
|
|
108
|
-
return Promise.reject(payload)
|
|
109
|
-
},
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
// reset le flag si on l’avait utilisé pour forcer la recréation de l'instance
|
|
113
|
-
this.clearCache = false
|
|
114
|
-
return client
|
|
115
|
-
},
|
|
116
|
-
}
|
|
1
|
+
import axios, { type AxiosInstance, type AxiosError, type AxiosResponse } from 'axios'
|
|
2
|
+
import { useAppStore } from '@/store/appStore'
|
|
3
|
+
import router from '@/router'
|
|
4
|
+
|
|
5
|
+
type ApiReponse<T = unknown> =
|
|
6
|
+
// Succès
|
|
7
|
+
| {
|
|
8
|
+
succes: true
|
|
9
|
+
resultat: T
|
|
10
|
+
status?: number
|
|
11
|
+
message?: string
|
|
12
|
+
location?: string
|
|
13
|
+
parametres?: unknown
|
|
14
|
+
[k: string]: unknown
|
|
15
|
+
}
|
|
16
|
+
// Échec (le backend peut quand même renvoyer resultat null/absent)
|
|
17
|
+
| {
|
|
18
|
+
succes: false
|
|
19
|
+
resultat?: unknown
|
|
20
|
+
status?: number
|
|
21
|
+
message?: string
|
|
22
|
+
location?: string
|
|
23
|
+
parametres?: unknown
|
|
24
|
+
[k: string]: unknown
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let client: AxiosInstance | null = null
|
|
28
|
+
let cachedBaseUrl = '' // pour éviter de régénérer une instance axios si rien n’a changé
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
clearCache: false,
|
|
32
|
+
|
|
33
|
+
getAxios(): AxiosInstance {
|
|
34
|
+
// Singleton + clearCache
|
|
35
|
+
if (client && !this.clearCache) return client
|
|
36
|
+
|
|
37
|
+
const appStore = useAppStore()
|
|
38
|
+
|
|
39
|
+
const rawUrl = appStore.modeleCharger
|
|
40
|
+
? appStore.appModele!.urlBase
|
|
41
|
+
: window.location.origin + import.meta.env.BASE_URL
|
|
42
|
+
|
|
43
|
+
const urlBase = rawUrl.endsWith('/') ? rawUrl.slice(0, -1) : rawUrl
|
|
44
|
+
|
|
45
|
+
// Si la base URL n'a pas changé et qu'on a déjà un client, on le renvoie
|
|
46
|
+
if (client && cachedBaseUrl === urlBase && !this.clearCache) return client
|
|
47
|
+
cachedBaseUrl = urlBase
|
|
48
|
+
|
|
49
|
+
client = axios.create({
|
|
50
|
+
baseURL: `${urlBase}/api`,
|
|
51
|
+
withCredentials: true,
|
|
52
|
+
timeout: 30_000,
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: 'application/json',
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
57
|
+
},
|
|
58
|
+
// validateStatus: (s) => s >= 200 && s < 300, // défaut axios
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
client.interceptors.response.use(
|
|
62
|
+
(response: AxiosResponse<any>) => {
|
|
63
|
+
const data = response.data
|
|
64
|
+
|
|
65
|
+
// Détection de la réponse { succes, resultat }
|
|
66
|
+
if (data && typeof data === 'object' && 'succes' in data) {
|
|
67
|
+
const env = data as ApiReponse
|
|
68
|
+
return env.succes === true ? env.resultat : Promise.reject(env)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Sinon, renvoyer data si présent, sinon la réponse complète
|
|
72
|
+
return data ?? response
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
(error: AxiosError<any>) => {
|
|
76
|
+
const status = error.response?.status
|
|
77
|
+
const payload = error.response?.data?.resultat ?? { message: error.message }
|
|
78
|
+
|
|
79
|
+
// 403 / 404
|
|
80
|
+
if (status === 403 || status === 404) {
|
|
81
|
+
try {
|
|
82
|
+
appStore.lancerErreur(payload)
|
|
83
|
+
if (router.currentRoute.value.name !== '403') {
|
|
84
|
+
router.push({ name: '403' })
|
|
85
|
+
}
|
|
86
|
+
} catch {
|
|
87
|
+
// no-op
|
|
88
|
+
}
|
|
89
|
+
return Promise.reject(payload)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// gérer les autres 4XX ici
|
|
93
|
+
|
|
94
|
+
// Log minimal
|
|
95
|
+
console.error('HTTP error', {
|
|
96
|
+
status,
|
|
97
|
+
url: error.config?.url,
|
|
98
|
+
payload,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
// Remonter l’erreur normalisée dans appstore
|
|
102
|
+
try {
|
|
103
|
+
if (payload?.resultat) appStore.lancerErreur(payload)
|
|
104
|
+
else if (payload) appStore.lancerErreur(payload)
|
|
105
|
+
} catch {
|
|
106
|
+
// no-op
|
|
107
|
+
}
|
|
108
|
+
return Promise.reject(payload)
|
|
109
|
+
},
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
// reset le flag si on l’avait utilisé pour forcer la recréation de l'instance
|
|
113
|
+
this.clearCache = false
|
|
114
|
+
return client
|
|
115
|
+
},
|
|
116
|
+
}
|
package/package.json
CHANGED
package/vite.config.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// vite.config.ts
|
|
2
|
+
import { defineConfig } from 'vite'
|
|
3
|
+
import vue from '@vitejs/plugin-vue'
|
|
4
|
+
import { fileURLToPath, URL } from 'node:url'
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
plugins: [vue()],
|
|
8
|
+
resolve: {
|
|
9
|
+
alias: {
|
|
10
|
+
'@': fileURLToPath(new URL('./', import.meta.url)),
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
build: {
|
|
14
|
+
lib: {
|
|
15
|
+
entry: 'index.ts', // ton index.ts qui fait tous les exports
|
|
16
|
+
name: 'CodevDesign',
|
|
17
|
+
fileName: format => `codevdesign.${format}.js`,
|
|
18
|
+
formats: ['es', 'cjs'],
|
|
19
|
+
},
|
|
20
|
+
rollupOptions: {
|
|
21
|
+
// ne pas re-bundler ce qui doit être fourni par l'app
|
|
22
|
+
external: ['vue', 'vuetify', 'vue-i18n', '@e965/xlsx', 'tinymce', 'tinymce-i18n', '@tinymce/tinymce-vue'],
|
|
23
|
+
output: {
|
|
24
|
+
globals: {
|
|
25
|
+
vue: 'Vue',
|
|
26
|
+
vuetify: 'Vuetify',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
})
|