refactor: 07 => enhance fetchData for mobile handling and improve data fetching logic
This commit is contained in:
parent
15081f899d
commit
d268764024
1 changed files with 27 additions and 20 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { QTableProps } from 'quasar';
|
import { QTableProps } from 'quasar';
|
||||||
import { dialog } from 'src/stores/utils';
|
import { dialog } from 'src/stores/utils';
|
||||||
import { onMounted, reactive, ref } from 'vue';
|
import { onMounted, reactive, ref, watch } from 'vue';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { Icon } from '@iconify/vue/dist/iconify.js';
|
import { Icon } from '@iconify/vue/dist/iconify.js';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
@ -21,7 +21,6 @@ import FloatingActionButton from 'src/components/FloatingActionButton.vue';
|
||||||
import CreateButton from 'src/components/AddButton.vue';
|
import CreateButton from 'src/components/AddButton.vue';
|
||||||
import NoData from 'src/components/NoData.vue';
|
import NoData from 'src/components/NoData.vue';
|
||||||
import AgenciesDialog from './AgenciesDialog.vue';
|
import AgenciesDialog from './AgenciesDialog.vue';
|
||||||
import { watch } from 'vue';
|
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
|
|
@ -192,7 +191,7 @@ async function submit(opt?: { selectedImage: string }) {
|
||||||
pageState.isDrawerEdit = false;
|
pageState.isDrawerEdit = false;
|
||||||
currAgenciesData.value = ret;
|
currAgenciesData.value = ret;
|
||||||
formData.value.selectedImage = ret.selectedImage;
|
formData.value.selectedImage = ret.selectedImage;
|
||||||
await fetchData();
|
await fetchData($q.screen.xs);
|
||||||
|
|
||||||
if (refAgenciesDialog.value && opt?.selectedImage) {
|
if (refAgenciesDialog.value && opt?.selectedImage) {
|
||||||
refAgenciesDialog.value.clearImageState();
|
refAgenciesDialog.value.clearImageState();
|
||||||
|
|
@ -208,14 +207,12 @@ async function submit(opt?: { selectedImage: string }) {
|
||||||
onCreateImageList.value,
|
onCreateImageList.value,
|
||||||
);
|
);
|
||||||
|
|
||||||
await fetchData();
|
await fetchData($q.screen.xs);
|
||||||
pageState.addModal = false;
|
pageState.addModal = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function triggerChangeStatus(data?: Institution) {}
|
|
||||||
|
|
||||||
async function triggerDelete(id?: string) {
|
async function triggerDelete(id?: string) {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
dialog({
|
dialog({
|
||||||
|
|
@ -228,21 +225,26 @@ async function triggerDelete(id?: string) {
|
||||||
action: async () => {
|
action: async () => {
|
||||||
await institutionStore.deleteInstitution(id);
|
await institutionStore.deleteInstitution(id);
|
||||||
resetForm();
|
resetForm();
|
||||||
await fetchData();
|
await fetchData($q.screen.xs);
|
||||||
},
|
},
|
||||||
cancel: () => {},
|
cancel: () => {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchData() {
|
async function fetchData(mobileFetch?: boolean) {
|
||||||
const ret = await institutionStore.getInstitutionList({
|
const ret = await institutionStore.getInstitutionList({
|
||||||
page: page.value,
|
page: mobileFetch ? 1 : page.value,
|
||||||
pageSize: pageSize.value,
|
pageSize: mobileFetch
|
||||||
|
? data.value.length + (pageState.total === data.value.length ? 1 : 0)
|
||||||
|
: pageSize.value,
|
||||||
query: pageState.inputSearch,
|
query: pageState.inputSearch,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
$q.screen.xs ? data.value.push(...ret.result) : (data.value = ret.result);
|
data.value =
|
||||||
|
$q.screen.xs && !mobileFetch
|
||||||
|
? [...data.value, ...ret.result]
|
||||||
|
: ret.result;
|
||||||
pageMax.value = Math.ceil(ret.total / pageSize.value);
|
pageMax.value = Math.ceil(ret.total / pageSize.value);
|
||||||
pageState.total = ret.total;
|
pageState.total = ret.total;
|
||||||
}
|
}
|
||||||
|
|
@ -258,7 +260,11 @@ onMounted(async () => {
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => pageState.inputSearch,
|
() => pageState.inputSearch,
|
||||||
() => fetchData(),
|
() => {
|
||||||
|
page.value = 1;
|
||||||
|
data.value = [];
|
||||||
|
fetchData();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -436,12 +442,12 @@ watch(
|
||||||
class="col surface-2 flex items-center justify-center"
|
class="col surface-2 flex items-center justify-center"
|
||||||
>
|
>
|
||||||
<NoData
|
<NoData
|
||||||
v-if="pageState.total !== 0"
|
v-if="pageState.inputSearch"
|
||||||
:not-found="!!pageState.inputSearch"
|
:not-found="!!pageState.inputSearch"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<CreateButton
|
<CreateButton
|
||||||
v-if="pageState.total === 0"
|
v-if="!pageState.inputSearch && pageState.total === 0"
|
||||||
@click="triggerDialog('add')"
|
@click="triggerDialog('add')"
|
||||||
label="general.add"
|
label="general.add"
|
||||||
:i18n-args="{ text: $t('agencies.title') }"
|
:i18n-args="{ text: $t('agencies.title') }"
|
||||||
|
|
@ -454,6 +460,7 @@ watch(
|
||||||
@load="
|
@load="
|
||||||
(_, done) => {
|
(_, done) => {
|
||||||
if ($q.screen.gt.xs || page === pageMax) return;
|
if ($q.screen.gt.xs || page === pageMax) return;
|
||||||
|
console.log('load');
|
||||||
page = page + 1;
|
page = page + 1;
|
||||||
fetchData().then(() => done(page >= pageMax));
|
fetchData().then(() => done(page >= pageMax));
|
||||||
}
|
}
|
||||||
|
|
@ -508,8 +515,11 @@ watch(
|
||||||
class="text-center"
|
class="text-center"
|
||||||
v-if="fieldSelected.includes('orderNumber')"
|
v-if="fieldSelected.includes('orderNumber')"
|
||||||
>
|
>
|
||||||
{{ props.rowIndex + 1 }}
|
{{
|
||||||
<!-- {{ (currentPage - 1) * pageSize + props.rowIndex + 1 }} -->
|
$q.screen.xs
|
||||||
|
? props.rowIndex + 1
|
||||||
|
: (page - 1) * pageSize + props.rowIndex + 1
|
||||||
|
}}
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td v-if="fieldSelected.includes('name')">
|
<q-td v-if="fieldSelected.includes('name')">
|
||||||
<section class="row items-center no-wrap">
|
<section class="row items-center no-wrap">
|
||||||
|
|
@ -613,7 +623,6 @@ watch(
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
@delete="() => triggerDelete(props.row.id)"
|
@delete="() => triggerDelete(props.row.id)"
|
||||||
@change-status="() => triggerChangeStatus(props.row)"
|
|
||||||
/>
|
/>
|
||||||
</q-td>
|
</q-td>
|
||||||
</q-tr>
|
</q-tr>
|
||||||
|
|
@ -685,7 +694,6 @@ watch(
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
@delete="() => triggerDelete(props.row.id)"
|
@delete="() => triggerDelete(props.row.id)"
|
||||||
@change-status="() => triggerChangeStatus(props.row)"
|
|
||||||
/>
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
@ -782,7 +790,7 @@ watch(
|
||||||
<PaginationComponent
|
<PaginationComponent
|
||||||
v-model:current-page="page"
|
v-model:current-page="page"
|
||||||
v-model:max-page="pageMax"
|
v-model:max-page="pageMax"
|
||||||
:fetch-data="fetchData"
|
:fetch-data="() => fetchData()"
|
||||||
/>
|
/>
|
||||||
</nav>
|
</nav>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
@ -793,7 +801,6 @@ watch(
|
||||||
<AgenciesDialog
|
<AgenciesDialog
|
||||||
ref="refAgenciesDialog"
|
ref="refAgenciesDialog"
|
||||||
:data-id="currAgenciesData && currAgenciesData.id"
|
:data-id="currAgenciesData && currAgenciesData.id"
|
||||||
@change-status="triggerChangeStatus"
|
|
||||||
@drawer-delete="
|
@drawer-delete="
|
||||||
() => {
|
() => {
|
||||||
if (currAgenciesData) triggerDelete(currAgenciesData.id);
|
if (currAgenciesData) triggerDelete(currAgenciesData.id);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue