codevdesign 1.0.50 → 1.0.52
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/chaiseItem.vue +54 -54
- package/composants/csqcConfirmation.vue +75 -75
- package/composants/csqcDate.vue +58 -57
- package/composants/csqcEntete.vue +187 -187
- package/composants/csqcImportCSV.vue +125 -125
- package/composants/csqcSnackbar.vue +207 -207
- package/composants/csqcSwitch.vue +33 -6
- package/composants/csqcTexteBilingue.vue +175 -175
- package/composants/gabarit/csqcMenu.vue +281 -281
- package/index.ts +78 -78
- package/modeles/composants/csqcMenuModele.ts +18 -18
- package/modeles/composants/datatableColonne.ts +31 -31
- package/outils/appAxios.ts +116 -116
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import csqcAlerteErreur from './composants/csqcAlerteErreur.vue'
|
|
2
|
-
import csqcDialogue from './composants/csqcDialogue.vue'
|
|
3
|
-
|
|
4
|
-
// à enlever éventuellement. Remplacé par csqcSwitch
|
|
5
|
-
import csqcOptionSwitch from './composants/csqcSwitch.vue'
|
|
6
|
-
import csqcRecherche from './composants/csqcRecherche.vue'
|
|
7
|
-
import csqcSnackbar from './composants/csqcSnackbar.vue'
|
|
8
|
-
import csqcTiroir from './composants/csqcTiroir.vue'
|
|
9
|
-
import pivEntete from './composants/gabarit/pivEntete.vue'
|
|
10
|
-
import pivFooter from './composants/gabarit/pivPiedPage.vue'
|
|
11
|
-
import csqcMenu from './composants/gabarit/csqcMenu.vue'
|
|
12
|
-
import csqcConfirmation from './composants/csqcConfirmation.vue'
|
|
13
|
-
import csqcSaisie from './composants/csqcModaleSaisie.vue'
|
|
14
|
-
import csqcDate from './composants/csqcDate.vue'
|
|
15
|
-
import csqcTable from './composants/csqcTable/csqcTable.vue'
|
|
16
|
-
import csqcCodeBudgetaire from './composants/csqcCodeBudgetaireGenerique.vue'
|
|
17
|
-
import csqcChaise from './composants/csqcChaise/chaiseConteneur.vue'
|
|
18
|
-
import csqcAide from './composants/csqcAide.vue'
|
|
19
|
-
import csqcEntete from './composants/csqcEntete.vue'
|
|
20
|
-
import csqcTexteBilingue from './composants/csqcTexteBilingue.vue'
|
|
21
|
-
import csqcSwitch from './composants/csqcSwitch.vue'
|
|
22
|
-
|
|
23
|
-
import csqcEditeurTexteRiche from './composants/csqcEditeurTexteRiche.vue'
|
|
24
|
-
import csqcImportCSV from './composants/csqcImportCSV.vue'
|
|
25
|
-
import csqcRechercheUtilisateur from './composants/csqcRechercheUtilisateur.vue'
|
|
26
|
-
import validateurs from './composants/validateurs'
|
|
27
|
-
|
|
28
|
-
// modèles
|
|
29
|
-
import NotificationGabaritDefaut from './modeles/notificationGabaritDefaut'
|
|
30
|
-
import modeleSnackbar from './modeles/composants/snackbar'
|
|
31
|
-
import modeleDatatableColonne from './modeles/composants/datatableColonne'
|
|
32
|
-
import apiReponse from './modeles/apiReponse'
|
|
33
|
-
import data from './modeles/data'
|
|
34
|
-
import response from './modeles/response'
|
|
35
|
-
|
|
36
|
-
// outils
|
|
37
|
-
import csqcRafraichisseurToken from './outils/rafraichisseurToken'
|
|
38
|
-
import csqcOutils from './outils/csqcOutils'
|
|
39
|
-
|
|
40
|
-
// i18n
|
|
41
|
-
import csqcEn from './locales/en.json'
|
|
42
|
-
import csqcFr from './locales/fr.json'
|
|
43
|
-
|
|
44
|
-
export {
|
|
45
|
-
csqcFr,
|
|
46
|
-
csqcEn,
|
|
47
|
-
csqcAlerteErreur,
|
|
48
|
-
csqcDialogue,
|
|
49
|
-
csqcConfirmation,
|
|
50
|
-
csqcSaisie,
|
|
51
|
-
csqcDate,
|
|
52
|
-
csqcOptionSwitch, // a enlever eventuellement
|
|
53
|
-
csqcSwitch,
|
|
54
|
-
csqcRecherche,
|
|
55
|
-
csqcSnackbar,
|
|
56
|
-
csqcTable,
|
|
57
|
-
csqcTiroir,
|
|
58
|
-
csqcMenu,
|
|
59
|
-
csqcCodeBudgetaire,
|
|
60
|
-
csqcChaise,
|
|
61
|
-
pivFooter,
|
|
62
|
-
pivEntete,
|
|
63
|
-
csqcAide,
|
|
64
|
-
csqcEntete,
|
|
65
|
-
csqcTexteBilingue,
|
|
66
|
-
csqcEditeurTexteRiche,
|
|
67
|
-
validateurs,
|
|
68
|
-
csqcImportCSV,
|
|
69
|
-
csqcRechercheUtilisateur,
|
|
70
|
-
csqcRafraichisseurToken,
|
|
71
|
-
csqcOutils,
|
|
72
|
-
modeleSnackbar,
|
|
73
|
-
modeleDatatableColonne as colonne,
|
|
74
|
-
apiReponse,
|
|
75
|
-
data,
|
|
76
|
-
response,
|
|
77
|
-
NotificationGabaritDefaut,
|
|
78
|
-
}
|
|
1
|
+
import csqcAlerteErreur from './composants/csqcAlerteErreur.vue'
|
|
2
|
+
import csqcDialogue from './composants/csqcDialogue.vue'
|
|
3
|
+
|
|
4
|
+
// à enlever éventuellement. Remplacé par csqcSwitch
|
|
5
|
+
import csqcOptionSwitch from './composants/csqcSwitch.vue'
|
|
6
|
+
import csqcRecherche from './composants/csqcRecherche.vue'
|
|
7
|
+
import csqcSnackbar from './composants/csqcSnackbar.vue'
|
|
8
|
+
import csqcTiroir from './composants/csqcTiroir.vue'
|
|
9
|
+
import pivEntete from './composants/gabarit/pivEntete.vue'
|
|
10
|
+
import pivFooter from './composants/gabarit/pivPiedPage.vue'
|
|
11
|
+
import csqcMenu from './composants/gabarit/csqcMenu.vue'
|
|
12
|
+
import csqcConfirmation from './composants/csqcConfirmation.vue'
|
|
13
|
+
import csqcSaisie from './composants/csqcModaleSaisie.vue'
|
|
14
|
+
import csqcDate from './composants/csqcDate.vue'
|
|
15
|
+
import csqcTable from './composants/csqcTable/csqcTable.vue'
|
|
16
|
+
import csqcCodeBudgetaire from './composants/csqcCodeBudgetaireGenerique.vue'
|
|
17
|
+
import csqcChaise from './composants/csqcChaise/chaiseConteneur.vue'
|
|
18
|
+
import csqcAide from './composants/csqcAide.vue'
|
|
19
|
+
import csqcEntete from './composants/csqcEntete.vue'
|
|
20
|
+
import csqcTexteBilingue from './composants/csqcTexteBilingue.vue'
|
|
21
|
+
import csqcSwitch from './composants/csqcSwitch.vue'
|
|
22
|
+
|
|
23
|
+
import csqcEditeurTexteRiche from './composants/csqcEditeurTexteRiche.vue'
|
|
24
|
+
import csqcImportCSV from './composants/csqcImportCSV.vue'
|
|
25
|
+
import csqcRechercheUtilisateur from './composants/csqcRechercheUtilisateur.vue'
|
|
26
|
+
import validateurs from './composants/validateurs'
|
|
27
|
+
|
|
28
|
+
// modèles
|
|
29
|
+
import NotificationGabaritDefaut from './modeles/notificationGabaritDefaut'
|
|
30
|
+
import modeleSnackbar from './modeles/composants/snackbar'
|
|
31
|
+
import modeleDatatableColonne from './modeles/composants/datatableColonne'
|
|
32
|
+
import apiReponse from './modeles/apiReponse'
|
|
33
|
+
import data from './modeles/data'
|
|
34
|
+
import response from './modeles/response'
|
|
35
|
+
|
|
36
|
+
// outils
|
|
37
|
+
import csqcRafraichisseurToken from './outils/rafraichisseurToken'
|
|
38
|
+
import csqcOutils from './outils/csqcOutils'
|
|
39
|
+
|
|
40
|
+
// i18n
|
|
41
|
+
import csqcEn from './locales/en.json'
|
|
42
|
+
import csqcFr from './locales/fr.json'
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
csqcFr,
|
|
46
|
+
csqcEn,
|
|
47
|
+
csqcAlerteErreur,
|
|
48
|
+
csqcDialogue,
|
|
49
|
+
csqcConfirmation,
|
|
50
|
+
csqcSaisie,
|
|
51
|
+
csqcDate,
|
|
52
|
+
csqcOptionSwitch, // a enlever eventuellement
|
|
53
|
+
csqcSwitch,
|
|
54
|
+
csqcRecherche,
|
|
55
|
+
csqcSnackbar,
|
|
56
|
+
csqcTable,
|
|
57
|
+
csqcTiroir,
|
|
58
|
+
csqcMenu,
|
|
59
|
+
csqcCodeBudgetaire,
|
|
60
|
+
csqcChaise,
|
|
61
|
+
pivFooter,
|
|
62
|
+
pivEntete,
|
|
63
|
+
csqcAide,
|
|
64
|
+
csqcEntete,
|
|
65
|
+
csqcTexteBilingue,
|
|
66
|
+
csqcEditeurTexteRiche,
|
|
67
|
+
validateurs,
|
|
68
|
+
csqcImportCSV,
|
|
69
|
+
csqcRechercheUtilisateur,
|
|
70
|
+
csqcRafraichisseurToken,
|
|
71
|
+
csqcOutils,
|
|
72
|
+
modeleSnackbar,
|
|
73
|
+
modeleDatatableColonne as colonne,
|
|
74
|
+
apiReponse,
|
|
75
|
+
data,
|
|
76
|
+
response,
|
|
77
|
+
NotificationGabaritDefaut,
|
|
78
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export interface MenuItem {
|
|
2
|
-
nom: string
|
|
3
|
-
path: string
|
|
4
|
-
droit: string
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface SousListe {
|
|
8
|
-
droit: string
|
|
9
|
-
id: number
|
|
10
|
-
nom: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface SousListeItems {
|
|
14
|
-
parentId: number
|
|
15
|
-
nom: string
|
|
16
|
-
path: string
|
|
17
|
-
droit: string
|
|
18
|
-
}
|
|
1
|
+
export interface MenuItem {
|
|
2
|
+
nom: string
|
|
3
|
+
path: string
|
|
4
|
+
droit: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SousListe {
|
|
8
|
+
droit: string
|
|
9
|
+
id: number
|
|
10
|
+
nom: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface SousListeItems {
|
|
14
|
+
parentId: number
|
|
15
|
+
nom: string
|
|
16
|
+
path: string
|
|
17
|
+
droit: string
|
|
18
|
+
}
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import type { DataTableCompareFunction, DataTableHeader, FilterFunction } from 'vuetify'
|
|
2
|
-
import { HeaderCellProps } from 'vuetify/lib/components/VDataTable/types.mjs';
|
|
3
|
-
import { SelectItemKey } from 'vuetify/lib/util/helpers.mjs';
|
|
4
|
-
|
|
5
|
-
class datatableColonne<T = any> implements DataTableHeader<T> {
|
|
6
|
-
key?: 'data-table-group' | 'data-table-select' | 'data-table-expand' | (string & {});
|
|
7
|
-
value?: SelectItemKey<T>;
|
|
8
|
-
title?: string;
|
|
9
|
-
fixed?: boolean | 'start' | 'end';
|
|
10
|
-
align?: 'start' | 'end' | 'center';
|
|
11
|
-
width?: number | string;
|
|
12
|
-
minWidth?: number | string;
|
|
13
|
-
maxWidth?: number | string;
|
|
14
|
-
nowrap?: boolean;
|
|
15
|
-
intent?: number;
|
|
16
|
-
headerProps?: Record<string, any>;
|
|
17
|
-
cellProps?: HeaderCellProps;
|
|
18
|
-
sortable?: boolean;
|
|
19
|
-
sort?: DataTableCompareFunction;
|
|
20
|
-
sortRaw?: DataTableCompareFunction;
|
|
21
|
-
filter?: FilterFunction;
|
|
22
|
-
children?: DataTableHeader<T>[];
|
|
23
|
-
|
|
24
|
-
constructor(title: string, key: string) {
|
|
25
|
-
this.title = title
|
|
26
|
-
this.key = key
|
|
27
|
-
this.align = key === 'action' ? 'end' : key === 'estActif' ? 'center' : 'start'
|
|
28
|
-
this.sortable = key !== 'action'
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export default datatableColonne
|
|
1
|
+
import type { DataTableCompareFunction, DataTableHeader, FilterFunction } from 'vuetify'
|
|
2
|
+
import { HeaderCellProps } from 'vuetify/lib/components/VDataTable/types.mjs';
|
|
3
|
+
import { SelectItemKey } from 'vuetify/lib/util/helpers.mjs';
|
|
4
|
+
|
|
5
|
+
class datatableColonne<T = any> implements DataTableHeader<T> {
|
|
6
|
+
key?: 'data-table-group' | 'data-table-select' | 'data-table-expand' | (string & {});
|
|
7
|
+
value?: SelectItemKey<T>;
|
|
8
|
+
title?: string;
|
|
9
|
+
fixed?: boolean | 'start' | 'end';
|
|
10
|
+
align?: 'start' | 'end' | 'center';
|
|
11
|
+
width?: number | string;
|
|
12
|
+
minWidth?: number | string;
|
|
13
|
+
maxWidth?: number | string;
|
|
14
|
+
nowrap?: boolean;
|
|
15
|
+
intent?: number;
|
|
16
|
+
headerProps?: Record<string, any>;
|
|
17
|
+
cellProps?: HeaderCellProps;
|
|
18
|
+
sortable?: boolean;
|
|
19
|
+
sort?: DataTableCompareFunction;
|
|
20
|
+
sortRaw?: DataTableCompareFunction;
|
|
21
|
+
filter?: FilterFunction;
|
|
22
|
+
children?: DataTableHeader<T>[];
|
|
23
|
+
|
|
24
|
+
constructor(title: string, key: string) {
|
|
25
|
+
this.title = title
|
|
26
|
+
this.key = key
|
|
27
|
+
this.align = key === 'action' ? 'end' : key === 'estActif' ? 'center' : 'start'
|
|
28
|
+
this.sortable = key !== 'action'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export default datatableColonne
|
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
|
+
}
|