codevdesign 1.0.0 → 1.0.1
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/csqcChaise/chaiseConteneur.vue +363 -363
- package/composants/csqcRechercheUtilisateur.vue +197 -197
- package/composants/gabarit/pivEntete.vue +14 -1
- package/index.ts +72 -72
- package/outils/appAxios.ts +117 -117
- package/package.json +2 -2
package/outils/appAxios.ts
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
// 403 / 404
|
|
82
|
-
if (status === 403 || status === 404) {
|
|
83
|
-
try {
|
|
84
|
-
appStore.lancerErreur(payload)
|
|
85
|
-
if (router.currentRoute.value.name !== '403') {
|
|
86
|
-
router.push({ name: '403' })
|
|
87
|
-
}
|
|
88
|
-
} catch {
|
|
89
|
-
// no-op
|
|
90
|
-
}
|
|
91
|
-
return Promise.reject(payload)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// gérer les autres 4XX ici
|
|
95
|
-
|
|
96
|
-
// Log minimal
|
|
97
|
-
console.error('HTTP error', {
|
|
98
|
-
status,
|
|
99
|
-
url: error.config?.url,
|
|
100
|
-
payload,
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
// Remonter l’erreur normalisée dans appstore
|
|
104
|
-
try {
|
|
105
|
-
if (payload?.resultat) appStore.lancerErreur(payload)
|
|
106
|
-
} catch {
|
|
107
|
-
// no-op
|
|
108
|
-
}
|
|
109
|
-
return Promise.reject(payload)
|
|
110
|
-
},
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
// reset le flag si on l’avait utilisé pour forcer la recréation de l'instance
|
|
114
|
-
this.clearCache = false
|
|
115
|
-
return client
|
|
116
|
-
},
|
|
117
|
-
}
|
|
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
|
+
|
|
80
|
+
|
|
81
|
+
// 403 / 404
|
|
82
|
+
if (status === 403 || status === 404) {
|
|
83
|
+
try {
|
|
84
|
+
appStore.lancerErreur(payload)
|
|
85
|
+
if (router.currentRoute.value.name !== '403') {
|
|
86
|
+
router.push({ name: '403' })
|
|
87
|
+
}
|
|
88
|
+
} catch {
|
|
89
|
+
// no-op
|
|
90
|
+
}
|
|
91
|
+
return Promise.reject(payload)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// gérer les autres 4XX ici
|
|
95
|
+
|
|
96
|
+
// Log minimal
|
|
97
|
+
console.error('HTTP error', {
|
|
98
|
+
status,
|
|
99
|
+
url: error.config?.url,
|
|
100
|
+
payload,
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
// Remonter l’erreur normalisée dans appstore
|
|
104
|
+
try {
|
|
105
|
+
if (payload?.resultat) appStore.lancerErreur(payload)
|
|
106
|
+
} catch {
|
|
107
|
+
// no-op
|
|
108
|
+
}
|
|
109
|
+
return Promise.reject(payload)
|
|
110
|
+
},
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
// reset le flag si on l’avait utilisé pour forcer la recréation de l'instance
|
|
114
|
+
this.clearCache = false
|
|
115
|
+
return client
|
|
116
|
+
},
|
|
117
|
+
}
|
package/package.json
CHANGED