v-sistec-features 1.3.0 → 1.3.2

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.3.0",
4
+ "version": "1.3.2",
5
5
  "author": "Márlon Bento Azevedo (https://github.com/marlon-bento)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -37,7 +37,7 @@
37
37
  </template>
38
38
 
39
39
  <script setup lang="ts" generic="T extends Record<string, any>">
40
- import { readonly, ref, isRef, computed, watch, onMounted, nextTick, type Component, type Ref, type WatchSource } from 'vue';
40
+ import { readonly, ref, isRef, computed, watch, nextTick, type Component, type Ref, type WatchSource } from 'vue';
41
41
  import InfiniteLoading from "v3-infinite-loading";
42
42
  import PaginationDatatable from './PaginationDatatable.vue';
43
43
  // import Search from './SearchDatatable.vue';
@@ -101,7 +101,7 @@ interface VDataPageProps {
101
101
  next_page_response_name?: string;
102
102
  page_starts_at: number;
103
103
  element_id?: string;
104
- watch?: WatchSource[]
104
+ watch?: WatchSource[];
105
105
  }
106
106
 
107
107
  interface ExposedFunctions {
@@ -112,7 +112,10 @@ interface ExposedFunctions {
112
112
  set_search: (newSearch: string) => void;
113
113
  set_filter: (newFilter: string) => void;
114
114
  set_page: (newPage: number) => void;
115
+
116
+
115
117
  }
118
+ const emit = defineEmits(['tradePage', 'beforeFetch', 'afterFetch']);
116
119
 
117
120
  // =======================================================
118
121
  // 1. DEFINIÇÃO DE PROPS COM VALORES PADRÃO
@@ -218,13 +221,6 @@ const { data: response, pending: _pending, error, execute, attempt: _attempt } =
218
221
  // =======================================================
219
222
  // 4. PROPRIEDADES COMPUTADAS
220
223
  // =======================================================
221
- // const item_use = computed<number[]>(() => {
222
- // let use = [1]
223
- // if (props.list_filter.length > 0) {
224
- // use.push(2)
225
- // }
226
- // return use;
227
- // });
228
224
 
229
225
  const default_params = computed<Record<string, any>>(() => ({
230
226
  [props.page_param_name]: pagination.value.current_page + 1,
@@ -272,16 +268,24 @@ async function fetchDataWithDelay(): Promise<void> {
272
268
  delayTimer.value = setTimeout(() => {
273
269
  isDelaying.value = false;
274
270
  }, props.min_loading_delay);
271
+ if (props.type_fetch === 'infinite-scroll') {
272
+ return execute();
273
+ } else if (props.type_fetch === 'pagination') {
274
+ emit("beforeFetch")
275
+ await execute();
276
+ emit("afterFetch")
277
+ }
275
278
 
276
- return execute(); // Executa a busca de dados original do useApiFetch
277
279
  }
278
280
  async function initDataInfinite() {
279
281
  items.value = [];
280
282
  items_infinite.value = [];
281
283
 
282
284
  pagination.value.current_page = props.page_starts_at;
283
-
285
+ emit("beforeFetch")
284
286
  await fetchDataWithDelay();
287
+ emit("afterFetch")
288
+
285
289
 
286
290
  nextTick(() => {
287
291
  items_infinite.value.push(...items.value);
@@ -291,25 +295,6 @@ async function initDataInfinite() {
291
295
  });
292
296
  }
293
297
 
294
-
295
- // function reSearch(): void {
296
- // pagination.value.current_page = 0;
297
- // fetchDataWithDelay();
298
- // }
299
-
300
- // const changePageSize = (event: Event): void => {
301
- // const target = event.target as HTMLInputElement;
302
- // const newSize = parseInt(target.value, 10);
303
- // if (newSize > 0) {
304
- // pagination.value.limit_per_page = newSize;
305
- // pagination.value.limit_per_page = newSize; // Atualiza o limite de itens por página
306
- // pagination.value.current_page = 0;
307
- // fetchDataWithDelay();
308
- // }
309
- // };
310
-
311
-
312
-
313
298
  // =======================================================
314
299
  // 7. EXPOSE E CICLO DE VIDA
315
300
  // =======================================================
@@ -353,23 +338,6 @@ defineExpose<
353
338
  default_params
354
339
  });
355
340
 
356
- onMounted(() => {
357
- nextTick(() => {
358
-
359
- /*
360
- * executar dentro do nextTick para garantir que o pai já tem acesso ao
361
- * ref que foi exposto
362
- */
363
- if (first_fetch.value && props.type_fetch === 'infinite-scroll') {
364
- initDataInfinite();
365
- first_fetch.value = false;
366
- } else if (first_fetch.value && props.type_fetch === 'pagination') {
367
- fetchDataWithDelay();
368
- first_fetch.value = false;
369
- }
370
-
371
- })
372
- });
373
341
  const proxima_pagina = computed(() => {
374
342
  return response.value?.[props.next_page_response_name] || null
375
343
  })
@@ -488,6 +456,9 @@ if (props.watch && Array.isArray(props.watch)) {
488
456
  }
489
457
  });
490
458
  }
