新增显示所有邮箱邮件

This commit is contained in:
eoao
2025-12-07 22:08:00 +08:00
parent 9ec5345309
commit 13abc11f2c
21 changed files with 184 additions and 48 deletions

View File

@@ -34,7 +34,7 @@ http.interceptors.response.use((res) => {
repeatNum: -4,
})
localStorage.removeItem('token')
router.push('/login')
router.replace('/login')
reject(data)
} else if (data.code === 403) {
ElMessage({

View File

@@ -496,6 +496,8 @@ function updateCheckStatus() {
}
function jumpDetails(email) {
const sel = window.getSelection();
if (sel && !sel.isCollapsed) return;
emit('jump', email)
}
@@ -907,7 +909,7 @@ function loadData() {
.header-actions {
display: grid;
grid-template-columns: auto 1fr auto auto;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 15px;
padding: 3px 15px;

View File

@@ -64,10 +64,6 @@ const language = computed(() => {
return 'zh_CN'
}
if (locale.value === 'zhTW') {
return 'zh_TW'
}
return 'en'
})

View File

@@ -0,0 +1,4 @@
export const AccountAllReceiveEnum = {
DISABLED: 0,
ENABLED: 1
}

View File

@@ -309,7 +309,8 @@ const en = {
atLeast: 'At Least',
character: '',
mustNotContain: 'Must Not Contain',
mustNotContainDesc: 'Separate with commas'
mustNotContainDesc: 'Separate with commas',
setSuccess: 'Settings saved successfully'
}
export default en

View File

@@ -309,6 +309,7 @@ const zh = {
atLeast: '至少',
character: '位',
mustNotContain: '禁止包含',
mustNotContainDesc: '输入多个值用,分开'
mustNotContainDesc: '输入多个值用,分开',
setSuccess: '设置成功'
}
export default zh

View File

@@ -694,4 +694,16 @@ addCollection({
}
}
})
addCollection({
"prefix": "flat-color-icons",
"lastModified": 1754899066,
"aliases": {},
"width": 48,
"height": 48,
"icons": {
"folder": {
"body": "<path fill=\"rgb(51, 126, 204)\" d=\"M40 12H22l-4-4H8c-2.2 0-4 1.8-4 4v8h40v-4c0-2.2-1.8-4-4-4\"/><path fill=\"#23C5F0\" d=\"M40 12H8c-2.2 0-4 1.8-4 4v20c0 2.2 1.8 4 4 4h32c2.2 0 4-1.8 4-4V16c0-2.2-1.8-4-4-4\"/>"
}
}
})

View File

@@ -13,7 +13,8 @@
</div>
<div class="opt">
<div class="send-email" @click.stop>
<Icon icon="eva:email-fill" width="22" height="22" color="#fccb1a"/>
<Icon @click="setAllReceive(item)" v-if="!item.allReceive" icon="eva:email-fill" width="22" height="22" color="#fccb1a"/>
<Icon @click="setAllReceive(item)" v-else icon="flat-color-icons:folder" width="22" height="22" color="#23c4f1" />
</div>
<div class="settings" @click.stop>
<Icon icon="fluent-color:clipboard-24" width="22" height="22" @click.stop="copyAccount(item.email)"/>
@@ -127,19 +128,22 @@
<script setup>
import {Icon} from "@iconify/vue";
import {nextTick, reactive, ref, watch} from "vue";
import {accountList, accountAdd, accountDelete, accountSetName} from "@/request/account.js";
import {accountList, accountAdd, accountDelete, accountSetName, accountSetAllReceive} from "@/request/account.js";
import {sleep} from "@/utils/time-utils.js"
import {isEmail} from "@/utils/verify-utils.js";
import {useSettingStore} from "@/store/setting.js";
import {useAccountStore} from "@/store/account.js";
import {useEmailStore} from "@/store/email.js";
import {useUserStore} from "@/store/user.js";
import {hasPerm} from "@/perm/perm.js"
import {useI18n} from "vue-i18n";
import {AccountAllReceiveEnum} from "@/enums/account-enum.js";
const {t} = useI18n();
const userStore = useUserStore();
const accountStore = useAccountStore();
const settingStore = useSettingStore();
const emailStore = useEmailStore();
const showAdd = ref(false)
const addLoading = ref(false);
const domainList = settingStore.domainList
@@ -254,6 +258,28 @@ function openSetName(accountItem) {
setNameShow.value = true
}
function setAllReceive(account) {
let allReceiveAccount = accounts.find(account => account.allReceive === AccountAllReceiveEnum.ENABLED);
if (allReceiveAccount && allReceiveAccount.accountId !== account.accountId) allReceiveAccount.allReceive = AccountAllReceiveEnum.DISABLED;
account.allReceive = account.allReceive === AccountAllReceiveEnum.DISABLED ? AccountAllReceiveEnum.ENABLED : AccountAllReceiveEnum.DISABLED;
accountSetAllReceive(account.accountId).catch(() => {
account.allReceive = account.allReceive === AccountAllReceiveEnum.DISABLED ? AccountAllReceiveEnum.ENABLED : AccountAllReceiveEnum.DISABLED;
if (allReceiveAccount) allReceiveAccount.allReceive = AccountAllReceiveEnum.ENABLED;
}).then(() => {
if (account.allReceive === AccountAllReceiveEnum.ENABLED) {
ElMessage({
message: t('setSuccess'),
type: 'success',
plain: true,
})
}
changeAccount(account);
emailStore.emailScroll?.refreshList();
emailStore.sendScroll?.refreshList();
})
}
function showNullSetting(item) {
return !hasPerm('email:send') && !(item.accountId !== userStore.user.accountId && hasPerm('account:delete'))
}
@@ -351,7 +377,7 @@ function getAccountList() {
noLoading.value = true
}
if (accounts.length === 0) {
accountStore.currentAccount = list[0].accountId
accountStore.currentAccount = list[0]
}
queryParams.accountId = list.at(-1).accountId
accounts.push(...list)

View File

@@ -116,6 +116,7 @@ import {useWriterStore} from "@/store/writer.js";
import db from "@/db/db.js";
import dayjs from "dayjs";
import {useI18n} from "vue-i18n";
import router from "@/router/index.js";
defineExpose({
open,
@@ -392,6 +393,10 @@ async function sendEmail() {
message: h('span', {style: 'color: teal'}, e.message),
position: 'bottom-right'
})
if (e.code === 401) {
localStorage.removeItem('token');
router.replace('/login');
}
show.value = true
addRecipientRecord();
}).finally(() => {

View File

@@ -16,3 +16,7 @@ export function accountDelete(accountId) {
return http.delete('/account/delete', {params: {accountId}})
}
export function accountSetAllReceive(accountId) {
return http.put('/account/setAllReceive', {accountId})
}

View File

@@ -1,15 +1,15 @@
import http from '@/axios/index.js';
export function emailList(accountId, emailId, timeSort, size, type) {
return http.get('/email/list', {params: {accountId, emailId, timeSort, size, type}})
export function emailList(accountId, allReceive, emailId, timeSort, size, type) {
return http.get('/email/list', {params: {accountId, allReceive, emailId, timeSort, size, type}})
}
export function emailDelete(emailIds) {
return http.delete('/email/delete?emailIds=' + emailIds)
}
export function emailLatest(emailId, accountId) {
return http.get('/email/latest', {params: {emailId, accountId}, noMsg: true })
export function emailLatest(emailId, accountId, allReceive) {
return http.get('/email/latest', {params: {emailId, accountId, allReceive}, noMsg: true })
}
export function emailRead(emailIds) {

View File

@@ -397,7 +397,7 @@ function getEmailList(emailId, size) {
}
.clear {
@media (max-width: 409px) {
@media (max-width: 419px) {
position: absolute;
top: 41px;
left: 242px;
@@ -405,7 +405,7 @@ function getEmailList(emailId, size) {
}
:deep(.reload) {
@media (max-width: 409px) {
@media (max-width: 419px) {
position: absolute;
top: 42px;
left: 208px;
@@ -413,10 +413,16 @@ function getEmailList(emailId, size) {
}
:deep(.delete) {
@media (max-width: 443px) {
@media (max-width: 456px) {
position: absolute;
top: 43px;
left: 284px;
left: 294px;
}
@media (max-width: 419px) {
position: absolute;
top: 43px;
left: 282px;
}
}
</style>

View File

@@ -33,6 +33,7 @@ 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";
defineOptions({
name: 'email'
@@ -79,20 +80,24 @@ async function latest() {
if (!scroll.value.firstLoad && settingStore.settings.autoRefreshTime) {
try {
const accountId = accountStore.currentAccountId
const allReceive = scroll.value.latestEmail?.allReceive
const curTimeSort = params.timeSort
let list = []
//确保发起请求时最后一个邮件是当前账号的,或者
if (accountId === scroll.value.latestEmail?.accountId) {
list = await emailLatest(latestId, accountId);
if (accountId === scroll.value.latestEmail?.reqAccountId) {
list = await emailLatest(latestId, accountId, allReceive);
}
//确保请求回来后,账号没有切换,时间排序没有改变
if (accountId === accountStore.currentAccountId && params.timeSort === curTimeSort) {
//确保请求回来后,账号没有切换,时间排序没有改变,全部邮件类型没变
if (accountId === accountStore.currentAccountId && params.timeSort === curTimeSort && allReceive === accountStore.currentAccount.allReceive) {
if (list.length > 0) {
for (let email of list) {
email.reqAccountId = accountId;
email.allReceive = allReceive;
if (!existIds.has(email.emailId)) {
existIds.add(email.emailId)
@@ -135,7 +140,13 @@ function cancelStar(email) {
}
function getEmailList(emailId, size) {
return emailList(accountStore.currentAccountId, emailId, params.timeSort, size, 0)
const accountId = accountStore.currentAccountId;
const allReceive = accountStore.currentAccount.allReceive;
return emailList(accountId, allReceive, emailId, params.timeSort, size, 0).then(data => {
data.latestEmail.reqAccountId = accountId;
data.latestEmail.allReceive = allReceive;
return data;
})
}
</script>

View File

@@ -29,6 +29,7 @@ import {starAdd, starCancel} from "@/request/star.js";
import {defineOptions, onMounted, reactive, ref, watch} from "vue";
import router from "@/router/index.js";
import {Icon} from "@iconify/vue";
import {AccountAllReceiveEnum} from "@/enums/account-enum.js";
defineOptions({
name: 'send'
@@ -71,7 +72,13 @@ function cancelStar(email) {
}
function getEmailList(emailId, size) {
return emailList(accountStore.currentAccountId, emailId, params.timeSort, size, 1)
const accountId = accountStore.currentAccountId;
const allReceive = accountStore.currentAccount.allReceive;
return emailList(accountId, allReceive, emailId, params.timeSort, size, 1).then(data => {
data.latestEmail.reqAccountId = accountId;
data.latestEmail.allReceive = allReceive;
return data;
})
}
</script>

View File

@@ -754,7 +754,7 @@ defineOptions({
name: 'sys-setting'
})
const currentVersion = 'v2.5.0'
const currentVersion = 'v2.6.0'
const hasUpdate = ref(false)
let getUpdateErrorCount = 1;
const {t, locale} = useI18n();

View File

@@ -22,3 +22,8 @@ app.put('/account/setName', async (c) => {
await accountService.setName(c, await c.req.json(), userContext.getUserId(c));
return c.json(result.ok());
});
app.put('/account/setAllReceive', async (c) => {
await accountService.setAllReceive(c, await c.req.json(), userContext.getUserId(c));
return c.json(result.ok());
});

View File

@@ -7,6 +7,13 @@ export const userConst = {
}
}
export const accountConst = {
allReceive: {
CLOSE: 0,
OPEN: 1
}
}
export const roleConst = {
isDefault: {
CLOSE: 0,

View File

@@ -8,6 +8,7 @@ export const account = sqliteTable('account', {
latestEmailTime: text('latest_email_time'),
createTime: text('create_time').default(sql`CURRENT_TIMESTAMP`),
userId: integer('user_id').notNull(),
allReceive: integer('all_receive').default(0).notNull(),
isDel: integer('is_del').default(0).notNull(),
});
export default account

View File

@@ -25,10 +25,19 @@ const init = {
await this.v2_3DB(c);
await this.v2_4DB(c);
await this.v2_5DB(c);
await this.v2_6DB(c);
await settingService.refresh(c);
return c.text(t('initSuccess'));
},
async v2_6DB(c) {
try {
await c.env.db.prepare(`ALTER TABLE account ADD COLUMN all_receive INTEGER NOT NULL DEFAULT 0;`).run();
} catch (e) {
console.error(e)
}
},
async v2_5DB(c) {
try {

View File

@@ -6,7 +6,7 @@ import emailService from './email-service';
import orm from '../entity/orm';
import account from '../entity/account';
import { and, asc, eq, gt, inArray, count, sql, ne } from 'drizzle-orm';
import { isDel, settingConst } from '../const/entity-const';
import {accountConst, isDel, settingConst} from '../const/entity-const';
import settingService from './setting-service';
import turnstileService from './turnstile-service';
import roleService from './role-service';
@@ -231,8 +231,18 @@ const accountService = {
const { accountId } = params
await emailService.physicsDeleteByAccountId(c, accountId)
await orm(c).delete(account).where(eq(account.accountId, accountId)).run();
}
},
async setAllReceive(c, params, userId) {
let a = null
const { accountId } = params;
const accountRow = await this.selectById(c, accountId);
if (accountRow.userId !== userId) {
return;
}
await orm(c).update(account).set({ allReceive: accountConst.allReceive.CLOSE }).where(eq(account.userId, userId)).run();
await orm(c).update(account).set({ allReceive: accountRow.allReceive ? 0 : 1 }).where(eq(account.accountId, accountId)).run();
}
};
export default accountService;

View File

@@ -19,17 +19,19 @@ import kvConst from '../const/kv-const';
import { t } from '../i18n/i18n'
import r2Service from './r2-service';
import domainUtils from '../utils/domain-uitls';
import account from "../entity/account";
const emailService = {
async list(c, params, userId) {
let { emailId, type, accountId, size, timeSort } = params;
let { emailId, type, accountId, size, timeSort, allReceive } = params;
size = Number(size);
emailId = Number(emailId);
timeSort = Number(timeSort);
accountId = Number(accountId);
allReceive = Number(allReceive);
if (size > 30) {
size = 30;
@@ -45,6 +47,10 @@ const emailService = {
}
if (isNaN(allReceive)) {
let accountRow = await accountService.selectById(c, accountId);
allReceive = accountRow.allReceive;
}
const query = orm(c)
.select({
@@ -58,14 +64,18 @@ const emailService = {
eq(star.emailId, email.emailId),
eq(star.userId, userId)
)
).leftJoin(
account,
eq(account.accountId, email.accountId)
)
.where(
and(
allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.userId, userId),
eq(email.accountId, accountId),
timeSort ? gt(email.emailId, emailId) : lt(email.emailId, emailId),
eq(email.type, type),
eq(email.isDel, isDel.NORMAL)
eq(email.isDel, isDel.NORMAL),
eq(account.isDel, isDel.NORMAL)
)
);
@@ -77,23 +87,29 @@ const emailService = {
const listQuery = query.limit(size).all();
const totalQuery = orm(c).select({ total: count() }).from(email).where(
and(
eq(email.accountId, accountId),
eq(email.userId, userId),
eq(email.type, type),
eq(email.isDel, isDel.NORMAL)
const totalQuery = orm(c).select({ total: count() }).from(email)
.leftJoin(
account,
eq(account.accountId, email.accountId)
)
.where(
and(
allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.userId, userId),
eq(email.type, type),
eq(email.isDel, isDel.NORMAL),
eq(account.isDel, isDel.NORMAL)
)
).get();
const latestEmailQuery = orm(c).select().from(email).where(
and(
eq(email.accountId, accountId),
allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.userId, userId),
eq(email.type, type),
eq(email.isDel, isDel.NORMAL)
))
.orderBy(desc(email.emailId)).limit(1).get();
.orderBy(desc(email.emailId)).limit(size).get();
let [list, totalRow, latestEmail] = await Promise.all([listQuery, totalQuery, latestEmailQuery]);
@@ -445,15 +461,28 @@ const emailService = {
},
async latest(c, params, userId) {
let { emailId, accountId } = params;
const list = await orm(c).select().from(email).where(
and(
eq(email.userId, userId),
eq(email.isDel, isDel.NORMAL),
eq(email.accountId, accountId),
eq(email.type, emailConst.type.RECEIVE),
gt(email.emailId, emailId)
))
let { emailId, accountId, allReceive } = params;
allReceive = Number(allReceive);
if (isNaN(allReceive)) {
let accountRow = await accountService.selectById(c, accountId);
allReceive = accountRow.allReceive;
}
const list = await orm(c).select({...email}).from(email)
.leftJoin(
account,
eq(account.accountId, email.accountId)
)
.where(
and(
eq(email.userId, userId),
eq(email.isDel, isDel.NORMAL),
eq(account.isDel, isDel.NORMAL),
allReceive ? eq(1,1) : eq(email.accountId, accountId),
eq(email.type, emailConst.type.RECEIVE),
gt(email.emailId, emailId)
))
.orderBy(desc(email.emailId))
.limit(20);