Add pika hailuo pagination (#173)

This commit is contained in:
HCode authored and GitHub committed 2025-02-10 22:20:12 +08:00
1 parent 14efcf4e55
commit d8fba2afd8
16 files changed
+172 -33

No files matched your search

+38 -7
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/hailuo';
interface IData {
task: IHailuoTask | 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.hailuo.application;
},
tasks() {
return this.$store.state.hailuo.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() {
@@ -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('hailuo/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('hailuo/getTasks', {
limit: 30,
offset: 0
limit,
createdAtMin,
createdAtMax
});
},
async onGenerateVideo() {
@@ -165,8 +194,10 @@ export default defineComponent({
}
})
.finally(async () => {
await this.onGetTasks();
await this.onScrollDown();
setTimeout(async () => {
await this.onGetTasks();
await this.onScrollDown();
}, 1000);
});
}
}