459
+ watch(() => pagination.value.current_page, () => {
460
+ emit("tradePage")
461
+ });
491
462
  if (watchSources.length > 0) {
492
463
  if (props.type_fetch === 'pagination') {
493
464
  watch(watchSources, () => {
@@ -495,14 +466,44 @@ if (watchSources.length > 0) {
495
466
  fetchDataWithDelay();
496
467
  }, { deep: true });
497
468
  } else if (props.type_fetch === 'infinite-scroll') {
498
- watch(watchSources, () =>{
469
+ watch(watchSources, () => {
499
470
  dadosInicializados.value = false;
500
471
  initDataInfinite();
501
- } , { deep: true });
472
+ }, { deep: true });
502
473
  }
503
474
 
504
475
  }
505
-
476
+ const on_mounted_called = ref<boolean>(false);
477
+ watch(
478
+ () => props.add_params,
479
+ () => {
480
+ if (!on_mounted_called.value) {
481
+ on_mounted_called.value = true;
482
+ nextTick(() => {
483
+ /*
484
+ * executar dentro do nextTick para garantir que o pai já tem acesso ao
485
+ * ref que foi exposto
486
+ */
487
+ if (first_fetch.value && props.type_fetch === 'infinite-scroll') {
488
+ initDataInfinite();
489
+ first_fetch.value = false;
490
+ } else if (first_fetch.value && props.type_fetch === 'pagination') {
491
+ fetchDataWithDelay();
492
+ first_fetch.value = false;
493
+ }
494
+ })
495
+ } else {
496
+ if (props.type_fetch === 'pagination') {
497
+ pagination.value.current_page = props.page_starts_at;
498
+ fetchDataWithDelay();
499
+ } else if (props.type_fetch === 'infinite-scroll') {
500
+ dadosInicializados.value = false;
501
+ initDataInfinite();
502
+ }
503
+ }
504
+ },
505
+ { deep: true }
506
+ )
506
507
  </script>
507
508
 
508
509
  <style lang="scss" scoped>
@@ -8,8 +8,9 @@
8
8
  <div class="text-secondary">
9
9
  {{ props.first_text_page_size }}
10
10
  <div class="mx-2 d-inline-block">
11
- <input class="form-control form-control-sm" @change="changePageSize" v-model.lazy="pagination.limit_per_page" min="1"
12
- size="3" aria-label="Número de registros por página" type="number" />
11
+ <input class="form-control form-control-sm" @change="changePageSize"
12
+ v-model.lazy="pagination.limit_per_page" min="1" size="3" aria-label="Número de registros por página"
13
+ type="number" />
13
14
  </div>
14
15
  {{ props.second_text_page_size }}
15
16
  </div>
@@ -154,24 +155,26 @@
154
155
  <td v-for="col in columns" :key="col.field || col.header" :class="col.class_row">
155
156
  <component v-if="col.bodySlot" :is="col.bodySlot" :item="item" :is-selected="isSelected(item)" />
156
157
  <span @click="col.click ? col.click(item) : null"
157
- :class="col.class_item + (col.click ? ' cursor-pointer' : '') " v-else-if="col.type === 'text'">
158
+ :class="col.class_item + (col.click ? ' cursor-pointer' : '')" v-else-if="col.type === 'text'">
158
159
  {{
159
160
  limiteText(getSubItem(col.field, item, col.transform_function), col.limite_text ?? null)
160
161
  }}</span>
161
162
 
162
163
  <span @click="col.click ? col.click(item) : null" v-else-if="col.type === 'date'"
163
- :class="col.class_item + (col.click ? ' cursor-pointer' : '') "
164
- >
164
+ :class="col.class_item + (col.click ? ' cursor-pointer' : '')">
165
165
  <span v-if="col.format === 'complete'">{{ new Date(getSubItem(col.field, item)).toLocaleString()
166
166
  }}</span>
167
167
  <span v-if="col.format === 'simple'"> {{ new Date(getSubItem(col.field,
168
168
  item)).toLocaleDateString()
169
169
  }} </span>
170
170
  </span>
171
- <div @click="col.click ? col.click(item) : null" :class="col.class_item + (col.click ? ' cursor-pointer' : '') " v-else-if="col.type === 'html'" v-html="getSubItem(col.field, item)">
171
+ <div @click="col.click ? col.click(item) : null"
172
+ :class="col.class_item + (col.click ? ' cursor-pointer' : '')" v-else-if="col.type === 'html'"
173
+ v-html="getSubItem(col.field, item)">
172
174
  </div>
173
175
 
174
- <div @click="col.click ? col.click(item) : null" :class="col.class_item + (col.click ? ' cursor-pointer' : '') " v-else-if="col.type === 'img'">
176
+ <div @click="col.click ? col.click(item) : null"
177
+ :class="col.class_item + (col.click ? ' cursor-pointer' : '')" v-else-if="col.type === 'img'">
175
178
 
176
179
  <div v-if="getSubItem(col.field, item)" v-bind="col.deactivate_img_preview ? {
177
180
  class: 'container-img'
@@ -219,7 +222,7 @@
219
222
  </template>
220
223
 
221
224
  <script setup lang="ts" generic="T extends Record<string, any>">
222
- import { readonly,ref, provide, computed, watch, onMounted, nextTick, type Component, type Ref, type ComputedRef } from 'vue';
225
+ import { readonly, ref, provide, computed, watch, nextTick, type Component, type Ref, type ComputedRef } from 'vue';
223
226
 
224
227
  import PaginationDatatable from './PaginationDatatable.vue';
225
228
  import Search from './SearchDatatable.vue';
@@ -441,7 +444,6 @@ const atLeastOneSelected = computed<boolean>(() => selected_items.value.length >
441
444
  watch([selectAllState, selectAllCheckbox], ([newState]) => {
442
445
  if (selectAllCheckbox.value) {
443
446
  if (newState === 'indeterminate') {
444
- console.log("entrei no indeterminate")
445
447
  // Se o estado for indeterminado:
446
448
  selectAllCheckbox.value.checked = false; // Ele não está "marcado"
447
449
  selectAllCheckbox.value.indeterminate = true; // Ele está com o "traço"
@@ -540,7 +542,7 @@ const changePageSize = (event: Event): void => {
540
542
  pagination.value.limit_per_page = newSize; // Atualiza o limite de itens por página
541
543
  pagination.value.current_page = 0;
542
544
  fetchDataWithDelay();
543
- }
545
+ }
544
546
  };
545
547
 
546
548
  function getSubItem(field: string | null, item: T, transform_function: ((value: any) => any) | null = null): any {
@@ -580,7 +582,7 @@ function set_limit_per_page(newLimit: number): void {
580
582
  pagination.value.limit_per_page = newLimit;
581
583
  pagination.value.current_page = 0;
582
584
  fetchDataWithDelay();
583
- }else {
585
+ } else {
584
586
  console.warn("O limite deve ser um número maior que zero.");
585
587
  }
586
588
  }
@@ -616,17 +618,23 @@ defineExpose<
616
618
  selected_items,
617
619
  atLeastOneSelected,
618
620
  });
621
+ const on_mounted_called = ref<boolean>(false);
622
+ watch(
623
+ () => props.add_params,
624
+ () => {
625
+ if (!on_mounted_called.value) {
626
+ on_mounted_called.value = true;
627
+ // esperar até existir os exposes
628
+ nextTick(() => {
629
+ reSearch();
630
+ });
631
+ } else {
632
+ reSearch();
633
+ }
634
+ },
635
+ { deep: true, immediate: true }
636
+ )
619
637
 
620
- onMounted(() => {
621
- nextTick(() => {
622
-
623
- /*
624
- * executar dentro do nextTick para garantir que o pai já tem acesso ao
625
- * ref que foi exposto
626
- */
627
- fetchDataWithDelay();
628
- })
629
- });
630
638
  </script>
631
639
 
632
640
  <style lang="scss" scoped>