Add midjourney pagination (#172)
This commit is contained in:
1 parent
49b2a5846c
commit
31fc4b4472
10 files changed
+137
-32
No files matched your search
@@ -12,7 +12,7 @@
|
||||
:need-apply="needApply"
|
||||
@refresh="onGetApplication"
|
||||
/>
|
||||
<task-list @custom="onCustom" />
|
||||
<task-list @custom="onCustom" @reach-top="onReachTop" />
|
||||
</div>
|
||||
</template>
|
||||
</layout>
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
interface IData {
|
||||
operating: boolean;
|
||||
job: number;
|
||||
timer: NodeJS.Timer;
|
||||
}
|
||||
|
||||
const CALLBACK_URL = 'https://webhook.acedata.cloud/midjourney';
|
||||
@@ -56,7 +57,9 @@ export default defineComponent({
|
||||
data(): IData {
|
||||
return {
|
||||
operating: false,
|
||||
job: 0
|
||||
job: 0,
|
||||
// @ts-ignore
|
||||
timer: undefined
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -159,9 +162,11 @@ export default defineComponent({
|
||||
},
|
||||
watch: {
|
||||
tasks: {
|
||||
handler(val, oldVal) {
|
||||
if (oldVal === undefined && val) {
|
||||
this.onScrollDown();
|
||||
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
|
||||
@@ -172,7 +177,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();
|
||||
@@ -180,8 +185,15 @@ export default defineComponent({
|
||||
},
|
||||
async unmounted() {
|
||||
clearInterval(this.job);
|
||||
clearInterval(this.timer);
|
||||
},
|
||||
methods: {
|
||||
async onReachTop() {
|
||||
console.debug('ddasdasdreached top');
|
||||
await this.onGetTasks({
|
||||
createdAtMax: this.tasks?.items?.[0]?.created_at
|
||||
});
|
||||
},
|
||||
async onGetService() {
|
||||
console.debug('start onGetService');
|
||||
await this.$store.dispatch('midjourney/getService');
|
||||
@@ -232,8 +244,12 @@ export default defineComponent({
|
||||
}
|
||||
})
|
||||
.finally(async () => {
|
||||
await this.onGetTasks();
|
||||
await this.onScrollDown();
|
||||
setTimeout(async () => {
|
||||
await this.onGetTasks();
|
||||
await this.onScrollDown();
|
||||
}, 1000);
|
||||
// await this.onGetTasks();
|
||||
// await this.onScrollDown();
|
||||
});
|
||||
},
|
||||
async onCustom(payload: { image_id: string; action: MidjourneyImagineAction }) {
|
||||
@@ -256,23 +272,33 @@ export default defineComponent({
|
||||
await this.onStartTask(request);
|
||||
},
|
||||
async onScrollDown() {
|
||||
await this.$nextTick(); // 确保 DOM 更新完成后再执行滚动操作
|
||||
setTimeout(() => {
|
||||
// scroll to bottom for `.tasks`
|
||||
const el = document.querySelector('.tasks');
|
||||
|
||||
if (el) {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
}, 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('midjourney/getTasks', {
|
||||
limit: 30,
|
||||
offset: 0
|
||||
limit,
|
||||
createdAtMin,
|
||||
createdAtMax
|
||||
});
|
||||
// await this.$store.dispatch('midjourney/getTasks', {
|
||||
// limit: 30,
|
||||
// offset: 0
|
||||
// });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -149,8 +149,10 @@ export default defineComponent({
|
||||
setTimeout(() => {
|
||||
// scroll to bottom for `.recent`
|
||||
const el = document.querySelector('.recent');
|
||||
console.log('onScrollDown ', el, el.scrollTop, el.scrollHeight);
|
||||
if (el) {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
console.log('onScrollDown ', el.scrollTop, el.scrollHeight);
|
||||
}
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user