shared-ritm 1.3.87 → 1.3.89
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/dist/index.css +1 -1
- package/dist/shared-ritm.es.js +6 -5
- package/dist/shared-ritm.umd.js +2 -2
- package/dist/types/api/types/Api_User.d.ts +2 -0
- package/package.json +1 -1
- package/src/api/settings/ApiService.ts +184 -184
- package/src/api/types/Api_User.ts +3 -0
- package/src/common/app-table/components/TableModal.vue +5 -3
|
@@ -109,11 +109,13 @@ export type Api_User_Role = {
|
|
|
109
109
|
display_name: string;
|
|
110
110
|
permissions?: Api_User_Permission[];
|
|
111
111
|
};
|
|
112
|
+
export type Api_User_Position_Type = 'admin' | 'worker' | null;
|
|
112
113
|
export type Api_User_Position = {
|
|
113
114
|
id: string;
|
|
114
115
|
name: string;
|
|
115
116
|
display_name: string;
|
|
116
117
|
description?: string;
|
|
118
|
+
type?: Api_User_Position_Type;
|
|
117
119
|
};
|
|
118
120
|
export type Api_User_Delete_Body = {
|
|
119
121
|
user_id: string;
|
package/package.json
CHANGED
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
|
2
|
-
import { Api_Auth_Login } from '@/api/types/Api_Auth'
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line
|
|
5
|
-
var isRefreshing = false
|
|
6
|
-
// eslint-disable-next-line
|
|
7
|
-
var refreshSubscribers: any[] = []
|
|
8
|
-
|
|
9
|
-
interface Api_Auth_Refresh {
|
|
10
|
-
accessToken: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export enum ApiServiceType {
|
|
14
|
-
SERVICE_AUTH = 'SERVICE_AUTH',
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default class ApiService {
|
|
18
|
-
private axiosInstance: AxiosInstance
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
this.axiosInstance = axios.create({
|
|
22
|
-
baseURL: process.env.VUE_APP_BACKEND,
|
|
23
|
-
headers: {
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
Accept: 'application/json',
|
|
26
|
-
},
|
|
27
|
-
withCredentials: true,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
this.axiosInstance.interceptors.request.use(
|
|
31
|
-
(config: InternalAxiosRequestConfig) => {
|
|
32
|
-
config.headers.Authorization = `Bearer ${this.getAccessToken()}`
|
|
33
|
-
return config
|
|
34
|
-
},
|
|
35
|
-
(error: AxiosError) => {
|
|
36
|
-
return Promise.reject(error)
|
|
37
|
-
},
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
this.axiosInstance.interceptors.response.use(
|
|
41
|
-
(response: AxiosResponse) => {
|
|
42
|
-
return response.data
|
|
43
|
-
},
|
|
44
|
-
async error => {
|
|
45
|
-
const originalRequest = error.config
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
error.response?.status !== 401 ||
|
|
49
|
-
originalRequest.url === '/v2/auth/refresh' ||
|
|
50
|
-
originalRequest.url === '/v2/login' ||
|
|
51
|
-
originalRequest._retry
|
|
52
|
-
) {
|
|
53
|
-
return Promise.reject(error)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
originalRequest._retry = true
|
|
57
|
-
|
|
58
|
-
if (isRefreshing) {
|
|
59
|
-
return new Promise(resolve => {
|
|
60
|
-
this.subscribeTokenRefresh(() => resolve(this.axiosInstance(originalRequest)))
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
isRefreshing = true
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const response = await this.refresh()
|
|
68
|
-
|
|
69
|
-
const newToken = response.accessToken
|
|
70
|
-
if (!newToken) {
|
|
71
|
-
await this.logoutUser()
|
|
72
|
-
return Promise.reject(error)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this.setAccessToken(newToken)
|
|
76
|
-
this.onRefreshed()
|
|
77
|
-
isRefreshing = false
|
|
78
|
-
return this.axiosInstance(originalRequest)
|
|
79
|
-
} catch (e) {
|
|
80
|
-
await this.logoutUser()
|
|
81
|
-
return Promise.reject(e)
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private setAccessToken(token: string) {
|
|
88
|
-
localStorage.setItem('token', token)
|
|
89
|
-
}
|
|
90
|
-
private getAccessToken() {
|
|
91
|
-
return localStorage.getItem('token')
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
private removeToken() {
|
|
95
|
-
localStorage.removeItem('token')
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private subscribeTokenRefresh(cb: any) {
|
|
99
|
-
refreshSubscribers.push(cb)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private refresh(): Promise<Api_Auth_Refresh> {
|
|
103
|
-
return this.post<null, Api_Auth_Login>(`/v2/auth/refresh`, null)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private onRefreshed() {
|
|
107
|
-
refreshSubscribers.forEach(cb => cb())
|
|
108
|
-
refreshSubscribers = []
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public async logoutUser(): Promise<any> {
|
|
112
|
-
isRefreshing = false
|
|
113
|
-
await this.post<any, any>(`/v2/logout`, null)
|
|
114
|
-
this.removeToken()
|
|
115
|
-
window.location.href = '/sign-in'
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private handleError(error: AxiosError): void {
|
|
119
|
-
if (error.response) {
|
|
120
|
-
console.error('API Error:', error.response.status, error.response.data)
|
|
121
|
-
} else if (error.request) {
|
|
122
|
-
console.error('No response received:', error.request)
|
|
123
|
-
} else {
|
|
124
|
-
console.error('Error during request setup:', error.message)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
protected async get<T>(url: string, options?: AxiosRequestConfig) {
|
|
129
|
-
try {
|
|
130
|
-
const response: AxiosResponse<T> = await this.axiosInstance.get<T>(url, options)
|
|
131
|
-
if (response?.data === false) return false as unknown as T
|
|
132
|
-
|
|
133
|
-
return response?.data ?? (response as unknown as T)
|
|
134
|
-
} catch (error) {
|
|
135
|
-
const axiosError = error as AxiosError
|
|
136
|
-
this.handleError(axiosError)
|
|
137
|
-
throw error
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
protected async delete<T>(url: string, options?: AxiosRequestConfig) {
|
|
142
|
-
try {
|
|
143
|
-
return await this.axiosInstance.delete<T>(url, options)
|
|
144
|
-
} catch (error) {
|
|
145
|
-
const axiosError = error as AxiosError
|
|
146
|
-
this.handleError(axiosError)
|
|
147
|
-
throw error
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
protected async post<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
|
|
152
|
-
try {
|
|
153
|
-
const response: AxiosResponse<T2> = await this.axiosInstance.post<T1, AxiosResponse<T2>>(url, payload, options)
|
|
154
|
-
if (response?.data === false) return false
|
|
155
|
-
return response?.data || (response as any)
|
|
156
|
-
} catch (error) {
|
|
157
|
-
const axiosError = error as AxiosError
|
|
158
|
-
this.handleError(axiosError)
|
|
159
|
-
throw error
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
protected async patch<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig): Promise<T2> {
|
|
164
|
-
try {
|
|
165
|
-
const response: AxiosResponse<T2> = await this.axiosInstance.patch<T1, AxiosResponse<T2>>(url, payload, options)
|
|
166
|
-
return response.data
|
|
167
|
-
} catch (error) {
|
|
168
|
-
const axiosError = error as AxiosError
|
|
169
|
-
this.handleError(axiosError)
|
|
170
|
-
throw error
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
protected async put<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
|
|
175
|
-
try {
|
|
176
|
-
const response: AxiosResponse<T2> = await this.axiosInstance.put<T1, AxiosResponse<T2>>(url, payload, options)
|
|
177
|
-
return response.data
|
|
178
|
-
} catch (error) {
|
|
179
|
-
const axiosError = error as AxiosError
|
|
180
|
-
this.handleError(axiosError)
|
|
181
|
-
throw error
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
1
|
+
import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
|
|
2
|
+
import { Api_Auth_Login } from '@/api/types/Api_Auth'
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line
|
|
5
|
+
var isRefreshing = false
|
|
6
|
+
// eslint-disable-next-line
|
|
7
|
+
var refreshSubscribers: any[] = []
|
|
8
|
+
|
|
9
|
+
interface Api_Auth_Refresh {
|
|
10
|
+
accessToken: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum ApiServiceType {
|
|
14
|
+
SERVICE_AUTH = 'SERVICE_AUTH',
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default class ApiService {
|
|
18
|
+
private axiosInstance: AxiosInstance
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
this.axiosInstance = axios.create({
|
|
22
|
+
baseURL: process.env.VUE_APP_BACKEND,
|
|
23
|
+
headers: {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
Accept: 'application/json',
|
|
26
|
+
},
|
|
27
|
+
withCredentials: true,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
this.axiosInstance.interceptors.request.use(
|
|
31
|
+
(config: InternalAxiosRequestConfig) => {
|
|
32
|
+
config.headers.Authorization = `Bearer ${this.getAccessToken()}`
|
|
33
|
+
return config
|
|
34
|
+
},
|
|
35
|
+
(error: AxiosError) => {
|
|
36
|
+
return Promise.reject(error)
|
|
37
|
+
},
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
this.axiosInstance.interceptors.response.use(
|
|
41
|
+
(response: AxiosResponse) => {
|
|
42
|
+
return response.data
|
|
43
|
+
},
|
|
44
|
+
async error => {
|
|
45
|
+
const originalRequest = error.config
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
error.response?.status !== 401 ||
|
|
49
|
+
originalRequest.url === '/v2/auth/refresh' ||
|
|
50
|
+
originalRequest.url === '/v2/login' ||
|
|
51
|
+
originalRequest._retry
|
|
52
|
+
) {
|
|
53
|
+
return Promise.reject(error)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
originalRequest._retry = true
|
|
57
|
+
|
|
58
|
+
if (isRefreshing) {
|
|
59
|
+
return new Promise(resolve => {
|
|
60
|
+
this.subscribeTokenRefresh(() => resolve(this.axiosInstance(originalRequest)))
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
isRefreshing = true
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const response = await this.refresh()
|
|
68
|
+
|
|
69
|
+
const newToken = response.accessToken
|
|
70
|
+
if (!newToken) {
|
|
71
|
+
await this.logoutUser()
|
|
72
|
+
return Promise.reject(error)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.setAccessToken(newToken)
|
|
76
|
+
this.onRefreshed()
|
|
77
|
+
isRefreshing = false
|
|
78
|
+
return this.axiosInstance(originalRequest)
|
|
79
|
+
} catch (e) {
|
|
80
|
+
await this.logoutUser()
|
|
81
|
+
return Promise.reject(e)
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private setAccessToken(token: string) {
|
|
88
|
+
localStorage.setItem('token', token)
|
|
89
|
+
}
|
|
90
|
+
private getAccessToken() {
|
|
91
|
+
return localStorage.getItem('token')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private removeToken() {
|
|
95
|
+
localStorage.removeItem('token')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private subscribeTokenRefresh(cb: any) {
|
|
99
|
+
refreshSubscribers.push(cb)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private refresh(): Promise<Api_Auth_Refresh> {
|
|
103
|
+
return this.post<null, Api_Auth_Login>(`/v2/auth/refresh`, null)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private onRefreshed() {
|
|
107
|
+
refreshSubscribers.forEach(cb => cb())
|
|
108
|
+
refreshSubscribers = []
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public async logoutUser(): Promise<any> {
|
|
112
|
+
isRefreshing = false
|
|
113
|
+
await this.post<any, any>(`/v2/logout`, null)
|
|
114
|
+
this.removeToken()
|
|
115
|
+
window.location.href = '/sign-in'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private handleError(error: AxiosError): void {
|
|
119
|
+
if (error.response) {
|
|
120
|
+
console.error('API Error:', error.response.status, error.response.data)
|
|
121
|
+
} else if (error.request) {
|
|
122
|
+
console.error('No response received:', error.request)
|
|
123
|
+
} else {
|
|
124
|
+
console.error('Error during request setup:', error.message)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
protected async get<T>(url: string, options?: AxiosRequestConfig) {
|
|
129
|
+
try {
|
|
130
|
+
const response: AxiosResponse<T> = await this.axiosInstance.get<T>(url, options)
|
|
131
|
+
if (response?.data === false) return false as unknown as T
|
|
132
|
+
|
|
133
|
+
return response?.data ?? (response as unknown as T)
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const axiosError = error as AxiosError
|
|
136
|
+
this.handleError(axiosError)
|
|
137
|
+
throw error
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
protected async delete<T>(url: string, options?: AxiosRequestConfig) {
|
|
142
|
+
try {
|
|
143
|
+
return await this.axiosInstance.delete<T>(url, options)
|
|
144
|
+
} catch (error) {
|
|
145
|
+
const axiosError = error as AxiosError
|
|
146
|
+
this.handleError(axiosError)
|
|
147
|
+
throw error
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
protected async post<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
|
|
152
|
+
try {
|
|
153
|
+
const response: AxiosResponse<T2> = await this.axiosInstance.post<T1, AxiosResponse<T2>>(url, payload, options)
|
|
154
|
+
if (response?.data === false) return false
|
|
155
|
+
return response?.data || (response as any)
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const axiosError = error as AxiosError
|
|
158
|
+
this.handleError(axiosError)
|
|
159
|
+
throw error
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
protected async patch<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig): Promise<T2> {
|
|
164
|
+
try {
|
|
165
|
+
const response: AxiosResponse<T2> = await this.axiosInstance.patch<T1, AxiosResponse<T2>>(url, payload, options)
|
|
166
|
+
return response.data
|
|
167
|
+
} catch (error) {
|
|
168
|
+
const axiosError = error as AxiosError
|
|
169
|
+
this.handleError(axiosError)
|
|
170
|
+
throw error
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected async put<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
|
|
175
|
+
try {
|
|
176
|
+
const response: AxiosResponse<T2> = await this.axiosInstance.put<T1, AxiosResponse<T2>>(url, payload, options)
|
|
177
|
+
return response.data
|
|
178
|
+
} catch (error) {
|
|
179
|
+
const axiosError = error as AxiosError
|
|
180
|
+
this.handleError(axiosError)
|
|
181
|
+
throw error
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -117,11 +117,14 @@ export type Api_User_Role = {
|
|
|
117
117
|
permissions?: Api_User_Permission[]
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
export type Api_User_Position_Type = 'admin' | 'worker' | null
|
|
121
|
+
|
|
120
122
|
export type Api_User_Position = {
|
|
121
123
|
id: string
|
|
122
124
|
name: string
|
|
123
125
|
display_name: string
|
|
124
126
|
description?: string
|
|
127
|
+
type?: Api_User_Position_Type
|
|
125
128
|
}
|
|
126
129
|
|
|
127
130
|
export type Api_User_Delete_Body = {
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
:options="filteredOptions[field.key] || field.options"
|
|
56
56
|
:rules="field.rules"
|
|
57
57
|
:placeholder="mode === 'view' ? '' : field.placeholder"
|
|
58
|
-
:multiple="
|
|
59
|
-
:show-chip="
|
|
58
|
+
:multiple="!field.simple"
|
|
59
|
+
:show-chip="!field.simple"
|
|
60
60
|
:is-disabled="mode === 'view'"
|
|
61
61
|
:loading="field.loading"
|
|
62
62
|
:label="field.label"
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
option-label="label"
|
|
66
66
|
option-value="value"
|
|
67
67
|
chip-color="#e9eff9"
|
|
68
|
+
:simple="field.simple"
|
|
68
69
|
@update:search="val => field.onSearch?.(val)"
|
|
69
70
|
@update:scroll="() => field.onScroll?.()"
|
|
70
71
|
@clear="
|
|
@@ -129,6 +130,7 @@ interface FieldSchema {
|
|
|
129
130
|
onSearch?: (val: string) => void
|
|
130
131
|
onScroll?: () => void
|
|
131
132
|
loading?: boolean
|
|
133
|
+
simple?: boolean
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
const props = defineProps<{
|
|
@@ -227,7 +229,7 @@ function submit() {
|
|
|
227
229
|
}
|
|
228
230
|
function handleClear(key: string) {
|
|
229
231
|
const field = props.fields.find(f => f.key === key)
|
|
230
|
-
formData.value[key] = field?.type === 'select' ? [] : ''
|
|
232
|
+
formData.value[key] = field?.type === 'select' ? (field.simple ? null : []) : ''
|
|
231
233
|
|
|
232
234
|
nextTick(() => {
|
|
233
235
|
formRef.value?.validate()
|