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: `
${email.name}
${email.subject}
`, @@ -101,12 +110,10 @@ async function latest() { }) } - existIds.add(email.emailId) - scroll.value.addItem(email) + await sleep(50) + } - },50) - - }) + } } diff --git a/mail-vue/src/views/sys-setting/index.vue b/mail-vue/src/views/sys-setting/index.vue index 5fff62b..59a3f06 100644 --- a/mail-vue/src/views/sys-setting/index.vue +++ b/mail-vue/src/views/sys-setting/index.vue @@ -754,7 +754,7 @@ defineOptions({ name: 'sys-setting' }) -const currentVersion = 'v2.4.0' +const currentVersion = 'v2.5.0' const hasUpdate = ref(false) let getUpdateErrorCount = 1; const {t, locale} = useI18n(); diff --git a/mail-worker/src/service/email-service.js b/mail-worker/src/service/email-service.js index 9076f52..27d2ef4 100644 --- a/mail-worker/src/service/email-service.js +++ b/mail-worker/src/service/email-service.js @@ -29,6 +29,7 @@ const emailService = { size = Number(size); emailId = Number(emailId); timeSort = Number(timeSort); + accountId = Number(accountId); if (size > 30) { size = 30; @@ -110,6 +111,14 @@ const emailService = { emailRow.attList = atts; }); + if (!latestEmail) { + latestEmail = { + emailId: 0, + accountId: accountId, + userId: userId, + } + } + return { list, total: totalRow.total, latestEmail }; },