v-sistec-features 1.27.2 → 1.28.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 +2 -0
- package/dist/vDataTable.js +713 -685
- package/package.json +1 -1
- package/src/DatatableVue/components/VDataTable.vue +7 -41
- package/src/DatatableVue/composables/useDataTableFetch.ts +109 -24
- package/src/DatatableVue/config/datatableDefaults.ts +3 -0
- package/src/DatatableVue/types/v-data-table.ts +16 -0
package/package.json
CHANGED
|
@@ -245,7 +245,7 @@
|
|
|
245
245
|
|
|
246
246
|
<script setup lang="ts" generic="T extends Record<string, any>">
|
|
247
247
|
import type { VDataTableProps, ExposedFunctions, PaginationObject } from '../types/v-data-table.ts';
|
|
248
|
-
import { readonly, ref, provide, computed,
|
|
248
|
+
import { readonly, ref, provide, computed, nextTick, onMounted } from 'vue';
|
|
249
249
|
import PaginationDatatable from '@/Pagination/Pagination.vue';
|
|
250
250
|
import Search from './SearchDatatable.vue';
|
|
251
251
|
import VColumnManager from './VColumnManager.vue';
|
|
@@ -291,7 +291,7 @@ const emit = defineEmits(['tradePage', 'beforeFetch', 'afterFetch', 'clickedClea
|
|
|
291
291
|
|
|
292
292
|
const orderings_state = ref<Record<string, 'none' | 'increasing' | 'decreasing'>>({});
|
|
293
293
|
const columns = ref<ColumnConfiguration[]>([]);
|
|
294
|
-
|
|
294
|
+
|
|
295
295
|
|
|
296
296
|
|
|
297
297
|
|
|
@@ -322,10 +322,10 @@ const {
|
|
|
322
322
|
);
|
|
323
323
|
|
|
324
324
|
const {
|
|
325
|
-
items, error,
|
|
325
|
+
items, error, attempt, default_params,
|
|
326
326
|
fetchDataWithDelay, reSearch,
|
|
327
327
|
showLoadingState, first_fetch
|
|
328
|
-
} = useDataTableFetch<T>(options
|
|
328
|
+
} = useDataTableFetch<T>(options, pagination, columns, orderings_state, emit, close_all_expanded_items);
|
|
329
329
|
|
|
330
330
|
|
|
331
331
|
const {
|
|
@@ -492,16 +492,7 @@ const hasItems = computed(() => {
|
|
|
492
492
|
|
|
493
493
|
|
|
494
494
|
|
|
495
|
-
|
|
496
|
-
if (newResponse) {
|
|
497
|
-
items.value = newResponse[options.value.data_key] || [];
|
|
498
|
-
totalItems.value = newResponse[options.value.total_key] || 0;
|
|
499
|
-
pagination.value.count = totalItems.value;
|
|
500
|
-
} else {
|
|
501
|
-
items.value = [];
|
|
502
|
-
totalItems.value = 0;
|
|
503
|
-
}
|
|
504
|
-
}, { immediate: true });
|
|
495
|
+
|
|
505
496
|
|
|
506
497
|
|
|
507
498
|
// =======================================================
|
|
@@ -677,33 +668,8 @@ onMounted(() => {
|
|
|
677
668
|
});
|
|
678
669
|
});
|
|
679
670
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
const params = typeof options.value.add_params === 'function'
|
|
683
|
-
? options.value.add_params()
|
|
684
|
-
: options.value.add_params;
|
|
685
|
-
return JSON.stringify(params);
|
|
686
|
-
},
|
|
687
|
-
(newVal, oldVal) => {
|
|
688
|
-
if (newVal !== oldVal && oldVal !== undefined) {
|
|
689
|
-
reSearch();
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
);
|
|
693
|
-
/*
|
|
694
|
-
========
|
|
695
|
-
Observa mudanças no endpoint.
|
|
696
|
-
Caso a rota da API mude dinamicamente, ele reseta a tabela para a página inicial com segurança.
|
|
697
|
-
========
|
|
698
|
-
*/
|
|
699
|
-
watch(
|
|
700
|
-
() => options.value.endpoint,
|
|
701
|
-
(newVal, oldVal) => {
|
|
702
|
-
if (newVal !== oldVal && oldVal !== undefined) {
|
|
703
|
-
pagination.value.current_page = options.value.page_starts_at;
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
);
|
|
671
|
+
|
|
672
|
+
|
|
707
673
|
</script>
|
|
708
674
|
|
|
709
675
|
<style lang="scss" scoped>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ref, computed, type Ref } from 'vue';
|
|
1
|
+
import { ref, computed, type Ref, watch, unref } from 'vue';
|
|
2
2
|
import type { PaginationObject, DataTablePropsWithDefaults } from '../types/v-data-table'; // Ajuste o caminho conforme necessário
|
|
3
3
|
import { type ColumnConfiguration } from '../keys';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export function useDataTableFetch<T>(
|
|
7
|
-
|
|
7
|
+
/* para manter a reatividade a prop agora precisa usar unref*/
|
|
8
|
+
props: Ref<DataTablePropsWithDefaults>,
|
|
8
9
|
pagination: Ref<PaginationObject>,
|
|
9
10
|
columns: Ref<ColumnConfiguration[]>,
|
|
10
11
|
orderings_state: Ref<Record<string, 'none' | 'increasing' | 'decreasing'>>,
|
|
@@ -13,16 +14,17 @@ export function useDataTableFetch<T>(
|
|
|
13
14
|
|
|
14
15
|
) {
|
|
15
16
|
const items = ref<T[]>([]) as Ref<T[]>;
|
|
16
|
-
|
|
17
|
+
const propsValue = computed(() => unref(props));
|
|
17
18
|
const urlReativa = computed(() => {
|
|
18
|
-
return
|
|
19
|
+
return propsValue.value.endpoint;
|
|
19
20
|
});
|
|
20
21
|
|
|
22
|
+
|
|
21
23
|
const default_params = computed<Record<string, any>>(() => ({
|
|
22
|
-
[
|
|
23
|
-
[
|
|
24
|
-
[
|
|
25
|
-
[
|
|
24
|
+
[propsValue.value.page_param_name]: pagination.value.current_page + 1,
|
|
25
|
+
[propsValue.value.page_size_param_name]: pagination.value.limit_per_page,
|
|
26
|
+
[propsValue.value.search_param_name]: pagination.value.search || "",
|
|
27
|
+
[propsValue.value.filter_param_name]: pagination.value.filter || "",
|
|
26
28
|
}));
|
|
27
29
|
|
|
28
30
|
const params_ordering = computed(() => {
|
|
@@ -39,35 +41,65 @@ export function useDataTableFetch<T>(
|
|
|
39
41
|
|
|
40
42
|
return objectOrdering;
|
|
41
43
|
});
|
|
42
|
-
const { data: response, pending, error, execute, attempt } =
|
|
43
|
-
disable_request: () =>
|
|
44
|
+
const { data: response, pending, error, execute, attempt } = propsValue.value.fetch(urlReativa, {
|
|
45
|
+
disable_request: () => propsValue.value.disable_request,
|
|
44
46
|
params: () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
/*add_params*/
|
|
48
|
+
const addParamsIsFunction = typeof propsValue.value.add_params === 'function';
|
|
49
|
+
let extraAddParams = {};
|
|
50
|
+
/*silent_params*/
|
|
51
|
+
const silentParamsIsFunction = typeof propsValue.value.silent_params === 'function';
|
|
52
|
+
let extraSilentParams = {};
|
|
53
|
+
/*add_params_keep_page*/
|
|
54
|
+
const addParamsKeepPageIsFunction = typeof propsValue.value.add_params_keep_page === 'function';
|
|
55
|
+
let extraAddParamsKeepPage = {};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if (addParamsIsFunction) {
|
|
61
|
+
const getParams = propsValue.value.add_params as () => Record<string, any>;
|
|
62
|
+
extraAddParams = getParams();
|
|
63
|
+
} else {
|
|
64
|
+
extraAddParams = propsValue.value.add_params || {};
|
|
65
|
+
}
|
|
47
66
|
|
|
48
|
-
if (
|
|
49
|
-
const getParams =
|
|
50
|
-
|
|
67
|
+
if (silentParamsIsFunction) {
|
|
68
|
+
const getParams = propsValue.value.silent_params as () => Record<string, any>;
|
|
69
|
+
extraSilentParams = getParams();
|
|
51
70
|
} else {
|
|
52
|
-
|
|
71
|
+
extraSilentParams = propsValue.value.silent_params || {};
|
|
53
72
|
}
|
|
54
|
-
|
|
73
|
+
|
|
74
|
+
if (addParamsKeepPageIsFunction) {
|
|
75
|
+
const getParams = propsValue.value.add_params_keep_page as () => Record<string, any>;
|
|
76
|
+
extraAddParamsKeepPage = getParams();
|
|
77
|
+
} else {
|
|
78
|
+
extraAddParamsKeepPage = propsValue.value.add_params_keep_page || {};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if (propsValue.value.deactivate_default_params) {
|
|
55
83
|
return {
|
|
56
|
-
...
|
|
84
|
+
...extraAddParams,
|
|
85
|
+
...extraSilentParams,
|
|
86
|
+
...extraAddParamsKeepPage,
|
|
57
87
|
...params_ordering.value
|
|
58
88
|
};
|
|
59
89
|
}
|
|
60
90
|
return {
|
|
61
91
|
...default_params.value,
|
|
62
|
-
...
|
|
92
|
+
...extraAddParams,
|
|
93
|
+
...extraSilentParams,
|
|
94
|
+
...extraAddParamsKeepPage,
|
|
63
95
|
...params_ordering.value
|
|
64
96
|
};
|
|
65
97
|
},
|
|
66
|
-
retry:
|
|
67
|
-
retryDelay:
|
|
98
|
+
retry: propsValue.value.retry_attempts,
|
|
99
|
+
retryDelay: propsValue.value.retry_delay,
|
|
68
100
|
paramsReactives: false,
|
|
69
101
|
immediate: false,
|
|
70
|
-
},
|
|
102
|
+
}, propsValue.value.fetch_name);
|
|
71
103
|
|
|
72
104
|
const isDelaying = ref<boolean>(false);
|
|
73
105
|
const delayTimer = ref<ReturnType<typeof setTimeout> | null>(null);
|
|
@@ -87,7 +119,7 @@ export function useDataTableFetch<T>(
|
|
|
87
119
|
|
|
88
120
|
delayTimer.value = setTimeout(() => {
|
|
89
121
|
isDelaying.value = false;
|
|
90
|
-
},
|
|
122
|
+
}, propsValue.value.min_loading_delay);
|
|
91
123
|
close_all_expanded_items();
|
|
92
124
|
emit('beforeFetch');
|
|
93
125
|
await execute(); // Executa a busca de dados original do useApiFetch
|
|
@@ -95,9 +127,62 @@ export function useDataTableFetch<T>(
|
|
|
95
127
|
}
|
|
96
128
|
|
|
97
129
|
function reSearch(): void {
|
|
98
|
-
pagination.value.current_page =
|
|
130
|
+
pagination.value.current_page = propsValue.value.page_starts_at;
|
|
99
131
|
fetchDataWithDelay();
|
|
100
132
|
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
watch(response, (newResponse: any) => {
|
|
136
|
+
if (newResponse) {
|
|
137
|
+
items.value = newResponse[propsValue.value.data_key] || [];
|
|
138
|
+
pagination.value.count = newResponse[propsValue.value.total_key] || 0;
|
|
139
|
+
} else {
|
|
140
|
+
items.value = [];
|
|
141
|
+
pagination.value.count = 0;
|
|
142
|
+
}
|
|
143
|
+
}, { immediate: true });
|
|
144
|
+
|
|
145
|
+
watch(
|
|
146
|
+
() => {
|
|
147
|
+
const params = typeof propsValue.value.add_params === 'function'
|
|
148
|
+
? propsValue.value.add_params()
|
|
149
|
+
: propsValue.value.add_params;
|
|
150
|
+
return JSON.stringify(params);
|
|
151
|
+
},
|
|
152
|
+
(newVal, oldVal) => {
|
|
153
|
+
if (newVal !== oldVal && oldVal !== undefined) {
|
|
154
|
+
reSearch();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
watch(
|
|
159
|
+
() => {
|
|
160
|
+
const params = typeof propsValue.value.add_params_keep_page === 'function'
|
|
161
|
+
? propsValue.value.add_params_keep_page()
|
|
162
|
+
: propsValue.value.add_params_keep_page;
|
|
163
|
+
return JSON.stringify(params);
|
|
164
|
+
},
|
|
165
|
+
(newVal, oldVal) => {
|
|
166
|
+
if (newVal !== oldVal && oldVal !== undefined) {
|
|
167
|
+
fetchDataWithDelay();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
/*
|
|
173
|
+
========
|
|
174
|
+
Observa mudanças no endpoint.
|
|
175
|
+
Caso a rota da API mude dinamicamente, ele reseta a tabela para a página inicial com segurança.
|
|
176
|
+
========
|
|
177
|
+
*/
|
|
178
|
+
watch(
|
|
179
|
+
() => propsValue.value.endpoint,
|
|
180
|
+
(newVal, oldVal) => {
|
|
181
|
+
if (newVal !== oldVal && oldVal !== undefined) {
|
|
182
|
+
pagination.value.current_page = propsValue.value.page_starts_at;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
);
|
|
101
186
|
return {
|
|
102
187
|
items,
|
|
103
188
|
pending,
|
|
@@ -21,7 +21,23 @@ export interface ApiProps {
|
|
|
21
21
|
search_param_name?: string;
|
|
22
22
|
page_param_name?: string;
|
|
23
23
|
page_size_param_name?: string;
|
|
24
|
+
/*
|
|
25
|
+
Parâmetros reativos: dispara um novo fetch e reseta a tabela para a página 1 sempre que sofrer mutação.
|
|
26
|
+
Ideal para buscas e filtros primários.
|
|
27
|
+
*/
|
|
24
28
|
add_params?: Record<string, any> | (() => Record<string, any>);
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
Parâmetros de recarregamento suave: dispara um novo fetch quando alterados, mas NÃO reseta a página atual.
|
|
32
|
+
Ideal para ordenação externa ou filtros que não devem interromper a navegação.
|
|
33
|
+
*/
|
|
34
|
+
add_params_keep_page?: Record<string, any> | (() => Record<string, any>);
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
Parâmetros silenciosos: injeta dados na requisição sem disparar um fetch automático.
|
|
38
|
+
Ideal para injeção de paginação manual ou tokens.
|
|
39
|
+
*/
|
|
40
|
+
silent_params?: Record<string, any> | (() => Record<string, any>);
|
|
25
41
|
/* retira os params default da requisição */
|
|
26
42
|
deactivate_default_params?: boolean;
|
|
27
43
|
disable_request?: MaybeRefOrGetter<boolean>;
|