diff --git a/mail-vue/src/components/email-scroll/index.vue b/mail-vue/src/components/email-scroll/index.vue index c4e1e4f..1d5a653 100644 --- a/mail-vue/src/components/email-scroll/index.vue +++ b/mail-vue/src/components/email-scroll/index.vue @@ -447,14 +447,17 @@ function addItem(email) { if (props.timeSort) { if (noLoading.value) { emailList.push(email) - latestEmail.value = email - total.value++ - } else { - total.value++ } + + if (email.emailId > latestEmail.value.emailId) { + latestEmail.value = email + } + + total.value++ return; } + const index = emailList.findIndex(item => item.emailId < email.emailId) if (index !== -1) { @@ -465,6 +468,10 @@ function addItem(email) { } } + if (email.emailId > latestEmail.value.emailId) { + latestEmail.value = email + } + total.value++ } diff --git a/mail-vue/src/views/email/index.vue b/mail-vue/src/views/email/index.vue index 21096d3..5e3e479 100644 --- a/mail-vue/src/views/email/index.vue +++ b/mail-vue/src/views/email/index.vue @@ -74,22 +74,31 @@ const existIds = new Set(); async function latest() { while (true) { - const latestId = scroll.value.latestEmail?.emailId || 0 + const latestId = scroll.value.latestEmail?.emailId if (!scroll.value.firstLoad && settingStore.settings.autoRefreshTime) { try { const accountId = accountStore.currentAccountId const curTimeSort = params.timeSort - const list = await emailLatest(latestId, accountId) + let list = [] + + //确保发起请求时最后一个邮件是当前账号的,或者 + if (accountId === scroll.value.latestEmail?.accountId) { + list = await emailLatest(latestId, accountId); + } + + //确保请求回来后,账号没有切换,时间排序没有改变 if (accountId === accountStore.currentAccountId && params.timeSort === curTimeSort) { if (list.length > 0) { - list.forEach(email => { + for (let email of list) { - setTimeout(() => { + if (!existIds.has(email.emailId)) { - if (!existIds.has(email.emailId) && innerWidth > 1367) { + existIds.add(email.emailId) + scroll.value.addItem(email) + if (innerWidth > 1367) { ElNotification({ type: 'primary', message: `