Corrige tabela e paginacao

This commit is contained in:
LeoMortari
2025-09-24 11:46:55 -03:00
parent 31fb7addb5
commit 8e5939dcdf
3 changed files with 76 additions and 26 deletions

1
.gitignore vendored
View File

@@ -6,6 +6,7 @@ yarn-debug.log*
yarn-error.log* yarn-error.log*
pnpm-debug.log* pnpm-debug.log*
lerna-debug.log* lerna-debug.log*
pnpm-lock.yaml
node_modules node_modules
dist dist

View File

@@ -12,7 +12,7 @@
hide-pagination hide-pagination
> >
<template v-slot:loading> <template v-slot:loading>
<q-inner-loading color="primary" /> <q-inner-loading showing color="primary" />
</template> </template>
<template v-slot:no-data> <template v-slot:no-data>
@@ -25,8 +25,11 @@
<q-pagination <q-pagination
v-model="pagination.page" v-model="pagination.page"
color="primary" color="primary"
:max="pagination.totalPages"
size="md" size="md"
:max="pagination.totalPages"
:disable="loading"
input
@update:model-value="updatePagination"
/> />
</div> </div>
@@ -41,54 +44,52 @@
import has from "lodash/has"; import has from "lodash/has";
export default { export default {
name: "Table",
props: { props: {
columns: { columns: {
type: Array, type: Array,
required: true, required: true,
validator: (value) => value.some((item) => has(item, ["name", "label"])), validator: (value) =>
Array.isArray(value) &&
value.every((col) => has(col, "name") && has(col, "label")),
}, },
rows: { rows: {
type: Array, type: Array,
required: true, required: true,
validator: (value) => value.some((item) => has(item, ["name", "label"])), validator: (value) => Array.isArray(value),
}, },
rowName: { rowName: {
type: String, type: String,
required: false,
default: "name", default: "name",
}, },
rowKey: { rowKey: {
type: String, type: String,
required: false,
default: "id", default: "id",
}, },
title: { title: String,
type: String,
required: false,
},
loading: { loading: {
type: Boolean, type: Boolean,
required: false,
default: false, default: false,
}, },
pagination: { pagination: {
type: Object, type: Object,
required: false, required: false,
default: { default: {
sortBy: "desc", page: 1,
descending: false, direction: "desc",
currentPage: 1, perPage: 10,
total: 10,
totalPages: 1, totalPages: 1,
totalItems: 10, hasNext: false,
hasPrev: false,
}, },
}, },
}, },
setup(props) { emits: ["update:pagination"],
return { methods: {
columns: props.columns, updatePagination(page) {
rows: props.rows, this.$emit("update:pagination", { ...this.pagination, page });
rowKey: props.rowKey, },
};
}, },
}; };
</script> </script>

View File

@@ -18,7 +18,7 @@
<Button <Button
label="Buscar" label="Buscar"
:loading="loading" :loading="loading"
@click="handleSearch" @click="handleSearch(pagination)"
fullWidth fullWidth
/> />
</div> </div>
@@ -29,7 +29,9 @@
:columns="columns" :columns="columns"
:rows="rows" :rows="rows"
:pagination="pagination" :pagination="pagination"
:loading="loading"
row-key="id" row-key="id"
@update:pagination="updatePagination"
> >
<template #no-data> <template #no-data>
<div <div
@@ -58,8 +60,43 @@ const columns = [
align: "left", align: "left",
field: "id", field: "id",
}, },
{
name: "title",
label: "Título",
align: "center",
field: "title",
},
{
name: "clips_quantity",
label: "Clipes",
align: "left",
field: "clips_quantity",
},
{
name: "videoid",
label: "VideoID",
field: "videoid",
},
{
name: "situation",
label: "Situação",
field: "situation",
},
]; ];
/*
{
"id": 195,
"title": "VIDA EXTRATERRESTRE: FINALMENTE ENCONTRADA A EVIDÊNCIA + AGUARDADA...",
"url": "https://www.youtube.com/watch?v=2iU7oAmQROQ",
"situation": "CONCLUIDO",
"clips_quantity": 3,
"videoid": "2iU7oAmQROQ",
"filename": "VIDA_EXTRATERRESTRE_FINALMENTE_ENCONTRADA_A_EVIDENCIA_AGUARDADA_medium.mp4",
"datetime_download": "Invalid Date"
}
*/
export default { export default {
name: "UserList", name: "UserList",
components: { components: {
@@ -74,18 +111,26 @@ export default {
loading: false, loading: false,
pagination: { pagination: {
page: 1, page: 1,
totalPages: 1, direction: "desc",
total: 10,
perPage: 10, perPage: 10,
total: 10,
totalPages: 1,
hasNext: false,
hasPrev: false,
}, },
}; };
}, },
methods: { methods: {
async handleSearch() { async handleSearch(pagination) {
try { try {
this.loading = true; this.loading = true;
const { data } = await API.get("/videos"); const { data } = await API.get("/videos", {
params: {
perPage: pagination.perPage,
page: pagination.page,
},
});
this.rows = data.content; this.rows = data.content;
this.pagination = data.pagination; this.pagination = data.pagination;
@@ -98,6 +143,9 @@ export default {
this.loading = false; this.loading = false;
} }
}, },
updatePagination(pagination) {
this.handleSearch(pagination);
},
}, },
}; };
</script> </script>