修复切换邮箱自动刷新错乱

This commit is contained in:
eoao
2025-11-23 13:25:41 +08:00
parent 7de9b44f79
commit 9ec5345309
4 changed files with 38 additions and 15 deletions

View File

@@ -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++
}

View File

@@ -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: `<div style="cursor: pointer;"><div style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis; font-weight: bold;font-size: 16px;margin-bottom: 5px;">${email.name}</div><div style="color: teal;">${email.subject}</div></div>`,
@@ -101,12 +110,10 @@ async function latest() {
})
}
existIds.add(email.emailId)
scroll.value.addItem(email)
await sleep(50)
}
},50)
})
}
}

View File

@@ -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();

View File

@@ -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 };
},