v-sistec-features 1.28.0 → 1.30.0
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/core.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/v-sistec-features.css +1 -1
- package/dist/vDataTable.d.ts +5 -0
- package/dist/vDataTable.js +696 -655
- package/package.json +1 -1
- package/src/DatatableVue/components/SearchDatatable.vue +0 -1
- package/src/DatatableVue/components/VDataTable.vue +3 -1
- package/src/DatatableVue/composables/useDataTableFetch.ts +112 -42
- package/src/DatatableVue/config/datatableDefaults.ts +3 -1
- package/src/DatatableVue/types/v-data-table.ts +7 -1
package/package.json
CHANGED
|
@@ -324,7 +324,7 @@ const {
|
|
|
324
324
|
const {
|
|
325
325
|
items, error, attempt, default_params,
|
|
326
326
|
fetchDataWithDelay, reSearch,
|
|
327
|
-
showLoadingState, first_fetch
|
|
327
|
+
showLoadingState, first_fetch, raw_items
|
|
328
328
|
} = useDataTableFetch<T>(options, pagination, columns, orderings_state, emit, close_all_expanded_items);
|
|
329
329
|
|
|
330
330
|
|
|
@@ -651,6 +651,8 @@ defineExpose<ExposedFunctions<T>>({
|
|
|
651
651
|
selectAllCheckbox,
|
|
652
652
|
toggleColumnVisibility,
|
|
653
653
|
columns_list,
|
|
654
|
+
items: readonly(items),
|
|
655
|
+
results: readonly(raw_items),
|
|
654
656
|
});
|
|
655
657
|
|
|
656
658
|
onMounted(() => {
|
|
@@ -3,7 +3,7 @@ import type { PaginationObject, DataTablePropsWithDefaults } from '../types/v-da
|
|
|
3
3
|
import { type ColumnConfiguration } from '../keys';
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
export function useDataTableFetch<T
|
|
6
|
+
export function useDataTableFetch<T extends Record<string, any>>(
|
|
7
7
|
/* para manter a reatividade a prop agora precisa usar unref*/
|
|
8
8
|
props: Ref<DataTablePropsWithDefaults>,
|
|
9
9
|
pagination: Ref<PaginationObject>,
|
|
@@ -13,13 +13,16 @@ export function useDataTableFetch<T>(
|
|
|
13
13
|
close_all_expanded_items: () => void
|
|
14
14
|
|
|
15
15
|
) {
|
|
16
|
-
|
|
17
|
-
const
|
|
16
|
+
// Estado para armazenar o retorno bruto da API
|
|
17
|
+
const raw_items = ref<T[]>([]) as Ref<T[]>;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const propsValue = computed(() => unref(props));
|
|
18
21
|
const urlReativa = computed(() => {
|
|
19
22
|
return propsValue.value.endpoint;
|
|
20
23
|
});
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
|
|
25
|
+
|
|
23
26
|
const default_params = computed<Record<string, any>>(() => ({
|
|
24
27
|
[propsValue.value.page_param_name]: pagination.value.current_page + 1,
|
|
25
28
|
[propsValue.value.page_size_param_name]: pagination.value.limit_per_page,
|
|
@@ -35,8 +38,8 @@ export function useDataTableFetch<T>(
|
|
|
35
38
|
objectOrdering[col.param_ordering] = col.increasing_value || 'increasing';
|
|
36
39
|
} else if (orderings_state.value[col.id] === 'decreasing') {
|
|
37
40
|
objectOrdering[col.param_ordering] = col.decreasing_value || 'decreasing';
|
|
38
|
-
}
|
|
39
|
-
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
return objectOrdering;
|
|
@@ -54,8 +57,8 @@ export function useDataTableFetch<T>(
|
|
|
54
57
|
const addParamsKeepPageIsFunction = typeof propsValue.value.add_params_keep_page === 'function';
|
|
55
58
|
let extraAddParamsKeepPage = {};
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
|
|
61
|
+
|
|
59
62
|
|
|
60
63
|
if (addParamsIsFunction) {
|
|
61
64
|
const getParams = propsValue.value.add_params as () => Record<string, any>;
|
|
@@ -101,17 +104,64 @@ export function useDataTableFetch<T>(
|
|
|
101
104
|
immediate: false,
|
|
102
105
|
}, propsValue.value.fetch_name);
|
|
103
106
|
|
|
107
|
+
const filtered_items = computed<T[]>(() => {
|
|
108
|
+
if (!propsValue.value.frontend_pagination) {
|
|
109
|
+
return raw_items.value;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let filtered = raw_items.value;
|
|
113
|
+
const customFilterFn = propsValue.value.custom_frontend_filter;
|
|
114
|
+
|
|
115
|
+
if (customFilterFn && typeof customFilterFn === 'function') {
|
|
116
|
+
filtered = filtered.filter(item =>
|
|
117
|
+
customFilterFn(item, pagination.value.search, pagination.value.filter)
|
|
118
|
+
);
|
|
119
|
+
} else if (pagination.value.search) {
|
|
120
|
+
const searchLower = pagination.value.search.toLowerCase();
|
|
121
|
+
filtered = filtered.filter(item => {
|
|
122
|
+
return Object.values(item).some(val =>
|
|
123
|
+
val !== null && val !== undefined && String(val).toLowerCase().includes(searchLower)
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return filtered;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
watch(filtered_items, (newVal) => {
|
|
132
|
+
if (propsValue.value.frontend_pagination) {
|
|
133
|
+
pagination.value.count = newVal.length;
|
|
134
|
+
|
|
135
|
+
const maxPage = Math.ceil(newVal.length / pagination.value.limit_per_page) - 1;
|
|
136
|
+
if (pagination.value.current_page > maxPage && maxPage >= 0) {
|
|
137
|
+
pagination.value.current_page = maxPage;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}, { immediate: true });
|
|
141
|
+
|
|
142
|
+
const items = computed<T[]>(() => {
|
|
143
|
+
if (!propsValue.value.frontend_pagination) {
|
|
144
|
+
return raw_items.value;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const start = pagination.value.current_page * pagination.value.limit_per_page;
|
|
148
|
+
const end = start + pagination.value.limit_per_page;
|
|
149
|
+
|
|
150
|
+
return filtered_items.value.slice(start, end);
|
|
151
|
+
});
|
|
152
|
+
|
|
104
153
|
const isDelaying = ref<boolean>(false);
|
|
105
154
|
const delayTimer = ref<ReturnType<typeof setTimeout> | null>(null);
|
|
106
155
|
const first_fetch = ref<boolean>(false);
|
|
107
156
|
// para controlar a exibição do loading
|
|
108
157
|
const showLoadingState = computed<boolean>(() => {
|
|
109
|
-
|
|
158
|
+
return (pending.value || isDelaying.value)
|
|
110
159
|
});
|
|
111
160
|
// Função que gerencia o delay e a chamada da API
|
|
112
161
|
async function fetchDataWithDelay(): Promise<void> {
|
|
113
162
|
// agora já fez pelo menos a primeira busca então marca como true
|
|
114
163
|
if (!first_fetch.value) first_fetch.value = true;
|
|
164
|
+
|
|
115
165
|
// Limpa timer anterior, se houver
|
|
116
166
|
if (delayTimer.value) clearTimeout(delayTimer.value);
|
|
117
167
|
|
|
@@ -120,53 +170,72 @@ export function useDataTableFetch<T>(
|
|
|
120
170
|
delayTimer.value = setTimeout(() => {
|
|
121
171
|
isDelaying.value = false;
|
|
122
172
|
}, propsValue.value.min_loading_delay);
|
|
173
|
+
|
|
123
174
|
close_all_expanded_items();
|
|
124
175
|
emit('beforeFetch');
|
|
125
|
-
|
|
176
|
+
if (!propsValue.value.frontend_pagination || raw_items.value.length === 0) {
|
|
177
|
+
await execute(); // Executa a busca de dados original do useApiFetch
|
|
178
|
+
}
|
|
179
|
+
|
|
126
180
|
emit('afterFetch');
|
|
127
181
|
}
|
|
128
182
|
|
|
129
183
|
function reSearch(): void {
|
|
130
184
|
pagination.value.current_page = propsValue.value.page_starts_at;
|
|
185
|
+
|
|
131
186
|
fetchDataWithDelay();
|
|
132
187
|
}
|
|
133
188
|
|
|
134
189
|
|
|
135
190
|
watch(response, (newResponse: any) => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
191
|
+
if (newResponse) {
|
|
192
|
+
let fetchedData = [];
|
|
193
|
+
|
|
194
|
+
// Aceitação de dados direto da raiz do objeto quando data_key for string vazia
|
|
195
|
+
if (!propsValue.value.data_key) {
|
|
196
|
+
fetchedData = Array.isArray(newResponse) ? newResponse : [newResponse];
|
|
197
|
+
} else {
|
|
198
|
+
fetchedData = newResponse[propsValue.value.data_key] || [];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
raw_items.value = fetchedData;
|
|
202
|
+
|
|
203
|
+
// O count é operado pelo frontend se a prop estiver ativa
|
|
204
|
+
if (!propsValue.value.frontend_pagination) {
|
|
205
|
+
pagination.value.count = newResponse[propsValue.value.total_key] || 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
} else {
|
|
209
|
+
raw_items.value = [];
|
|
210
|
+
pagination.value.count = 0;
|
|
211
|
+
}
|
|
143
212
|
}, { immediate: true });
|
|
144
|
-
|
|
213
|
+
|
|
145
214
|
watch(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
215
|
+
() => {
|
|
216
|
+
const params = typeof propsValue.value.add_params === 'function'
|
|
217
|
+
? propsValue.value.add_params()
|
|
218
|
+
: propsValue.value.add_params;
|
|
219
|
+
return JSON.stringify(params);
|
|
220
|
+
},
|
|
221
|
+
(newVal, oldVal) => {
|
|
222
|
+
if (newVal !== oldVal && oldVal !== undefined) {
|
|
223
|
+
reSearch();
|
|
224
|
+
}
|
|
155
225
|
}
|
|
156
|
-
}
|
|
157
226
|
);
|
|
158
227
|
watch(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
228
|
+
() => {
|
|
229
|
+
const params = typeof propsValue.value.add_params_keep_page === 'function'
|
|
230
|
+
? propsValue.value.add_params_keep_page()
|
|
231
|
+
: propsValue.value.add_params_keep_page;
|
|
232
|
+
return JSON.stringify(params);
|
|
233
|
+
},
|
|
234
|
+
(newVal, oldVal) => {
|
|
235
|
+
if (newVal !== oldVal && oldVal !== undefined) {
|
|
236
|
+
fetchDataWithDelay();
|
|
237
|
+
}
|
|
168
238
|
}
|
|
169
|
-
}
|
|
170
239
|
);
|
|
171
240
|
|
|
172
241
|
/*
|
|
@@ -176,10 +245,10 @@ export function useDataTableFetch<T>(
|
|
|
176
245
|
========
|
|
177
246
|
*/
|
|
178
247
|
watch(
|
|
179
|
-
|
|
248
|
+
() => propsValue.value.endpoint,
|
|
180
249
|
(newVal, oldVal) => {
|
|
181
250
|
if (newVal !== oldVal && oldVal !== undefined) {
|
|
182
|
-
|
|
251
|
+
pagination.value.current_page = propsValue.value.page_starts_at;
|
|
183
252
|
}
|
|
184
253
|
}
|
|
185
254
|
);
|
|
@@ -194,7 +263,8 @@ export function useDataTableFetch<T>(
|
|
|
194
263
|
fetchDataWithDelay,
|
|
195
264
|
reSearch,
|
|
196
265
|
showLoadingState,
|
|
197
|
-
first_fetch
|
|
266
|
+
first_fetch,
|
|
267
|
+
raw_items
|
|
198
268
|
|
|
199
269
|
};
|
|
200
270
|
}
|
|
@@ -11,7 +11,7 @@ export const defaultDataTableConfig: DataTableGlobalConfig = {
|
|
|
11
11
|
fetch_name: '',
|
|
12
12
|
custom_loading: null,
|
|
13
13
|
deactivate_default_params: false,
|
|
14
|
-
|
|
14
|
+
frontend_pagination: false,
|
|
15
15
|
add_params: {},
|
|
16
16
|
add_params_keep_page: {},
|
|
17
17
|
silent_params: {},
|
|
@@ -75,4 +75,6 @@ export const defaultDataTableConfig: DataTableGlobalConfig = {
|
|
|
75
75
|
show_header_when_empty: false,
|
|
76
76
|
storage_id: '',
|
|
77
77
|
use_column_manager: false,
|
|
78
|
+
|
|
79
|
+
custom_frontend_filter: null,
|
|
78
80
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Ref, ComputedRef, Component, MaybeRefOrGetter } from 'vue';
|
|
1
|
+
import type { Ref, ComputedRef, Component, MaybeRefOrGetter, DeepReadonly } from 'vue';
|
|
2
2
|
import type { PaginationObject } from '../keys';
|
|
3
3
|
|
|
4
4
|
export type { PaginationObject } from '../keys';
|
|
@@ -86,6 +86,7 @@ Tipagem para o comportamento principal.
|
|
|
86
86
|
Por que é usada: Controla limites, tempos de carregamento, armazenamento de estado e identificadores.
|
|
87
87
|
*/
|
|
88
88
|
export interface BehaviorProps {
|
|
89
|
+
frontend_pagination?: boolean;
|
|
89
90
|
limit_per_page?: number;
|
|
90
91
|
page_starts_at?: number;
|
|
91
92
|
/*
|
|
@@ -124,6 +125,7 @@ export interface SearchProps {
|
|
|
124
125
|
disable_search?: boolean;
|
|
125
126
|
deactivate_search_empty?: boolean;
|
|
126
127
|
deactivate_search_on_clear?: boolean;
|
|
128
|
+
custom_frontend_filter?: ((item: any, search: string, filter: string) => boolean) | null;
|
|
127
129
|
}
|
|
128
130
|
/*
|
|
129
131
|
Tipagem para regras de paginação.
|
|
@@ -179,6 +181,8 @@ Tipagem consolidada de propriedades do VDataTable com valores padrão.
|
|
|
179
181
|
Por que é usada: Fornece uma interface completa para o Vue, incluindo todas as propriedades obrigatórias e opcionais, com valores padrão definidos.
|
|
180
182
|
*/
|
|
181
183
|
export type DataTablePropsWithDefaults = VDataTableProps & {
|
|
184
|
+
custom_frontend_filter: ((item: any, search: string, filter: string) => boolean) | null;
|
|
185
|
+
frontend_pagination: boolean;
|
|
182
186
|
// Strings
|
|
183
187
|
fetch_name: string;
|
|
184
188
|
type_loading: string;
|
|
@@ -254,4 +258,6 @@ export interface ExposedFunctions<T extends Record<string, any>> {
|
|
|
254
258
|
visible: boolean;
|
|
255
259
|
locked: boolean;
|
|
256
260
|
}>>;
|
|
261
|
+
items: DeepReadonly<Ref<T[]>>;
|
|
262
|
+
results: DeepReadonly<Ref<T[]>>;
|
|
257
263
|
}
|