Update loading more experience (#292)

This commit is contained in:
Germey authored and GitHub committed 2025-12-06 23:49:38 +08:00
1 parent ea1603cf0f
commit aa2c2cd2f7
25 files changed
+274 -24

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "update loading more",
"packageName": "@acedatacloud/nexior",
"email": "cqc@cuiqingcai.com",
"dependentChangeType": "patch"
}
+51
View File
@@ -0,0 +1,51 @@
<template>
<div ref="panel" class="scroll-list relative" @scroll="onHandleScroll">
<top-loading v-if="loading" :text="loadingText" :floating="floatingLoader" />
<slot />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import TopLoading from './TopLoading.vue';
export default defineComponent({
name: 'ScrollList',
components: {
TopLoading
},
props: {
loading: {
type: Boolean,
default: false
},
loadingText: {
type: String,
default: ''
},
floatingLoader: {
type: Boolean,
default: true
}
},
emits: ['reach-top', 'scroll'],
methods: {
onHandleScroll() {
const el = this.$refs.panel as HTMLElement;
this.$emit('scroll', el);
if (el.scrollTop === 0) {
this.$emit('reach-top');
}
},
getScrollElement(): HTMLElement | undefined {
return this.$refs.panel as HTMLElement | undefined;
}
}
});
</script>
<style lang="scss" scoped>
.scroll-list {
position: relative;
}
</style>
+62
View File
@@ -0,0 +1,62 @@
<template>
<div :class="['top-loading', { floating }]" role="status" aria-live="polite">
<el-icon class="is-loading" :size="size">
<loading />
</el-icon>
<span>{{ label }}</span>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElIcon } from 'element-plus';
import { Loading } from '@element-plus/icons-vue';
export default defineComponent({
name: 'TopLoading',
components: {
ElIcon,
Loading
},
props: {
text: {
type: String,
default: ''
},
size: {
type: Number,
default: 16
},
floating: {
type: Boolean,
default: true
}
},
computed: {
label(): string {
return this.text || (this as any).$t('common.status.loading');
}
}
});
</script>
<style lang="scss" scoped>
.top-loading {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
border-radius: 999px;
background: var(--el-bg-color);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
color: var(--el-text-color-regular);
pointer-events: none;
&.floating {
position: absolute;
top: 8px;
left: 50%;
transform: translateX(-50%);
z-index: 1;
}
}
</style>
+20 -8
View File
@@ -2,9 +2,15 @@
<div v-if="tasks?.items === undefined"> <div v-if="tasks?.items === undefined">
<bot-placeholder /> <bot-placeholder />
</div> </div>
<div v-else-if="tasks?.items?.length && tasks?.items?.length > 0" class="tasks h-full w-full overflow-y-auto"> <scroll-list
v-else-if="tasks?.items?.length && tasks?.items?.length > 0"
ref="scrollList"
class="tasks h-full w-full overflow-y-auto"
:loading="loading"
@reach-top="$emit('reach-top')"
>
<task-preview v-for="task in tasks?.items" :key="task.id" :model-value="task" /> <task-preview v-for="task in tasks?.items" :key="task.id" :model-value="task" />
</div> </scroll-list>
<div v-if="tasks?.items?.length === 0" class="w-full h-full flex items-center justify-center"> <div v-if="tasks?.items?.length === 0" class="w-full h-full flex items-center justify-center">
<no-tasks /> <no-tasks />
</div> </div>
@@ -15,13 +21,21 @@ import { defineComponent } from 'vue';
import TaskPreview from './task/Preview.vue'; import TaskPreview from './task/Preview.vue';
import BotPlaceholder from '../common/BotPlaceholder.vue'; import BotPlaceholder from '../common/BotPlaceholder.vue';
import NoTasks from '@/components/common/NoTasks.vue'; import NoTasks from '@/components/common/NoTasks.vue';
import ScrollList from '@/components/common/ScrollList.vue';
export default defineComponent({ export default defineComponent({
name: 'RecentPanel', name: 'RecentPanel',
components: { components: {
TaskPreview, TaskPreview,
BotPlaceholder, BotPlaceholder,
NoTasks NoTasks,
ScrollList
},
props: {
loading: {
type: Boolean,
default: false
}
}, },
emits: ['reach-top'], emits: ['reach-top'],
data() { data() {
@@ -38,11 +52,9 @@ export default defineComponent({
} }
}, },
methods: { methods: {
onHandleScroll() { getScrollElement(): HTMLElement | undefined {
const el = this.$refs.panel as HTMLElement; const list = this.$refs.scrollList as any;
if (el.scrollTop === 0) { return list?.getScrollElement?.();
this.$emit('reach-top');
}
} }
} }
}); });
+4
View File
@@ -187,6 +187,10 @@
"message": "الحالة", "message": "الحالة",
"description": "حالة الكيان" "description": "حالة الكيان"
}, },
"status.loading": {
"message": "جارٍ التحميل...",
"description": "نص الحالة المعروض أثناء تحميل المحتوى"
},
"entity.operation": { "entity.operation": {
"message": "العملية", "message": "العملية",
"description": "عملية الكيان" "description": "عملية الكيان"
+4
View File
@@ -187,6 +187,10 @@
"message": "Status", "message": "Status",
"description": "Der Status der Entität" "description": "Der Status der Entität"
}, },
"status.loading": {
"message": "Wird geladen...",
"description": "Statustext, der während des Ladens angezeigt wird"
},
"entity.operation": { "entity.operation": {
"message": "Operation", "message": "Operation",
"description": "Die Operation der Entität" "description": "Die Operation der Entität"
+4
View File
@@ -187,6 +187,10 @@
"message": "Κατάσταση", "message": "Κατάσταση",
"description": "Η κατάσταση της οντότητας" "description": "Η κατάσταση της οντότητας"
}, },
"status.loading": {
"message": "Φόρτωση...",
"description": "Κείμενο κατάστασης που εμφανίζεται κατά τη φόρτωση περιεχομένου"
},
"entity.operation": { "entity.operation": {
"message": "Λειτουργία", "message": "Λειτουργία",
"description": "Η λειτουργία της οντότητας" "description": "Η λειτουργία της οντότητας"
+4
View File
@@ -187,6 +187,10 @@
"message": "Status", "message": "Status",
"description": "The status of the entity" "description": "The status of the entity"
}, },
"status.loading": {
"message": "Loading...",
"description": "Status text shown while content is loading"
},
"entity.operation": { "entity.operation": {
"message": "Operation", "message": "Operation",
"description": "The operation of the entity" "description": "The operation of the entity"
+4
View File
@@ -187,6 +187,10 @@
"message": "Estado", "message": "Estado",
"description": "El estado de la entidad" "description": "El estado de la entidad"
}, },
"status.loading": {
"message": "Cargando...",
"description": "Texto de estado que se muestra mientras se carga el contenido"
},
"entity.operation": { "entity.operation": {
"message": "Operación", "message": "Operación",
"description": "La operación de la entidad" "description": "La operación de la entidad"
+4
View File
@@ -187,6 +187,10 @@
"message": "Tila", "message": "Tila",
"description": "Entiteetin tila" "description": "Entiteetin tila"
}, },
"status.loading": {
"message": "Ladataan...",
"description": "Tilateksti, joka näytetään sisällön latautuessa"
},
"entity.operation": { "entity.operation": {
"message": "Toiminto", "message": "Toiminto",
"description": "Entiteetin toiminto" "description": "Entiteetin toiminto"
+4
View File
@@ -187,6 +187,10 @@
"message": "Statut", "message": "Statut",
"description": "Le statut de l'entité" "description": "Le statut de l'entité"
}, },
"status.loading": {
"message": "Chargement...",
"description": "Texte de statut affiché pendant le chargement du contenu"
},
"entity.operation": { "entity.operation": {
"message": "Opération", "message": "Opération",
"description": "L'opération de l'entité" "description": "L'opération de l'entité"
+4
View File
@@ -187,6 +187,10 @@
"message": "Stato", "message": "Stato",
"description": "Lo stato dell'entità" "description": "Lo stato dell'entità"
}, },
"status.loading": {
"message": "Caricamento...",
"description": "Testo di stato mostrato durante il caricamento dei contenuti"
},
"entity.operation": { "entity.operation": {
"message": "Operazione", "message": "Operazione",
"description": "L'operazione dell'entità" "description": "L'operazione dell'entità"
+4
View File
@@ -187,6 +187,10 @@
"message": "ステータス", "message": "ステータス",
"description": "エンティティのステータス" "description": "エンティティのステータス"
}, },
"status.loading": {
"message": "読み込み中...",
"description": "コンテンツ読込中に表示されるステータス文言"
},
"entity.operation": { "entity.operation": {
"message": "操作", "message": "操作",
"description": "エンティティの操作" "description": "エンティティの操作"
+4
View File
@@ -187,6 +187,10 @@
"message": "상태", "message": "상태",
"description": "엔티티의 상태" "description": "엔티티의 상태"
}, },
"status.loading": {
"message": "로딩 중...",
"description": "콘텐츠가 로딩될 때 표시되는 상태 문구"
},
"entity.operation": { "entity.operation": {
"message": "작업", "message": "작업",
"description": "엔티티의 작업" "description": "엔티티의 작업"
+4
View File
@@ -187,6 +187,10 @@
"message": "Status", "message": "Status",
"description": "Status encji" "description": "Status encji"
}, },
"status.loading": {
"message": "Ładowanie...",
"description": "Tekst statusu wyświetlany podczas wczytywania treści"
},
"entity.operation": { "entity.operation": {
"message": "Operacja", "message": "Operacja",
"description": "Operacja encji" "description": "Operacja encji"
+4
View File
@@ -187,6 +187,10 @@
"message": "Status", "message": "Status",
"description": "Status da entidade" "description": "Status da entidade"
}, },
"status.loading": {
"message": "Carregando...",
"description": "Texto de status exibido enquanto o conteúdo é carregado"
},
"entity.operation": { "entity.operation": {
"message": "Operação", "message": "Operação",
"description": "Operação da entidade" "description": "Operação da entidade"
+4
View File
@@ -187,6 +187,10 @@
"message": "Статус", "message": "Статус",
"description": "Статус сущности" "description": "Статус сущности"
}, },
"status.loading": {
"message": "Загрузка...",
"description": "Текст статуса, отображаемый во время загрузки контента"
},
"entity.operation": { "entity.operation": {
"message": "Операция", "message": "Операция",
"description": "Операция сущности" "description": "Операция сущности"
+4
View File
@@ -187,6 +187,10 @@
"message": "Status", "message": "Status",
"description": "Status entiteta" "description": "Status entiteta"
}, },
"status.loading": {
"message": "Учитавање...",
"description": "Текст статуса који се приказује док се садржај учитава"
},
"entity.operation": { "entity.operation": {
"message": "Operacija", "message": "Operacija",
"description": "Operacija entiteta" "description": "Operacija entiteta"
+4
View File
@@ -187,6 +187,10 @@
"message": "Status", "message": "Status",
"description": "Status för enheten" "description": "Status för enheten"
}, },
"status.loading": {
"message": "Laddar...",
"description": "Statustext som visas medan innehållet laddas"
},
"entity.operation": { "entity.operation": {
"message": "Operation", "message": "Operation",
"description": "Operationen för enheten" "description": "Operationen för enheten"
+4
View File
@@ -187,6 +187,10 @@
"message": "Статус", "message": "Статус",
"description": "Статус сутності" "description": "Статус сутності"
}, },
"status.loading": {
"message": "Завантаження...",
"description": "Текст статусу, що показується під час завантаження контенту"
},
"entity.operation": { "entity.operation": {
"message": "Операція", "message": "Операція",
"description": "Операція сутності" "description": "Операція сутності"
+4
View File
@@ -187,6 +187,10 @@
"message": "状态", "message": "状态",
"description": "实体的状态" "description": "实体的状态"
}, },
"status.loading": {
"message": "加载中...",
"description": "内容加载时显示的状态文案"
},
"entity.operation": { "entity.operation": {
"message": "操作", "message": "操作",
"description": "实体的操作" "description": "实体的操作"
+4
View File
@@ -187,6 +187,10 @@
"message": "狀態", "message": "狀態",
"description": "實體的狀態" "description": "實體的狀態"
}, },
"status.loading": {
"message": "載入中...",
"description": "內容載入時顯示的狀態文案"
},
"entity.operation": { "entity.operation": {
"message": "操作", "message": "操作",
"description": "實體的操作" "description": "實體的操作"
+47 -13
View File
@@ -4,7 +4,7 @@
<config-panel @generate="onGenerate" /> <config-panel @generate="onGenerate" />
</template> </template>
<template #result> <template #result>
<recent-panel @reach-top="onReachTop" /> <recent-panel ref="recentPanel" :loading="loading" @reach-top="onReachTop" />
</template> </template>
</layout> </layout>
</template> </template>
@@ -25,6 +25,7 @@ const CALLBACK_URL = 'https://webhook.acedata.cloud/nanobanana';
interface IData { interface IData {
task: INanobananaTask | undefined; task: INanobananaTask | undefined;
job: number; job: number;
loading: boolean;
} }
export default defineComponent({ export default defineComponent({
@@ -38,13 +39,17 @@ export default defineComponent({
data(): IData { data(): IData {
return { return {
task: undefined, task: undefined,
job: 0 job: 0,
loading: false
}; };
}, },
computed: { computed: {
loading() { applicationsLoading() {
return this.$store.state.nanobanana?.status?.getApplications === Status.Request; return this.$store.state.nanobanana?.status?.getApplications === Status.Request;
}, },
tasksLoading() {
return this.$store.state.nanobanana?.status?.getTasks === Status.Request;
},
credential() { credential() {
return this.$store.state.nanobanana?.credential; return this.$store.state.nanobanana?.credential;
}, },
@@ -90,9 +95,35 @@ export default defineComponent({
methods: { methods: {
async onReachTop() { async onReachTop() {
console.debug('reached top'); console.debug('reached top');
await this.onGetTasks({ if (this.loading || this.tasksLoading) {
createdAtMax: this.tasks?.items?.[0]?.created_at return;
}); }
const total = this.tasks?.total;
const currentLength = this.tasks?.items?.length || 0;
if (total !== undefined && total <= currentLength) {
return;
}
const oldest = this.tasks?.items?.[0];
if (!oldest?.created_at) {
return;
}
const panel = this.$refs.recentPanel as any;
const el = panel?.getScrollElement?.() as HTMLElement | undefined;
const previousHeight = el?.scrollHeight || 0;
const previousScrollTop = el?.scrollTop || 0;
this.loading = true;
try {
await this.onGetTasks({
createdAtMax: oldest.created_at
});
await this.$nextTick();
if (el) {
const newHeight = el.scrollHeight;
el.scrollTop = newHeight - previousHeight + previousScrollTop;
}
} finally {
this.loading = false;
}
}, },
async onGetService() { async onGetService() {
console.debug('start onGetService'); console.debug('start onGetService');
@@ -106,15 +137,14 @@ export default defineComponent({
await this.onGetTasks(); await this.onGetTasks();
}, },
async onScrollDown() { async onScrollDown() {
setTimeout(() => { await this.$nextTick();
const el = document.querySelector('.tasks'); const el = this.getTasksScrollElement();
if (el) { if (el) {
el.scrollTop = el.scrollHeight; el.scrollTop = el.scrollHeight;
} }
}, 1000);
}, },
async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) { async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) {
if (this.loading) { if (this.applicationsLoading || this.tasksLoading) {
console.debug('loading'); console.debug('loading');
return; return;
} }
@@ -176,6 +206,10 @@ export default defineComponent({
await this.onScrollDown(); await this.onScrollDown();
}, 1000); }, 1000);
}); });
},
getTasksScrollElement(): HTMLElement | undefined {
const panel = this.$refs.recentPanel as any;
return panel?.getScrollElement?.();
} }
} }
}); });
+6
View File
@@ -129,18 +129,22 @@ export const getTasks = async (
createdAtMax createdAtMax
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number } }: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
): Promise<INanobananaTask[]> => { ): Promise<INanobananaTask[]> => {
state.status.getTasks = Status.Request;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.debug('start to get tasks', offset, limit); console.debug('start to get tasks', offset, limit);
const credential = state.credential; const credential = state.credential;
console.debug('current credential', credential); console.debug('current credential', credential);
const token = credential?.token; const token = credential?.token;
if (!token) { if (!token) {
state.status.getTasks = Status.Error;
return reject('no token'); return reject('no token');
} }
nanobananaOperator nanobananaOperator
.tasks( .tasks(
{ {
userId: rootState?.user?.id, userId: rootState?.user?.id,
offset,
limit,
createdAtMin, createdAtMin,
createdAtMax, createdAtMax,
type: 'images' type: 'images'
@@ -158,9 +162,11 @@ export const getTasks = async (
const mergedItems = mergeAndSortLists(existingItems, newItems); const mergedItems = mergeAndSortLists(existingItems, newItems);
commit('setTasksItems', mergedItems); commit('setTasksItems', mergedItems);
commit('setTasksTotal', response.data.count); commit('setTasksTotal', response.data.count);
state.status.getTasks = Status.Success;
resolve(response.data.items); resolve(response.data.items);
}) })
.catch((error) => { .catch((error) => {
state.status.getTasks = Status.Error;
return reject(error); return reject(error);
}); });
}); });
+9 -3
View File
@@ -2,6 +2,12 @@ import { IApplication, ICredential, INanobananaConfig, INanobananaTask, IService
import initialState from './state'; import initialState from './state';
import { INanobananaState } from './models'; import { INanobananaState } from './models';
const defaultTasks = {
items: undefined,
total: undefined,
active: undefined
};
export const resetAll = (state: INanobananaState): void => { export const resetAll = (state: INanobananaState): void => {
Object.assign(state, initialState()); Object.assign(state, initialState());
}; };
@@ -28,7 +34,7 @@ export const setConfig = (state: INanobananaState, payload: INanobananaConfig):
export const setTasksItems = (state: INanobananaState, payload: INanobananaTask[]): void => { export const setTasksItems = (state: INanobananaState, payload: INanobananaTask[]): void => {
const newPayload = { const newPayload = {
...state.tasks, ...(state.tasks || defaultTasks),
items: payload items: payload
} as typeof state.tasks; } as typeof state.tasks;
state.tasks = newPayload; state.tasks = newPayload;
@@ -36,7 +42,7 @@ export const setTasksItems = (state: INanobananaState, payload: INanobananaTask[
export const setTasksTotal = (state: INanobananaState, payload: number): void => { export const setTasksTotal = (state: INanobananaState, payload: number): void => {
const newPayload = { const newPayload = {
...state.tasks, ...(state.tasks || defaultTasks),
total: payload total: payload
} as typeof state.tasks; } as typeof state.tasks;
state.tasks = newPayload; state.tasks = newPayload;
@@ -44,7 +50,7 @@ export const setTasksTotal = (state: INanobananaState, payload: number): void =>
export const setTasksActive = (state: INanobananaState, payload: INanobananaTask): void => { export const setTasksActive = (state: INanobananaState, payload: INanobananaTask): void => {
const newPayload = { const newPayload = {
...state.tasks, ...(state.tasks || defaultTasks),
active: payload active: payload
} as typeof state.tasks; } as typeof state.tasks;
state.tasks = newPayload; state.tasks = newPayload;