新增全部邮件自动刷新
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
<div ref="scroll" class="scroll">
|
||||
<el-scrollbar ref="scrollbarRef" style="height: 100%">
|
||||
<div class="scroll-box" :infinite-scroll-immediate="false" v-infinite-scroll="loadData"
|
||||
infinite-scroll-distance="600">
|
||||
infinite-scroll-distance="3000">
|
||||
<div v-if="(skeleton && !loading)" v-for="item in emailList" :key="item.emailId">
|
||||
<div class="email-row"
|
||||
:data-checked="item.checked"
|
||||
@@ -252,7 +252,7 @@ let isMobile = ref(innerWidth < 1367)
|
||||
let skeletonRows = 0
|
||||
const queryParam = reactive({
|
||||
emailId: 0,
|
||||
size: 30,
|
||||
size: 50,
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
|
||||
@@ -11,3 +11,7 @@ export function allEmailDelete(emailIds) {
|
||||
export function allEmailBatchDelete(params) {
|
||||
return http.delete('/allEmail/batchDelete', {params: params} )
|
||||
}
|
||||
|
||||
export function allEmailLatest(emailId) {
|
||||
return http.get('/allEmail/latest', {params: {emailId}, noMsg: true, timeout: 35 * 1000})
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
show-status
|
||||
actionLeft="4px"
|
||||
:show-account-icon="false"
|
||||
:time-sort="params.timeSort"
|
||||
@jump="jumpContent"
|
||||
@refresh-before="refreshBefore"
|
||||
:type="'all-email'"
|
||||
@@ -87,24 +88,31 @@
|
||||
<script setup>
|
||||
import {starAdd, starCancel} from "@/request/star.js";
|
||||
import emailScroll from "@/components/email-scroll/index.vue"
|
||||
import {computed, defineOptions, reactive, ref, watch} from "vue";
|
||||
import {computed, defineOptions, reactive, ref, watch, onMounted} from "vue";
|
||||
import {useEmailStore} from "@/store/email.js";
|
||||
import {
|
||||
allEmailList,
|
||||
allEmailDelete,
|
||||
allEmailBatchDelete
|
||||
allEmailBatchDelete,
|
||||
allEmailLatest
|
||||
} from "@/request/all-email.js";
|
||||
import {Icon} from "@iconify/vue";
|
||||
import router from "@/router/index.js";
|
||||
import {useI18n} from 'vue-i18n';
|
||||
import {toUtc} from "@/utils/day.js";
|
||||
import {AutoRefreshEnum} from "@/enums/setting-enum.js";
|
||||
import {sleep} from "@/utils/time-utils.js";
|
||||
import {useSettingStore} from "@/store/setting.js";
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
defineOptions({
|
||||
name: 'all-email'
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
const {t} = useI18n();
|
||||
const emailStore = useEmailStore();
|
||||
const settingStore = useSettingStore();
|
||||
const clearTime = ref('')
|
||||
const sysEmailScroll = ref({})
|
||||
const searchValue = ref('')
|
||||
@@ -112,6 +120,10 @@ const mySelect = ref()
|
||||
const showBathDelete = ref(false)
|
||||
const clearLoading = ref(false)
|
||||
|
||||
onMounted(() => {
|
||||
latest();
|
||||
})
|
||||
|
||||
const openSelect = () => {
|
||||
mySelect.value.toggleMenu()
|
||||
}
|
||||
@@ -272,6 +284,67 @@ function jumpContent(email) {
|
||||
function getEmailList(emailId, size) {
|
||||
return allEmailList({emailId, size, ...params})
|
||||
}
|
||||
|
||||
async function latest() {
|
||||
|
||||
while (true) {
|
||||
|
||||
await sleep(1000)
|
||||
|
||||
const latestId = sysEmailScroll.value.latestEmail?.emailId
|
||||
|
||||
if (settingStore.settings.autoRefresh === AutoRefreshEnum.DISABLED) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!latestId && latestId !== 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (route.name !== 'all-email') {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
if (params.type !== 'receive') {
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const curTimeSort = params.timeSort
|
||||
let list = await allEmailLatest(latestId)
|
||||
|
||||
if (list.length === 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (params.type !== 'receive') {
|
||||
continue
|
||||
}
|
||||
|
||||
// 确保回来之后条件没变
|
||||
if (params.timeSort !== curTimeSort) {
|
||||
continue
|
||||
}
|
||||
|
||||
for (let email of list) {
|
||||
|
||||
sysEmailScroll.value.addItem(email)
|
||||
await sleep(50)
|
||||
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
if (e.code === 401) {
|
||||
settingStore.settings.autoRefresh = AutoRefreshEnum.DISABLED;
|
||||
}
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<style>
|
||||
|
||||
|
||||
@@ -33,13 +33,14 @@ import {defineOptions, h, onMounted, reactive, ref, watch} from "vue";
|
||||
import {sleep} from "@/utils/time-utils.js";
|
||||
import router from "@/router/index.js";
|
||||
import {Icon} from "@iconify/vue";
|
||||
import {AccountAllReceiveEnum} from "@/enums/account-enum.js";
|
||||
import { useRoute } from 'vue-router'
|
||||
import {AutoRefreshEnum} from "@/enums/setting-enum.js";
|
||||
|
||||
defineOptions({
|
||||
name: 'email'
|
||||
})
|
||||
|
||||
const route = useRoute();
|
||||
const emailStore = useEmailStore();
|
||||
const accountStore = useAccountStore();
|
||||
const settingStore = useSettingStore();
|
||||
@@ -76,6 +77,13 @@ const existIds = new Set();
|
||||
|
||||
async function latest() {
|
||||
while (true) {
|
||||
|
||||
await sleep(1000)
|
||||
|
||||
if (route.name !== 'email') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const latestId = scroll.value.latestEmail?.emailId
|
||||
|
||||
if (!scroll.value.firstLoad && settingStore.settings.autoRefresh === AutoRefreshEnum.ENABLED) {
|
||||
@@ -125,10 +133,12 @@ async function latest() {
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
if (e.code === 401) {
|
||||
settingStore.settings.autoRefresh = AutoRefreshEnum.DISABLED;
|
||||
}
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
await sleep(500)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user