v-sistec-features 1.24.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "v-sistec-features",
3
3
  "private": false,
4
- "version": "1.24.0",
4
+ "version": "1.26.0",
5
5
  "author": "Márlon Bento Azevedo (https://github.com/marlon-bento)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -1,57 +1,93 @@
1
1
  <template>
2
2
  <div class="dropdown d-flex">
3
- <a v-if="item_use.includes(2)" href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown"
4
- title="Pesquisas Prédefinidas">
5
- <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-filter" width="24" height="24"
6
- viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
7
- stroke-linejoin="round">
8
- <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
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 d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"></path>
32
- <path d="M21 21l-6 -6"></path>
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
- </span>
35
- </div>
36
- <div v-if="item_use.includes(2)" class="dropdown-menu">
37
- <template v-for="(filter, index) in props.list_filter" :key="index">
38
- <router-link v-if="('type' in filter ? filter.type === 1 : false) && ('visible' in filter ? filter.visible : true)" :to="filter?.to"
39
- class="dropdown-item cursor-pointer">
40
- {{ filter.text }}
41
- </router-link>
42
- <a v-else-if="('type' in filter ? filter.type === 2 : true) && ('visible' in filter ? filter.visible : true)"
43
- @click.prevent="tradeFilter(String(filter.value))" class="dropdown-item cursor-pointer"
44
- :class="modelFilter === filter?.value ? 'bg-info text-dark selected' : ''">
45
- {{ filter.text }}
46
- </a>
47
- <a v-else-if="('type' in filter ? filter.type === 3 : true) && ('visible' in filter ? filter.visible : true)" @click.prevent="clickItem(filter)"
48
- class="dropdown-item cursor-pointer"
49
- :class="filter?.active ? 'bg-info text-dark selected' : ''"
50
- >
51
- {{ filter.text }}
52
- </a>
53
- </template>
54
- </div>
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 {
@@ -31,6 +32,7 @@ interface VColumnProps {
31
32
  decreasing_value?: string;
32
33
  increasing_value?: string;
33
34
  class_rules?: Record<string, (item: any) => boolean>;
35
+ start_hidden?: boolean;
34
36
  }
35
37
  const props = withDefaults(defineProps<VColumnProps>(), {
36
38
  field: null,
@@ -59,6 +61,7 @@ const props = withDefaults(defineProps<VColumnProps>(), {
59
61
  locked: false,
60
62
 
61
63
  use_ordering: false,
64
+ start_hidden: false,
62
65
  param_ordering: '',
63
66
  decreasing_value: '',
64
67
  increasing_value: '',
@@ -99,6 +102,7 @@ onMounted(() => {
99
102
  }
100
103
 
101
104
  parentApi.addColumn({
105
+ id: column_internal_id,
102
106
  field: props.field,
103
107
  header: props.header,
104
108
  type: props.type,
@@ -122,8 +126,11 @@ onMounted(() => {
122
126
  ...(props.type === 'text' && { limite_text: Number(props.limite_text) }),
123
127
  ...(props.type === 'img' && { deactivate_img_preview: props.deactivate_img_preview }),
124
128
  ...(props.type === 'date' && { format: props.format }),
129
+
130
+ start_hidden: props.start_hidden,// se a coluna é opcional por padrão ela não é visível, mas o usuário pode escolher mostrar ela
131
+ visible:! props.start_hidden // Se start_hidden for true, ela não estará visível inicialmente
125
132
 
126
133
  });
127
-
134
+
128
135
  });
129
136
  </script>
@@ -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
- <slot name="search-field" :search="pagination.search" :filter="pagination.filter" :reSearch="reSearch"
24
- :list_filter="options.list_filter" :item_use="item_use">
25
- <Search v-if="!options.disable_search" v-model:search="pagination.search"
26
- v-model:filter="pagination.filter" :list_filter="options.list_filter" :item_use="item_use"
27
- @search="reSearch" :deactivate_search_on_clear="options.deactivate_search_on_clear"
28
- :placeholder_search="options.placeholder_search"
29
- :deactivate_search_empty="options.deactivate_search_empty"
30
- @clicked-clear-search="$emit('clickedClearSearch')" />
31
- </slot>
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">{{ selected_items.length }}</span></h4>
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="header" :animation="400"
76
- ghost-class="ghost-item" drag-class="dragging-item" @start="isDraggingColumns = true"
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>
@@ -86,8 +96,8 @@
86
96
 
87
97
  <template #item="{ element: col }">
88
98
  <v-th-data-table :header="col.header" :class_column="col.class_column"
89
- :use_ordering="col.use_ordering" :orderings_state="orderings_state[col.header] || 'none'"
90
- @toggleOrderingState="() => toggleOrderingState(col.header)" :locked="false" :col="col">
99
+ :use_ordering="col.use_ordering" :orderings_state="orderings_state[col.id] || 'none'"
100
+ @toggleOrderingState="() => toggleOrderingState(col.id)" :locked="false" :col="col">
91
101
 
92
102
  </v-th-data-table>
93
103
  </template>
@@ -96,8 +106,8 @@
96
106
 
97
107
  <template v-for="col in lockedColumns" :key="col.field || col.header">
98
108
  <v-th-data-table :header="col.header" :class_column="col.class_column"
99
- :use_ordering="col.use_ordering" :orderings_state="orderings_state[col.header] || 'none'"
100
- @toggleOrderingState="() => toggleOrderingState(col.header)" :col="col" locked>
109
+ :use_ordering="col.use_ordering" :orderings_state="orderings_state[col.id] || 'none'"
110
+ @toggleOrderingState="() => toggleOrderingState(col.id)" :col="col" locked>
101
111
 
102
112
  </v-th-data-table>
103
113
 
@@ -219,7 +229,7 @@
219
229
 
220
230
  </slot>
221
231
  </div>
222
- <div v-else class="text-center p-4 text-secondary">
232
+ <div v-else-if="!hasItems" class="text-center p-4 text-secondary">
223
233
  <p class="m-0">Nenhum item encontrado.</p>
224
234
  </div>
225
235
  </div>
@@ -255,6 +265,8 @@ import { useDataTableFetch } from '../composables/useDataTableFetch';
255
265
  import { useCheckBox } from '../composables/useCheckBox.ts';
256
266
  import VDataTableLoading from './VDataTableLoading.vue';
257
267
  import VThDataTable from './VThDataTable.vue';
268
+
269
+
258
270
  const globalConfig = inject(DATA_TABLE_CONFIG, {});
259
271
  const {
260
272
  isHovering,
@@ -294,6 +306,8 @@ const props = withDefaults(defineProps<VDataTableProps>(), {
294
306
  pagination_teleport: null,
295
307
  search_teleport: null,
296
308
  show_header_when_empty: false,
309
+ storage_id: '',
310
+ use_column_manager: false,
297
311
  });
298
312
  const options = computed(() => {
299
313
  return {
@@ -333,6 +347,8 @@ const options = computed(() => {
333
347
  retry_attempts: props.retry_attempts ?? globalConfig.retry_attempts ?? 3,
334
348
  retry_delay: props.retry_delay ?? globalConfig.retry_delay ?? 2000,
335
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,
336
352
  };
337
353
  });
338
354
  const emit = defineEmits(['tradePage', 'beforeFetch', 'afterFetch', 'clickedClearSearch']);
@@ -387,28 +403,144 @@ const {
387
403
  atLeastOneSelected, toggleSelectAll, toggleItemSelection
388
404
  } = useCheckBox(options.value, items);
389
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
+
390
492
  // =======================================================
391
493
  // 4. PROPRIEDADES COMPUTADAS
392
494
  // =======================================================
393
495
 
394
496
  // colunas TRAVADAS (apenas leitura)
395
497
  const lockedColumns = computed(() =>
396
- columns.value.filter(c => c.locked)
498
+ columns.value.filter(c => c.locked && c.visible !== false)
397
499
  );
398
500
  // 'v-model' para as colunas ARRASTÁVEIS (com get/set)
399
501
  const draggableColumns = computed({
400
502
  get() {
401
- return columns.value.filter(c => !c.locked);
503
+ return columns.value.filter(c => !c.locked && c.visible !== false);
402
504
  },
403
505
  set(newUnlockedOrder) {
404
- const locked = lockedColumns.value;
405
- columns.value = [...newUnlockedOrder, ...locked];
506
+ const locked = columns.value.filter(c => c.locked);
507
+ const hidden = columns.value.filter(c => !c.locked && c.visible === false);
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();
406
511
  }
407
512
  });
408
513
  // colunas RENDERIZADAS (ordem final)
409
514
  const renderedColumns = computed(() => {
410
515
  return [...draggableColumns.value, ...lockedColumns.value];
411
516
  });
517
+ /*
518
+ Variável que mapeia as colunas cadastradas.
519
+ Usada para entregar ao componente pai as informações de cabeçalho, campo, se a coluna é opcional e se está visível atualmente.
520
+ */
521
+ const columns_list = computed(() => {
522
+ return columns.value.map(col => ({
523
+ id: col.id,
524
+ header: col.header,
525
+ field: col.field,
526
+ start_hidden: !!col.start_hidden, // Converte para booleano, caso seja undefined
527
+ visible: col.visible !== false,
528
+ locked: col.locked
529
+ }));
530
+ });
531
+ /*
532
+ Função que inverte o estado de visibilidade de uma coluna específica.
533
+ Recebe: id (string), que é o identificador único da coluna.
534
+ Devolve: nada (void).
535
+ Por que é usada: Permite ao usuário exibir ou ocultar uma coluna dinamicamente (como as opcionais) diretamente pela interface externa da tabela.
536
+ */
537
+ function toggleColumnVisibility(id: string): void {
538
+ const coluna = columns.value.find(c => c.id === id);
539
+ if (coluna) {
540
+ coluna.visible = !coluna.visible;
541
+ saveColumnsState();
542
+ }
543
+ }
412
544
 
413
545
  const item_use = computed<number[]>(() => {
414
546
  let use = [1]
@@ -442,7 +574,6 @@ watch(response, (newResponse: any) => {
442
574
  }, { immediate: true });
443
575
 
444
576
 
445
-
446
577
  // =======================================================
447
578
  // 6. MÉTODOS
448
579
  // =======================================================
@@ -498,22 +629,22 @@ function limiteText(text: string | null, limite: number | null): string | null {
498
629
  return text;
499
630
  }
500
631
 
501
- function toggleOrderingState(header: string) {
632
+ function toggleOrderingState(id: string) {
502
633
 
503
634
  // desabilita todos que não são o header clicado
504
635
  for (const key in orderings_state.value) {
505
- if (key !== header) {
636
+ if (key !== id) {
506
637
  orderings_state.value[key] = 'none';
507
638
  }
508
639
  }
509
640
 
510
- const currentState = orderings_state.value[header] || 'none';
641
+ const currentState = orderings_state.value[id] || 'none';
511
642
  if (currentState === 'none') {
512
- orderings_state.value[header] = 'increasing';
643
+ orderings_state.value[id] = 'increasing';
513
644
  } else if (currentState === 'increasing') {
514
- orderings_state.value[header] = 'decreasing';
645
+ orderings_state.value[id] = 'decreasing';
515
646
  } else {
516
- orderings_state.value[header] = 'none';
647
+ orderings_state.value[id] = 'none';
517
648
  }
518
649
 
519
650
  reSearch();
@@ -596,7 +727,9 @@ defineExpose<ExposedFunctions<T>>({
596
727
  atLeastOneSelected,
597
728
  expand_item_toggle,
598
729
  close_all_expanded_items,
599
- selectAllCheckbox
730
+ selectAllCheckbox,
731
+ toggleColumnVisibility,
732
+ columns_list,
600
733
  });
601
734
 
602
735
  onMounted(() => {
@@ -605,14 +738,40 @@ onMounted(() => {
605
738
  reSearch();
606
739
  });
607
740
  }
741
+ nextTick(() => {
742
+ if (options.value.storage_id) {
743
+ validateAndAssignKeys();
744
+ loadColumnsState();
745
+ }
746
+ });
608
747
  });
609
748
 
610
749
  watch(
611
- () => options.value.add_params,
612
750
  () => {
613
- reSearch();
751
+ const params = typeof options.value.add_params === 'function'
752
+ ? options.value.add_params()
753
+ : options.value.add_params;
754
+ return JSON.stringify(params);
614
755
  },
615
- { deep: true }
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
+ }
616
775
  );
617
776
  </script>
618
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>