v-sistec-features 1.25.0 → 1.26.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 -2
- package/dist/vDataTable.js +794 -677
- package/package.json +1 -1
- package/src/DatatableVue/components/SearchDatatable.vue +93 -51
- package/src/DatatableVue/components/VColumn.vue +2 -1
- package/src/DatatableVue/components/VDataTable.vue +147 -18
- package/src/DatatableVue/components/VOrderingIcon.vue +50 -0
- package/src/DatatableVue/components/VThDataTable.vue +19 -49
- package/src/DatatableVue/composables/useDataTableFetch.ts +1 -2
- package/src/DatatableVue/keys.ts +2 -0
- package/src/DatatableVue/types/v-data-table.ts +5 -0
package/package.json
CHANGED
|
@@ -1,57 +1,93 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="dropdown d-flex">
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<path
|
|
10
|
-
d="M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227z">
|
|
11
|
-
</path>
|
|
12
|
-
</svg>
|
|
13
|
-
</a>
|
|
14
|
-
<div class="input-icon">
|
|
15
|
-
<input type="text" class="form-control ms-1" id="inputSearchVDataTable" v-model="modelSearch"
|
|
16
|
-
@keyup.enter="searchEnter" :placeholder="placeholder_search">
|
|
17
|
-
|
|
18
|
-
<span v-if="modelSearch" @click="cleanSearch()" class=" inputClose" title="Limpar pesquisa">
|
|
19
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
20
|
-
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
21
|
-
class="icon icon-tabler icons-tabler-outline icon-tabler-x">
|
|
22
|
-
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
23
|
-
<path d="M18 6l-12 12" />
|
|
24
|
-
<path d="M6 6l12 12" />
|
|
25
|
-
</svg>
|
|
26
|
-
</span>
|
|
27
|
-
<span v-else class="input-icon-addon">
|
|
28
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
29
|
-
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon">
|
|
3
|
+
<slot name="search-field">
|
|
4
|
+
<a v-if="item_use.includes(2)" href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown"
|
|
5
|
+
title="Pesquisas Prédefinidas">
|
|
6
|
+
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-filter" width="24"
|
|
7
|
+
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
|
|
8
|
+
stroke-linecap="round" stroke-linejoin="round">
|
|
30
9
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
|
31
|
-
<path
|
|
32
|
-
|
|
10
|
+
<path
|
|
11
|
+
d="M4 4h16v2.172a2 2 0 0 1 -.586 1.414l-4.414 4.414v7l-6 2v-8.5l-4.48 -4.928a2 2 0 0 1 -.52 -1.345v-2.227z">
|
|
12
|
+
</path>
|
|
33
13
|
</svg>
|
|
34
|
-
</
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
14
|
+
</a>
|
|
15
|
+
<div class="input-icon">
|
|
16
|
+
<input type="text" class="form-control ms-1" id="inputSearchVDataTable" v-model="modelSearch"
|
|
17
|
+
@keyup.enter="searchEnter" :placeholder="placeholder_search">
|
|
18
|
+
|
|
19
|
+
<span v-if="modelSearch" @click="cleanSearch()" class=" inputClose" title="Limpar pesquisa">
|
|
20
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
21
|
+
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
22
|
+
class="icon icon-tabler icons-tabler-outline icon-tabler-x">
|
|
23
|
+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
24
|
+
<path d="M18 6l-12 12" />
|
|
25
|
+
<path d="M6 6l12 12" />
|
|
26
|
+
</svg>
|
|
27
|
+
</span>
|
|
28
|
+
<span v-else class="input-icon-addon">
|
|
29
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
30
|
+
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
31
|
+
class="icon">
|
|
32
|
+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
|
33
|
+
<path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"></path>
|
|
34
|
+
<path d="M21 21l-6 -6"></path>
|
|
35
|
+
</svg>
|
|
36
|
+
</span>
|
|
37
|
+
</div>
|
|
38
|
+
<div v-if="item_use.includes(2)" class="dropdown-menu">
|
|
39
|
+
<template v-for="(filter, index) in props.list_filter" :key="index">
|
|
40
|
+
<router-link
|
|
41
|
+
v-if="('type' in filter ? filter.type === 1 : false) && ('visible' in filter ? filter.visible : true)"
|
|
42
|
+
:to="filter?.to" class="dropdown-item cursor-pointer">
|
|
43
|
+
{{ filter.text }}
|
|
44
|
+
</router-link>
|
|
45
|
+
<a v-else-if="('type' in filter ? filter.type === 2 : true) && ('visible' in filter ? filter.visible : true)"
|
|
46
|
+
@click.prevent="tradeFilter(String(filter.value))" class="dropdown-item cursor-pointer"
|
|
47
|
+
:class="modelFilter === filter?.value ? 'bg-info text-dark selected' : ''">
|
|
48
|
+
{{ filter.text }}
|
|
49
|
+
</a>
|
|
50
|
+
<a v-else-if="('type' in filter ? filter.type === 3 : true) && ('visible' in filter ? filter.visible : true)"
|
|
51
|
+
@click.prevent="clickItem(filter)" class="dropdown-item cursor-pointer"
|
|
52
|
+
:class="filter?.active ? 'bg-info text-dark selected' : ''">
|
|
53
|
+
{{ filter.text }}
|
|
54
|
+
</a>
|
|
55
|
+
</template>
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
<div v-if="use_column_manager" class="dropdown d-inline-block ms-2">
|
|
59
|
+
<button class="btn dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"
|
|
60
|
+
title="Gerenciar Colunas visíveis">
|
|
61
|
+
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-columns" width="24"
|
|
62
|
+
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
|
|
63
|
+
stroke-linecap="round" stroke-linejoin="round">
|
|
64
|
+
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
|
65
|
+
<path d="M4 6l5.5 0" />
|
|
66
|
+
<path d="M4 10l5.5 0" />
|
|
67
|
+
<path d="M4 14l5.5 0" />
|
|
68
|
+
<path d="M4 18l5.5 0" />
|
|
69
|
+
<path d="M14.5 6l5.5 0" />
|
|
70
|
+
<path d="M14.5 10l5.5 0" />
|
|
71
|
+
<path d="M14.5 14l5.5 0" />
|
|
72
|
+
<path d="M14.5 18l5.5 0" />
|
|
73
|
+
</svg>
|
|
74
|
+
</button>
|
|
75
|
+
<div class="dropdown-menu dropdown-menu-end p-3 shadow-sm" style="min-width: 220px; z-index: 1050;">
|
|
76
|
+
<h6 class="dropdown-header text-uppercase fw-bold mb-2">Exibir Colunas</h6>
|
|
77
|
+
<div class="d-flex flex-column gap-2">
|
|
78
|
+
<label v-for="coluna in columns_list" :key="coluna.id" class="form-check cursor-pointer m-0">
|
|
79
|
+
<input class="form-check-input" type="checkbox" :checked="coluna.visible"
|
|
80
|
+
:disabled="coluna.locked" @change="toggleColumnVisibility(coluna.id)">
|
|
81
|
+
<span class="form-check-label user-select-none">{{ coluna.header }}</span>
|
|
82
|
+
</label>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</slot>
|
|
87
|
+
|
|
88
|
+
<slot name="extra-actions">
|
|
89
|
+
|
|
90
|
+
</slot>
|
|
55
91
|
</div>
|
|
56
92
|
</template>
|
|
57
93
|
<script setup lang="ts">
|
|
@@ -64,6 +100,9 @@ interface SearchProps {
|
|
|
64
100
|
placeholder_search?: string;
|
|
65
101
|
deactivate_search_on_clear?: boolean;
|
|
66
102
|
deactivate_search_empty?: boolean;
|
|
103
|
+
columns_list?: any[];
|
|
104
|
+
use_column_manager?: boolean;
|
|
105
|
+
toggleColumnVisibility?: (columnId: string) => void;
|
|
67
106
|
}
|
|
68
107
|
const props = withDefaults(defineProps<SearchProps>(), {
|
|
69
108
|
filter: "",
|
|
@@ -100,6 +139,9 @@ const props = withDefaults(defineProps<SearchProps>(), {
|
|
|
100
139
|
click: null,
|
|
101
140
|
deactivate_search_on_clear: false,
|
|
102
141
|
deactivate_search_empty: false,
|
|
142
|
+
columns_list: () => [],
|
|
143
|
+
use_column_manager: false,
|
|
144
|
+
toggleColumnVisibility: () => { }
|
|
103
145
|
});
|
|
104
146
|
|
|
105
147
|
const emit = defineEmits(['update:search', 'update:filter', "search", "clickedClearSearch"]);
|
|
@@ -148,7 +190,7 @@ function tradeFilter(newFilter: string): void {
|
|
|
148
190
|
|
|
149
191
|
function cleanSearch(): void {
|
|
150
192
|
modelSearch.value = ""
|
|
151
|
-
if (!props.deactivate_search_on_clear){
|
|
193
|
+
if (!props.deactivate_search_on_clear) {
|
|
152
194
|
emit('search'); // emite o evento de busca para atualizar a lista
|
|
153
195
|
}
|
|
154
196
|
emit('clickedClearSearch');
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
<script setup lang="ts">
|
|
6
6
|
import { inject, onMounted, useSlots } from 'vue';
|
|
7
|
+
import type { Component } from 'vue';
|
|
7
8
|
import { dataTableApiKey } from '../keys';
|
|
8
9
|
const column_internal_id = crypto.randomUUID();
|
|
9
10
|
defineSlots<{
|
|
10
11
|
// props para o slot body
|
|
11
12
|
body?: (props: { item: any }) => any,
|
|
12
|
-
col_header?: (props: { col: any, locked: boolean }) => any,
|
|
13
|
+
col_header?: (props: { col: any, locked: boolean, OrderingComponent: Component }) => any,
|
|
13
14
|
col_header_midle?: (props: { col: any, locked: boolean }) => any,
|
|
14
15
|
}>();
|
|
15
16
|
interface VColumnProps {
|
|
@@ -19,23 +19,34 @@
|
|
|
19
19
|
<slot name="fieldMiddle">
|
|
20
20
|
|
|
21
21
|
</slot>
|
|
22
|
+
|
|
22
23
|
<Teleport :to="options.search_teleport || 'body'" :disabled="!options.search_teleport">
|
|
23
|
-
<
|
|
24
|
-
:list_filter="options.list_filter" :item_use="item_use"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
<Search v-if="!options.disable_search" v-model:search="pagination.search" v-model:filter="pagination.filter"
|
|
25
|
+
:list_filter="options.list_filter" :item_use="item_use" @search="reSearch"
|
|
26
|
+
:deactivate_search_on_clear="options.deactivate_search_on_clear"
|
|
27
|
+
:placeholder_search="options.placeholder_search"
|
|
28
|
+
:deactivate_search_empty="options.deactivate_search_empty"
|
|
29
|
+
:use_column_manager="options.use_column_manager" :toggleColumnVisibility="toggleColumnVisibility"
|
|
30
|
+
:columns_list="columns_list" @clicked-clear-search="$emit('clickedClearSearch')">
|
|
31
|
+
|
|
32
|
+
<template #search-field>
|
|
33
|
+
<slot name="search-field" :search="pagination.search" :filter="pagination.filter" :reSearch="reSearch">
|
|
34
|
+
</slot>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<template #extra-actions>
|
|
38
|
+
<slot name="extra-actions">
|
|
39
|
+
</slot>
|
|
40
|
+
</template>
|
|
41
|
+
</Search>
|
|
32
42
|
</Teleport>
|
|
33
43
|
</div>
|
|
34
44
|
<slot name="item-selected-info" :selected_items="selected_items" :clearSelection="() => selected_items = []">
|
|
35
45
|
<div v-if="(options.use_checkbox && selected_items.length > 0) && !options.deactivate_selected_info"
|
|
36
46
|
class="alert alert-cyan d-flex justify-content-center align-items-center py-2" role="alert">
|
|
37
47
|
<h4 class="alert-title m-0"> <strong>oi Itens Selecionados:</strong> <span
|
|
38
|
-
class="badge bg-azure text-azure-fg">{{
|
|
48
|
+
class="badge bg-azure text-azure-fg">{{
|
|
49
|
+
selected_items.length }}</span></h4>
|
|
39
50
|
<a class=" cursor-pointer " @click="selected_items = []">
|
|
40
51
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
|
41
52
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
|
@@ -72,9 +83,8 @@
|
|
|
72
83
|
<table class="table table-vcenter table-selectable" :class="options.class_table">
|
|
73
84
|
<thead>
|
|
74
85
|
|
|
75
|
-
<draggable v-model="draggableColumns" tag="tr" item-key="id" :animation="400"
|
|
76
|
-
|
|
77
|
-
@end="() => onDragEnd()">
|
|
86
|
+
<draggable v-model="draggableColumns" tag="tr" item-key="id" :animation="400" ghost-class="ghost-item"
|
|
87
|
+
drag-class="dragging-item" @start="isDraggingColumns = true" @end="() => onDragEnd()">
|
|
78
88
|
|
|
79
89
|
<template #header>
|
|
80
90
|
<th v-if="options.use_expandable_items"></th>
|
|
@@ -256,6 +266,7 @@ import { useCheckBox } from '../composables/useCheckBox.ts';
|
|
|
256
266
|
import VDataTableLoading from './VDataTableLoading.vue';
|
|
257
267
|
import VThDataTable from './VThDataTable.vue';
|
|
258
268
|
|
|
269
|
+
|
|
259
270
|
const globalConfig = inject(DATA_TABLE_CONFIG, {});
|
|
260
271
|
const {
|
|
261
272
|
isHovering,
|
|
@@ -295,6 +306,8 @@ const props = withDefaults(defineProps<VDataTableProps>(), {
|
|
|
295
306
|
pagination_teleport: null,
|
|
296
307
|
search_teleport: null,
|
|
297
308
|
show_header_when_empty: false,
|
|
309
|
+
storage_id: '',
|
|
310
|
+
use_column_manager: false,
|
|
298
311
|
});
|
|
299
312
|
const options = computed(() => {
|
|
300
313
|
return {
|
|
@@ -334,6 +347,8 @@ const options = computed(() => {
|
|
|
334
347
|
retry_attempts: props.retry_attempts ?? globalConfig.retry_attempts ?? 3,
|
|
335
348
|
retry_delay: props.retry_delay ?? globalConfig.retry_delay ?? 2000,
|
|
336
349
|
show_header_when_empty: props.show_header_when_empty ?? globalConfig.show_header_when_empty ?? false,
|
|
350
|
+
storage_id: props.storage_id ?? globalConfig.storage_id ?? '',
|
|
351
|
+
use_column_manager: props.use_column_manager ?? globalConfig.use_column_manager ?? false,
|
|
337
352
|
};
|
|
338
353
|
});
|
|
339
354
|
const emit = defineEmits(['tradePage', 'beforeFetch', 'afterFetch', 'clickedClearSearch']);
|
|
@@ -388,6 +403,92 @@ const {
|
|
|
388
403
|
atLeastOneSelected, toggleSelectAll, toggleItemSelection
|
|
389
404
|
} = useCheckBox(options.value, items);
|
|
390
405
|
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
// Variável computada que forma uma string exclusiva para garantir que este cache não atropele o cache de outra tabela.
|
|
409
|
+
const storageKey = computed(() => {
|
|
410
|
+
if (!options.value.storage_id) return null;
|
|
411
|
+
|
|
412
|
+
return `vdatatable_${options.value.storage_id}_${options.value.endpoint}`;
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
/*
|
|
416
|
+
Recebe: Nada.
|
|
417
|
+
Devolve: Nada.
|
|
418
|
+
Por que é usada: Inspeciona cada coluna para gerar um ID confiável de cache. Se for incapaz de gerar IDs únicos sem conflitos, a aplicação é encerrada propositalmente.
|
|
419
|
+
*/
|
|
420
|
+
function validateAndAssignKeys(): void {
|
|
421
|
+
for (const col of columns.value) {
|
|
422
|
+
let key = '';
|
|
423
|
+
const fieldCount = columns.value.filter(c => c.field === col.field).length;
|
|
424
|
+
|
|
425
|
+
if (col.field && fieldCount === 1) {
|
|
426
|
+
key = col.field;
|
|
427
|
+
} else {
|
|
428
|
+
const headerCount = columns.value.filter(c => c.header === col.header).length;
|
|
429
|
+
if (col.header && headerCount === 1) {
|
|
430
|
+
key = col.header;
|
|
431
|
+
} else {
|
|
432
|
+
throw new Error(`[VDataTable] Falha de integridade: Impossível designar um ID único de armazenamento. O 'field' e 'header' estão duplicados ou ausentes. Header ofensor: ${col.header}`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
col.storage_key = key;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/*
|
|
440
|
+
Recebe: Nada.
|
|
441
|
+
Devolve: Nada.
|
|
442
|
+
Por que é usada: Converte o estado de visibilidade e a ordem das colunas para JSON e grava no navegador do usuário.
|
|
443
|
+
*/
|
|
444
|
+
function saveColumnsState(): void {
|
|
445
|
+
if (!storageKey.value) return;
|
|
446
|
+
const state = columns.value.map(col => ({
|
|
447
|
+
storage_key: col.storage_key,
|
|
448
|
+
visible: col.visible
|
|
449
|
+
}));
|
|
450
|
+
localStorage.setItem(storageKey.value, JSON.stringify(state));
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/*
|
|
454
|
+
Recebe: Nada.
|
|
455
|
+
Devolve: Nada.
|
|
456
|
+
Por que é usada: Tenta recuperar o estado anterior da tabela. Caso detecte mudanças na estrutura das colunas, ele expurga o cache velho e impõe a nova realidade.
|
|
457
|
+
*/
|
|
458
|
+
function loadColumnsState(): void {
|
|
459
|
+
if (!storageKey.value) return;
|
|
460
|
+
const saved = localStorage.getItem(storageKey.value);
|
|
461
|
+
if (!saved) return;
|
|
462
|
+
|
|
463
|
+
try {
|
|
464
|
+
const parsed = JSON.parse(saved);
|
|
465
|
+
const currentKeys = columns.value.map(c => c.storage_key).sort();
|
|
466
|
+
const savedKeys = parsed.map((p: any) => p.storage_key).sort();
|
|
467
|
+
|
|
468
|
+
if (JSON.stringify(currentKeys) !== JSON.stringify(savedKeys)) {
|
|
469
|
+
localStorage.removeItem(storageKey.value);
|
|
470
|
+
saveColumnsState();
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const newColumnsOrder = [];
|
|
475
|
+
for (const savedCol of parsed) {
|
|
476
|
+
const found = columns.value.find(c => c.storage_key === savedCol.storage_key);
|
|
477
|
+
if (found) {
|
|
478
|
+
found.visible = savedCol.visible;
|
|
479
|
+
newColumnsOrder.push(found);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Atualiza o array in-place para não destruir a instância que o vuedraggable vigia
|
|
484
|
+
columns.value.splice(0, columns.value.length, ...newColumnsOrder);
|
|
485
|
+
|
|
486
|
+
} catch (e) {
|
|
487
|
+
localStorage.removeItem(storageKey.value);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
|
|
391
492
|
// =======================================================
|
|
392
493
|
// 4. PROPRIEDADES COMPUTADAS
|
|
393
494
|
// =======================================================
|
|
@@ -404,7 +505,9 @@ const draggableColumns = computed({
|
|
|
404
505
|
set(newUnlockedOrder) {
|
|
405
506
|
const locked = columns.value.filter(c => c.locked);
|
|
406
507
|
const hidden = columns.value.filter(c => !c.locked && c.visible === false);
|
|
407
|
-
|
|
508
|
+
// Usa splice para não quebrar a referência de reatividade do array original!
|
|
509
|
+
columns.value.splice(0, columns.value.length, ...newUnlockedOrder, ...hidden, ...locked);
|
|
510
|
+
saveColumnsState();
|
|
408
511
|
}
|
|
409
512
|
});
|
|
410
513
|
// colunas RENDERIZADAS (ordem final)
|
|
@@ -435,6 +538,7 @@ function toggleColumnVisibility(id: string): void {
|
|
|
435
538
|
const coluna = columns.value.find(c => c.id === id);
|
|
436
539
|
if (coluna) {
|
|
437
540
|
coluna.visible = !coluna.visible;
|
|
541
|
+
saveColumnsState();
|
|
438
542
|
}
|
|
439
543
|
}
|
|
440
544
|
|
|
@@ -470,7 +574,6 @@ watch(response, (newResponse: any) => {
|
|
|
470
574
|
}, { immediate: true });
|
|
471
575
|
|
|
472
576
|
|
|
473
|
-
|
|
474
577
|
// =======================================================
|
|
475
578
|
// 6. MÉTODOS
|
|
476
579
|
// =======================================================
|
|
@@ -635,14 +738,40 @@ onMounted(() => {
|
|
|
635
738
|
reSearch();
|
|
636
739
|
});
|
|
637
740
|
}
|
|
741
|
+
nextTick(() => {
|
|
742
|
+
if (options.value.storage_id) {
|
|
743
|
+
validateAndAssignKeys();
|
|
744
|
+
loadColumnsState();
|
|
745
|
+
}
|
|
746
|
+
});
|
|
638
747
|
});
|
|
639
748
|
|
|
640
749
|
watch(
|
|
641
|
-
() => options.value.add_params,
|
|
642
750
|
() => {
|
|
643
|
-
|
|
751
|
+
const params = typeof options.value.add_params === 'function'
|
|
752
|
+
? options.value.add_params()
|
|
753
|
+
: options.value.add_params;
|
|
754
|
+
return JSON.stringify(params);
|
|
644
755
|
},
|
|
645
|
-
|
|
756
|
+
(newVal, oldVal) => {
|
|
757
|
+
if (newVal !== oldVal && oldVal !== undefined) {
|
|
758
|
+
reSearch();
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
);
|
|
762
|
+
/*
|
|
763
|
+
========
|
|
764
|
+
Observa mudanças no endpoint.
|
|
765
|
+
Caso a rota da API mude dinamicamente, ele reseta a tabela para a página inicial com segurança.
|
|
766
|
+
========
|
|
767
|
+
*/
|
|
768
|
+
watch(
|
|
769
|
+
() => options.value.endpoint,
|
|
770
|
+
(newVal, oldVal) => {
|
|
771
|
+
if (newVal !== oldVal && oldVal !== undefined) {
|
|
772
|
+
pagination.value.current_page = options.value.page_starts_at;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
646
775
|
);
|
|
647
776
|
</script>
|
|
648
777
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span v-if="use_ordering" @click="emit('toggle')" class="cursor-pointer">
|
|
3
|
+
<svg v-if="!props.orderings_state || props.orderings_state === 'none'" xmlns="http://www.w3.org/2000/svg"
|
|
4
|
+
width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
|
5
|
+
stroke-linecap="round" stroke-linejoin="round">
|
|
6
|
+
<path d="m3 8 4-4 4 4"></path>
|
|
7
|
+
<path d="m11 16-4 4-4-4"></path>
|
|
8
|
+
<path d="M7 4v16"></path>
|
|
9
|
+
<path d="M15 8h6"></path>
|
|
10
|
+
<path d="M15 16h6"></path>
|
|
11
|
+
<path d="M13 12h8"></path>
|
|
12
|
+
</svg>
|
|
13
|
+
|
|
14
|
+
<svg v-else-if="props.orderings_state === 'decreasing'" xmlns="http://www.w3.org/2000/svg" width="16"
|
|
15
|
+
height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
|
16
|
+
stroke-linejoin="round">
|
|
17
|
+
<path d="m3 16 4 4 4-4"></path>
|
|
18
|
+
<path d="M7 20V4"></path>
|
|
19
|
+
<path d="M11 4h10"></path>
|
|
20
|
+
<path d="M11 8h7"></path>
|
|
21
|
+
<path d="M11 12h4"></path>
|
|
22
|
+
</svg>
|
|
23
|
+
|
|
24
|
+
<svg v-else-if="props.orderings_state === 'increasing'" xmlns="http://www.w3.org/2000/svg" width="16"
|
|
25
|
+
height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
|
26
|
+
stroke-linejoin="round">
|
|
27
|
+
<path d="m3 8 4-4 4 4"></path>
|
|
28
|
+
<path d="M7 4v16"></path>
|
|
29
|
+
<path d="M11 12h4"></path>
|
|
30
|
+
<path d="M11 16h7"></path>
|
|
31
|
+
<path d="M11 20h10"></path>
|
|
32
|
+
</svg>
|
|
33
|
+
</span>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
/*
|
|
38
|
+
========
|
|
39
|
+
Componente interno de uso exclusivo do VDataTable para renderizar o ícone de ordenação.
|
|
40
|
+
========
|
|
41
|
+
*/
|
|
42
|
+
const props = defineProps<{
|
|
43
|
+
orderings_state?: 'none' | 'increasing' | 'decreasing';
|
|
44
|
+
use_ordering?: boolean;
|
|
45
|
+
}>();
|
|
46
|
+
|
|
47
|
+
const emit = defineEmits<{
|
|
48
|
+
toggle: [void];
|
|
49
|
+
}>();
|
|
50
|
+
</script>
|
|
@@ -1,56 +1,22 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<th :class="class_all">
|
|
3
3
|
<div :class="{ 'header-ordering': use_ordering }">
|
|
4
|
-
|
|
5
|
-
<component
|
|
6
|
-
v-if="hasCustomHeader"
|
|
7
|
-
:is="col.colHeaderSlot"
|
|
8
|
-
v-bind="{ col: props.col, locked: props.locked }"
|
|
9
|
-
></component>
|
|
10
|
-
|
|
11
|
-
<template v-else>
|
|
12
|
-
<span>
|
|
13
|
-
{{ props.header }}
|
|
14
|
-
</span>
|
|
15
4
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
<component v-if="hasCustomHeader" :is="col.colHeaderSlot"
|
|
6
|
+
v-bind="{ col: props.col, locked: props.locked, OrderingComponent }"></component>
|
|
7
|
+
|
|
8
|
+
<template v-else>
|
|
9
|
+
<div class="d-flex justify-content-between align-items-center">
|
|
10
|
+
<span>
|
|
11
|
+
{{ props.header }}
|
|
12
|
+
</span>
|
|
21
13
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
|
|
25
|
-
stroke-linecap="round" stroke-linejoin="round">
|
|
26
|
-
<path d="m3 8 4-4 4 4"></path>
|
|
27
|
-
<path d="m11 16-4 4-4-4"></path>
|
|
28
|
-
<path d="M7 4v16"></path>
|
|
29
|
-
<path d="M15 8h6"></path>
|
|
30
|
-
<path d="M15 16h6"></path>
|
|
31
|
-
<path d="M13 12h8"></path>
|
|
32
|
-
</svg>
|
|
14
|
+
<component v-if="col.colHeaderMidleSlot" :is="col.colHeaderMidleSlot"
|
|
15
|
+
v-bind="{ col: props.col, locked: props.locked }"></component>
|
|
33
16
|
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
stroke-linejoin="round">
|
|
37
|
-
<path d="m3 16 4 4 4-4"></path>
|
|
38
|
-
<path d="M7 20V4"></path>
|
|
39
|
-
<path d="M11 4h10"></path>
|
|
40
|
-
<path d="M11 8h7"></path>
|
|
41
|
-
<path d="M11 12h4"></path>
|
|
42
|
-
</svg>
|
|
17
|
+
<component :is="OrderingComponent" />
|
|
18
|
+
</div>
|
|
43
19
|
|
|
44
|
-
<svg v-else-if="props.orderings_state === 'increasing'" xmlns="http://www.w3.org/2000/svg" width="16"
|
|
45
|
-
height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
|
|
46
|
-
stroke-linejoin="round">
|
|
47
|
-
<path d="m3 8 4-4 4 4"></path>
|
|
48
|
-
<path d="M7 4v16"></path>
|
|
49
|
-
<path d="M11 12h4"></path>
|
|
50
|
-
<path d="M11 16h7"></path>
|
|
51
|
-
<path d="M11 20h10"></path>
|
|
52
|
-
</svg>
|
|
53
|
-
</span>
|
|
54
20
|
</template>
|
|
55
21
|
|
|
56
22
|
</div>
|
|
@@ -58,8 +24,8 @@
|
|
|
58
24
|
</template>
|
|
59
25
|
|
|
60
26
|
<script setup lang="ts">
|
|
61
|
-
import { computed, Comment, Fragment, Text } from 'vue';
|
|
62
|
-
|
|
27
|
+
import { computed, Comment, Fragment, Text, h } from 'vue';
|
|
28
|
+
import VOrderingIcon from './VOrderingIcon.vue';
|
|
63
29
|
const props = defineProps<{
|
|
64
30
|
header: string;
|
|
65
31
|
class_column: string;
|
|
@@ -68,7 +34,11 @@ const props = defineProps<{
|
|
|
68
34
|
orderings_state: 'none' | 'increasing' | 'decreasing';
|
|
69
35
|
col: any;
|
|
70
36
|
}>();
|
|
71
|
-
|
|
37
|
+
const OrderingComponent = () => h(VOrderingIcon, {
|
|
38
|
+
orderings_state: props.orderings_state,
|
|
39
|
+
use_ordering: props.use_ordering,
|
|
40
|
+
onToggle: () => emit('toggleOrderingState')
|
|
41
|
+
});
|
|
72
42
|
const class_all = computed(() => {
|
|
73
43
|
return {
|
|
74
44
|
'header-draggable': !props.locked,
|
|
@@ -15,10 +15,9 @@ export function useDataTableFetch<T>(
|
|
|
15
15
|
const items = ref<T[]>([]) as Ref<T[]>;
|
|
16
16
|
|
|
17
17
|
const urlReativa = computed(() => {
|
|
18
|
-
pagination.value.current_page = props.page_starts_at;
|
|
19
18
|
return props.endpoint;
|
|
20
19
|
});
|
|
21
|
-
|
|
20
|
+
|
|
22
21
|
const default_params = computed<Record<string, any>>(() => ({
|
|
23
22
|
[props.page_param_name]: pagination.value.current_page + 1,
|
|
24
23
|
[props.page_size_param_name]: pagination.value.limit_per_page,
|
package/src/DatatableVue/keys.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface ColumnConfiguration {
|
|
|
26
26
|
// não é prop, é uma propriedade interna do VDataTable para controlar a visibilidade da coluna
|
|
27
27
|
visible?: boolean;
|
|
28
28
|
id: string; // ID único da coluna, gerado internamente pelo VDataTable
|
|
29
|
+
// Chave gerada dinamicamente para salvar e recuperar o estado da coluna no localstorage
|
|
30
|
+
storage_key?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
// A API que o VDataTable "fornece" para os filhos
|
|
@@ -78,6 +78,9 @@ export interface VDataTableProps {
|
|
|
78
78
|
pagination_teleport?: string | HTMLElement | null;
|
|
79
79
|
search_teleport?: string | HTMLElement | null;
|
|
80
80
|
show_header_when_empty?: boolean;
|
|
81
|
+
// Propriedade para ativar a persistência de configuração da tabela no localstorage
|
|
82
|
+
storage_id?: string;
|
|
83
|
+
use_column_manager?: boolean;
|
|
81
84
|
}
|
|
82
85
|
export type DataTablePropsWithDefaults = VDataTableProps & {
|
|
83
86
|
// Strings
|
|
@@ -129,6 +132,8 @@ export type DataTablePropsWithDefaults = VDataTableProps & {
|
|
|
129
132
|
add_params: Record<string, any> | (() => Record<string, any>);
|
|
130
133
|
list_filter: any[];
|
|
131
134
|
custom_loading: any | null;
|
|
135
|
+
storage_id: string;
|
|
136
|
+
use_column_manager: boolean;
|
|
132
137
|
};
|
|
133
138
|
export interface ExposedFunctions<T extends Record<string, any>> {
|
|
134
139
|
execute: () => void;
|