v-sistec-features 1.3.1 → 1.3.3

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.1",
4
+ "version": "1.3.3",
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';
@@ -102,7 +102,6 @@ interface VDataPageProps {
102
102
  page_starts_at: number;
103
103
  element_id?: string;
104
104
  watch?: WatchSource[];
105
- scroll_on_trade_page?: boolean;
106
105
  }
107
106
 
108
107
  interface ExposedFunctions {
@@ -116,6 +115,7 @@ interface ExposedFunctions {
116
115
 
117
116
 
118
117
  }
118
+ const emit = defineEmits(['tradePage', 'beforeFetch', 'afterFetch']);
119
119
 
120
120
  // =======================================================
121
121
  // 1. DEFINIÇÃO DE PROPS COM VALORES PADRÃO
@@ -150,7 +150,6 @@ const props = withDefaults(defineProps<VDataPageProps>(), {
150
150
  type_fetch: 'pagination',
151
151
  page_starts_at: 0,
152
152
  element_id: '',
153
- scroll_on_trade_page: false,
154
153
  watch: () => []
155
154
  });
156
155
 
@@ -222,13 +221,6 @@ const { data: response, pending: _pending, error, execute, attempt: _attempt } =
222
221
  // =======================================================
223
222
  // 4. PROPRIEDADES COMPUTADAS
224
223
  // =======================================================
225
- // const item_use = computed<number[]>(() => {
226
- // let use = [1]
227
- // if (props.list_filter.length > 0) {
228
- // use.push(2)
229
- // }
230
- // return use;
231
- // });
232
224
 
233
225
  const default_params = computed<Record<string, any>>(() => ({
234
226
  [props.page_param_name]: pagination.value.current_page + 1,
@@ -276,16 +268,24 @@ async function fetchDataWithDelay(): Promise<void> {
276
268
  delayTimer.value = setTimeout(() => {
277
269
  isDelaying.value = false;
278
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
+ }
279
278
 
280
- return execute(); // Executa a busca de dados original do useApiFetch
281
279
  }
282
280
  async function initDataInfinite() {
283
281
  items.value = [];
284
282
  items_infinite.value = [];
285
283
 
286
284
  pagination.value.current_page = props.page_starts_at;
287
-
285
+ emit("beforeFetch")
288
286
  await fetchDataWithDelay();
287
+ emit("afterFetch")
288
+
289
289
 
290
290
  nextTick(() => {
291
291
  items_infinite.value.push(...items.value);
@@ -295,25 +295,6 @@ async function initDataInfinite() {
295
295
  });
296
296
  }
297
297
 
298
-
299
- // function reSearch(): void {
300
- // pagination.value.current_page = 0;
301
- // fetchDataWithDelay();
302
- // }
303
-
304
- // const changePageSize = (event: Event): void => {
305
- // const target = event.target as HTMLInputElement;
306
- // const newSize = parseInt(target.value, 10);
307
- // if (newSize > 0) {
308
- // pagination.value.limit_per_page = newSize;
309
- // pagination.value.limit_per_page = newSize; // Atualiza o limite de itens por página
310
- // pagination.value.current_page = 0;
311
- // fetchDataWithDelay();
312
- // }
313
- // };
314
-
315
-
316
-
317
298
  // =======================================================
318
299
  // 7. EXPOSE E CICLO DE VIDA
319
300
  // =======================================================
@@ -357,23 +338,6 @@ defineExpose<
357
338
  default_params
358
339
  });
359
340
 
360
- onMounted(() => {
361
- nextTick(() => {
362
-
363
- /*
364
- * executar dentro do nextTick para garantir que o pai já tem acesso ao
365
- * ref que foi exposto
366
- */
367
- if (first_fetch.value && props.type_fetch === 'infinite-scroll') {
368
- initDataInfinite();
369
- first_fetch.value = false;
370
- } else if (first_fetch.value && props.type_fetch === 'pagination') {
371
- fetchDataWithDelay();
372
- first_fetch.value = false;
373
- }
374
-
375
- })
376
- });
377
341
  const proxima_pagina = computed(() => {
378
342
  return response.value?.[props.next_page_response_name] || null
379
343
  })
@@ -493,10 +457,7 @@ if (props.watch && Array.isArray(props.watch)) {
493
457
  });
494
458
  }
495
459
  watch(() => pagination.value.current_page, () => {
496
- //scrola para o topo da página ao mudar de página
497
- if (props.type_fetch === 'pagination' && props.scroll_on_trade_page) {
498
- window.scrollTo({ top: 0, behavior: 'auto' })
499
- }
460
+ emit("tradePage")
500
461
  });
501
462
  if (watchSources.length > 0) {
502
463
  if (props.type_fetch === 'pagination') {
@@ -505,14 +466,44 @@ if (watchSources.length > 0) {
505
466
  fetchDataWithDelay();
506
467
  }, { deep: true });
507
468
  } else if (props.type_fetch === 'infinite-scroll') {
508
- watch(watchSources, () =>{
469
+ watch(watchSources, () => {
509
470
  dadosInicializados.value = false;
510
471
  initDataInfinite();
511
- } , { deep: true });
472
+ }, { deep: true });
512
473
  }
513
474
 
514
475
  }
515
-
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, immediate: true }
506
+ )
516
507
  </script>
517
508
 
518
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>