From 094b7cd518803d5aa76f60178367a2990eefdcf5 Mon Sep 17 00:00:00 2001 From: HCode <71808213+hyf-github-user@users.noreply.github.com> Date: Wed, 12 Feb 2025 21:52:35 +0800 Subject: [PATCH] Add drawai qrart pagination (#176) --- ...-271cfc54-2629-4ae0-adf4-d731adc544ec.json | 7 +++ src/components/headshots/RecentPanel.vue | 14 +++++- src/components/pika/task/Preview.vue | 26 +++++----- src/components/qrart/RecentPanel.vue | 14 +++++- src/models/headshots.ts | 2 +- src/models/qrart.ts | 2 +- src/operators/headshots.ts | 20 +++++++- src/operators/qrart.ts | 20 +++++++- src/pages/headshots/Index.vue | 47 +++++++++++++++---- src/pages/qrart/Index.vue | 47 +++++++++++++++---- src/store/headshots/actions.ts | 23 +++++++-- src/store/headshots/persist.ts | 2 +- src/store/qrart/actions.ts | 23 +++++++-- src/store/qrart/persist.ts | 2 +- 14 files changed, 202 insertions(+), 47 deletions(-) create mode 100644 change/@acedatacloud-nexior-271cfc54-2629-4ae0-adf4-d731adc544ec.json diff --git a/change/@acedatacloud-nexior-271cfc54-2629-4ae0-adf4-d731adc544ec.json b/change/@acedatacloud-nexior-271cfc54-2629-4ae0-adf4-d731adc544ec.json new file mode 100644 index 00000000..b894961b --- /dev/null +++ b/change/@acedatacloud-nexior-271cfc54-2629-4ae0-adf4-d731adc544ec.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "add drawai qrart pagination", + "packageName": "@acedatacloud/nexior", + "email": "1348977728@qq.com", + "dependentChangeType": "patch" +} diff --git a/src/components/headshots/RecentPanel.vue b/src/components/headshots/RecentPanel.vue index 438f9a7c..ca6359b5 100644 --- a/src/components/headshots/RecentPanel.vue +++ b/src/components/headshots/RecentPanel.vue @@ -1,5 +1,5 @@ @@ -34,6 +34,7 @@ const CALLBACK_URL = 'https://webhook.acedata.cloud/qrart'; interface IData { task: IQrartTask | undefined; job: number; + timer: NodeJS.Timer; } export default defineComponent({ @@ -47,7 +48,9 @@ export default defineComponent({ data(): IData { return { task: undefined, - job: 0 + job: 0, + // @ts-ignore + timer: undefined }; }, computed: { @@ -71,6 +74,21 @@ export default defineComponent({ }, application() { return this.$store.state.qrart.application; + }, + tasks() { + return this.$store.state.qrart.tasks; + } + }, + watch: { + tasks: { + handler(value, oldValue) { + // scroll down if new tasks are added + if (value?.items?.length > oldValue?.items?.length) { + console.debug('new tasks detected'); + // this.onScrollDown(); + } + }, + deep: true } }, async mounted() { @@ -78,7 +96,7 @@ export default defineComponent({ await this.onGetApplication(); await this.onScrollDown(); await this.onGetTasks(); - await this.onScrollDown(); + // await this.onScrollDown(); // @ts-ignore this.job = setInterval(() => { this.onGetTasks(); @@ -86,8 +104,15 @@ export default defineComponent({ }, async unmounted() { clearInterval(this.job); + clearInterval(this.timer); }, methods: { + async onReachTop() { + console.debug('reached top'); + await this.onGetTasks({ + createdAtMax: this.tasks?.items?.[0]?.created_at + }); + }, async onGetService() { console.debug('start onGetService'); await this.$store.dispatch('qrart/getService'); @@ -124,14 +149,18 @@ export default defineComponent({ } }, 500); }, - async onGetTasks() { + async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) { if (this.loading) { console.debug('loading'); return; } + console.debug('start onGetTasks', payload); + const { limit = 5, createdAtMin, createdAtMax } = payload || {}; + console.debug('limit', limit, 'createdAtMin', createdAtMin, 'createdAtMax', createdAtMax); await this.$store.dispatch('qrart/getTasks', { - limit: 30, - offset: 0 + limit, + createdAtMin, + createdAtMax }); }, async onGenerate() { @@ -181,8 +210,10 @@ export default defineComponent({ } }) .finally(async () => { - await this.onGetTasks(); - await this.onScrollDown(); + setTimeout(async () => { + await this.onGetTasks(); + await this.onScrollDown(); + }, 1000); }); } } diff --git a/src/store/headshots/actions.ts b/src/store/headshots/actions.ts index c8f93b17..eafed77c 100644 --- a/src/store/headshots/actions.ts +++ b/src/store/headshots/actions.ts @@ -5,6 +5,7 @@ import { IRootState } from '../common/models'; import { IApplication, ICredential, IHeadshotsConfig, IHeadshotsTask, IService, IApplicationType } from '@/models'; import { Status } from '@/models/common'; import { HEADSHOTS_SERVICE_ID } from '@/constants'; +import { mergeAndSortLists } from '@/utils/merge'; export const resetAll = ({ commit }: ActionContext): void => { commit('resetAll'); @@ -113,7 +114,12 @@ export const getService = async ({ commit, state }: ActionContext, - { offset, limit }: { offset?: number; limit?: number } + { + offset, + limit, + createdAtMin, + createdAtMax + }: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number } ): Promise => { return new Promise((resolve, reject) => { console.debug('start to get tasks', offset, limit); @@ -125,15 +131,24 @@ export const getTasks = async ( headshotsOperator .tasks( { - userId: rootState?.user?.id + userId: rootState?.user?.id, + createdAtMin, + createdAtMax }, { token } ) .then((response) => { - console.debug('get imagine tasks success', response.data.items); - commit('setTasksItems', response.data.items); + console.debug('get videos tasks success', response.data.items); + // merge with existing tasks + const existingItems = state?.tasks?.items || []; + console.debug('existing items', existingItems); + const newItems = response.data.items || []; + console.debug('new items', newItems); + // sort and de-duplicate using created_at + const mergedItems = mergeAndSortLists(existingItems, newItems); + commit('setTasksItems', mergedItems); commit('setTasksTotal', response.data.count); resolve(response.data.items); }) diff --git a/src/store/headshots/persist.ts b/src/store/headshots/persist.ts index 47904624..a41a94f1 100644 --- a/src/store/headshots/persist.ts +++ b/src/store/headshots/persist.ts @@ -1 +1 @@ -export default ['headshots.credential', 'headshots.application', 'headshots.tasks']; +export default ['headshots.credential', 'headshots.application']; diff --git a/src/store/qrart/actions.ts b/src/store/qrart/actions.ts index 2ab002cb..941c9bc0 100644 --- a/src/store/qrart/actions.ts +++ b/src/store/qrart/actions.ts @@ -5,6 +5,7 @@ import { IRootState } from '../common/models'; import { IApplication, IApplicationType, ICredential, IQrartConfig, IQrartTask, IService } from '@/models'; import { Status } from '@/models/common'; import { QRART_SERVICE_ID } from '@/constants'; +import { mergeAndSortLists } from '@/utils/merge'; export const resetAll = ({ commit }: ActionContext): void => { commit('resetAll'); @@ -113,7 +114,12 @@ export const getService = async ({ commit, state }: ActionContext, - { offset, limit }: { offset?: number; limit?: number } + { + offset, + limit, + createdAtMin, + createdAtMax + }: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number } ): Promise => { return new Promise((resolve, reject) => { console.debug('start to get tasks', offset, limit); @@ -125,15 +131,24 @@ export const getTasks = async ( qrartOperator .tasks( { - userId: rootState?.user?.id + userId: rootState?.user?.id, + createdAtMin, + createdAtMax }, { token } ) .then((response) => { - console.debug('get imagine tasks success', response.data.items); - commit('setTasksItems', response.data.items); + console.debug('get qrart tasks success', response.data.items); + // merge with existing tasks + const existingItems = state?.tasks?.items || []; + console.debug('existing items', existingItems); + const newItems = response.data.items || []; + console.debug('new items', newItems); + // sort and de-duplicate using created_at + const mergedItems = mergeAndSortLists(existingItems, newItems); + commit('setTasksItems', mergedItems); commit('setTasksTotal', response.data.count); resolve(response.data.items); }) diff --git a/src/store/qrart/persist.ts b/src/store/qrart/persist.ts index 37211546..dbd27a8d 100644 --- a/src/store/qrart/persist.ts +++ b/src/store/qrart/persist.ts @@ -1 +1 @@ -export default ['qrart.config', 'qrart.credential', 'qrart.application', 'qrart.tasks']; +export default ['qrart.config', 'qrart.credential', 'qrart.application'];