Add drawai qrart pagination (#176)

This commit is contained in:
HCode authored and GitHub committed 2025-02-12 21:52:35 +08:00
1 parent c59c916b99
commit 094b7cd518
14 files changed
+202 -47

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "add drawai qrart pagination",
"packageName": "@acedatacloud/nexior",
"email": "1348977728@qq.com",
"dependentChangeType": "patch"
}
+12 -2
View File
@@ -1,5 +1,5 @@
<template>
<div class="panel recent">
<div ref="panel" class="panel recent" @scroll="onHandleScroll">
<div v-if="tasks?.items === undefined" class="tasks">
<div v-for="_ in 3" :key="_" class="task placeholder">
<div class="left">
@@ -40,6 +40,7 @@ export default defineComponent({
ElSkeleton,
ElSkeletonItem
},
emits: ['reach-top'],
data() {
return {
job: 0
@@ -50,9 +51,18 @@ export default defineComponent({
// reverse the order of the tasks.items
return {
...this.$store.state.headshots?.tasks,
items: this.$store.state.headshots?.tasks?.items?.slice().reverse()
items: this.$store.state.headshots?.tasks?.items?.slice()
};
}
},
methods: {
onHandleScroll() {
const el = this.$refs.panel as HTMLElement;
console.log('reach-top reach-top reach-top');
if (el.scrollTop === 0) {
this.$emit('reach-top');
}
}
}
});
</script>
+13 -13
View File
@@ -141,19 +141,19 @@ export default defineComponent({
}
},
methods: {
onExtend(event: MouseEvent, response: IPikaGenerateResponse) {
event.stopPropagation();
// extend url here
console.debug('set config', response);
this.$store.commit('pika/setConfig', {
...this.$store.state.pika?.config,
video_id: response.video_id,
prompt: response.prompt,
action: 'extend',
thumbnail_url: response.thumbnail_url,
video_url: response.video_url
});
},
// onExtend(event: MouseEvent, response: IPikaGenerateResponse) {
// event.stopPropagation();
// // extend url here
// console.debug('set config', response);
// this.$store.commit('pika/setConfig', {
// ...this.$store.state.pika?.config,
// video_id: response.video_id,
// prompt: response.prompt,
// action: 'extend',
// thumbnail_url: response.thumbnail_url,
// video_url: response.video_url
// });
// },
onDownload(event: MouseEvent, video_url: string) {
event.stopPropagation();
console.log('on download');
+12 -2
View File
@@ -1,5 +1,5 @@
<template>
<div class="panel recent">
<div ref="panel" class="panel recent" @scroll="onHandleScroll">
<div v-if="tasks?.items === undefined" class="tasks">
<div v-for="_ in 3" :key="_" class="task placeholder">
<div class="left">
@@ -40,6 +40,7 @@ export default defineComponent({
ElSkeleton,
ElSkeletonItem
},
emits: ['reach-top'],
data() {
return {
job: 0
@@ -50,9 +51,18 @@ export default defineComponent({
// reverse the order of the tasks.items
return {
...this.$store.state.qrart?.tasks,
items: this.$store.state.qrart?.tasks?.items?.slice().reverse()
items: this.$store.state.qrart?.tasks?.items?.slice()
};
}
},
methods: {
onHandleScroll() {
const el = this.$refs.panel as HTMLElement;
console.log('reach-top reach-top reach-top');
if (el.scrollTop === 0) {
this.$emit('reach-top');
}
}
}
});
</script>
+1 -1
View File
@@ -39,7 +39,7 @@ export interface IHeadshotsTask {
_id: string;
api_id?: string;
application_id?: string;
created_at?: string;
created_at?: number;
credential_id?: string;
trace_id?: string;
user_id?: string;
+1 -1
View File
@@ -58,7 +58,7 @@ export interface IQrartGenerateResponse {
export interface IQrartTask {
id: string;
created_at?: string;
created_at?: number;
request?: IQrartGenerateRequest;
response?: IQrartGenerateResponse;
}
+19 -1
View File
@@ -28,7 +28,15 @@ class HeadshotsOperator {
}
async tasks(
filter: { ids?: string[]; applicationId?: string; userId?: string; limit?: number; offset?: number },
filter: {
ids?: string[];
applicationId?: string;
userId?: string;
limit?: number;
offset?: number;
createdAtMax?: number;
createdAtMin?: number;
},
options: { token: string }
): Promise<AxiosResponse<IHeadshotsTasksResponse>> {
return await axios.post(
@@ -59,6 +67,16 @@ class HeadshotsOperator {
? {
offset: filter.offset
}
: {}),
...(filter.createdAtMax !== undefined
? {
created_at_max: filter.createdAtMax
}
: {}),
...(filter.createdAtMin !== undefined
? {
created_at_min: filter.createdAtMin
}
: {})
},
{
+19 -1
View File
@@ -23,7 +23,15 @@ class QrartOperator {
}
async tasks(
filter: { ids?: string[]; applicationId?: string; userId?: string; limit?: number; offset?: number },
filter: {
ids?: string[];
applicationId?: string;
userId?: string;
limit?: number;
offset?: number;
createdAtMax?: number;
createdAtMin?: number;
},
options: { token: string }
): Promise<AxiosResponse<IQrartTasksResponse>> {
return await axios.post(
@@ -54,6 +62,16 @@ class QrartOperator {
? {
offset: filter.offset
}
: {}),
...(filter.createdAtMax !== undefined
? {
created_at_max: filter.createdAtMax
}
: {}),
...(filter.createdAtMin !== undefined
? {
created_at_min: filter.createdAtMin
}
: {})
},
{
+39 -8
View File
@@ -12,7 +12,7 @@
class="mb-4"
@refresh="onGetApplication"
/>
<recent-panel class="panel recent" />
<recent-panel class="panel recent" @reach-top="onReachTop" />
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
</template>
</layout>
@@ -35,6 +35,7 @@ const CALLBACK_URL = 'https://webhook.acedata.cloud/headshots';
interface IData {
task: IHeadshotsTask | undefined;
job: number;
timer: NodeJS.Timer;
}
export default defineComponent({
@@ -48,7 +49,9 @@ export default defineComponent({
data(): IData {
return {
task: undefined,
job: 0
job: 0,
// @ts-ignore
timer: undefined
};
},
computed: {
@@ -72,6 +75,21 @@ export default defineComponent({
},
application() {
return this.$store.state.headshots.application;
},
tasks() {
return this.$store.state.headshots.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() {
@@ -79,7 +97,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();
@@ -87,8 +105,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('headshots/getService');
@@ -125,14 +150,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('headshots/getTasks', {
limit: 30,
offset: 0
limit,
createdAtMin,
createdAtMax
});
},
async onGeneratePicture() {
@@ -165,8 +194,10 @@ export default defineComponent({
}
})
.finally(async () => {
await this.onGetTasks();
await this.onScrollDown();
setTimeout(async () => {
await this.onGetTasks();
await this.onScrollDown();
}, 1000);
});
}
}
+39 -8
View File
@@ -12,7 +12,7 @@
class="mb-4"
@refresh="onGetApplication"
/>
<recent-panel class="panel recent" />
<recent-panel class="panel recent" @reach-top="onReachTop" />
</template>
</layout>
</template>
@@ -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);
});
}
}
+19 -4
View File
@@ -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<IHeadshotsState, IRootState>): void => {
commit('resetAll');
@@ -113,7 +114,12 @@ export const getService = async ({ commit, state }: ActionContext<IHeadshotsStat
export const getTasks = async (
{ commit, state, rootState }: ActionContext<IHeadshotsState, IRootState>,
{ offset, limit }: { offset?: number; limit?: number }
{
offset,
limit,
createdAtMin,
createdAtMax
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
): Promise<IHeadshotsTask[]> => {
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);
})
+1 -1
View File
@@ -1 +1 @@
export default ['headshots.credential', 'headshots.application', 'headshots.tasks'];
export default ['headshots.credential', 'headshots.application'];
+19 -4
View File
@@ -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<IQrartState, IRootState>): void => {
commit('resetAll');
@@ -113,7 +114,12 @@ export const getService = async ({ commit, state }: ActionContext<IQrartState, I
export const getTasks = async (
{ commit, state, rootState }: ActionContext<IQrartState, IRootState>,
{ offset, limit }: { offset?: number; limit?: number }
{
offset,
limit,
createdAtMin,
createdAtMax
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
): Promise<IQrartTask[]> => {
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);
})
+1 -1
View File
@@ -1 +1 @@
export default ['qrart.config', 'qrart.credential', 'qrart.application', 'qrart.tasks'];
export default ['qrart.config', 'qrart.credential', 'qrart.application'];