feat: display verification code in frontend email list

This commit is contained in:
eoao
2026-05-10 00:26:45 +08:00
parent 92e18ea683
commit a46192b214
5 changed files with 77 additions and 20 deletions

View File

@@ -69,7 +69,7 @@
<div v-else></div>
<span class="name">
<span>
<div class="unread" v-if="isMobile && (item.unread === EmailUnreadEnum.UNREAD && showUnread) "/>
<div class="unread" v-if="isMobile && !item.code && (item.unread === EmailUnreadEnum.UNREAD && showUnread) "/>
<slot name="name" :email="item"> {{ item.name }}</slot>
</span>
<span>
@@ -81,10 +81,13 @@
<div>
<div class="email-text">
<span class="email-subject" :style="(item.unread === EmailUnreadEnum.UNREAD && showUnread) ? 'font-weight: bold' : ''">
<div class="unread" v-if="!isMobile && (item.unread === EmailUnreadEnum.UNREAD && showUnread) "/>
<slot name="subject" :email="item" >
{{ item.subject || '\u200B' }}
</slot>
<div class="unread" v-if="!isMobile && !item.code && (item.unread === EmailUnreadEnum.UNREAD && showUnread) "/>
<span v-if="item.code" class="code-tag" @click.stop="copyCode(item.code)">[{{ t('codeLabel') }}{{ item.code }}]</span>
<span class="subject-text">
<slot name="subject" :email="item" >
{{ item.subject || '\u200B' }}
</slot>
</span>
</span>
<span class="email-content">{{ item.formatText || '\u200B' }}</span>
</div>
@@ -152,6 +155,14 @@
>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item v-if="rightClickEmail.code" @click="copyCode(rightClickEmail.code)" >
<template #default>
<div class="right-dropdown-item">
<Icon icon="fluent-color:clipboard-24" width="20" height="20" />
<span>{{t('copyCode')}}</span>
</div>
</template>
</el-dropdown-item>
<el-dropdown-item v-if="['email'].includes(props.type)" @click="emailRead(rightClickEmail.emailId)" >
<template #default>
<div class="right-dropdown-item">
@@ -656,6 +667,24 @@ function handleSearch(type, value) {
emit('right-search', type, value);
}
async function copyCode(code) {
try {
await navigator.clipboard.writeText(code);
ElMessage({
message: t('copySuccessMsg'),
type: 'success',
plain: true
})
} catch (err) {
console.error(`${t('copyFailMsg')}:`, err);
ElMessage({
message: t('copyFailMsg'),
type: 'error',
plain: true
})
}
}
function handleDelete() {
ElMessageBox.confirm(t('delEmailsConfirm'), {
confirmButtonText: t('confirm'),
@@ -1139,14 +1168,37 @@ function loadData() {
}
.email-subject {
display: flex;
align-items: center;
gap: 6px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
min-width: 0;
@media (min-width: 1367px) {
padding-left: 5px;
}
}
.code-tag {
flex: 0 0 auto;
max-width: 170px;
height: 20px;
line-height: 20px;
font-size: 14px;
color: var(--el-text-color-primary);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
cursor: pointer;
}
.subject-text {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
min-width: 0;
}
.email-content {
overflow: hidden;
white-space: nowrap;

View File

@@ -104,6 +104,8 @@ const en = {
validUntil: 'Valid Until',
expired: 'Expired',
copy: 'Copy',
copyCode: 'Copy Code',
codeLabel: 'Code: ',
history: 'History',
addRegKey: 'Add Invite Code',
regKey: 'Invite Code',

View File

@@ -104,6 +104,8 @@ const zh = {
validUntil: '有效至期',
expired: '已过期',
copy: '复制',
copyCode: '复制验证码',
codeLabel: '验证码:',
history: '记录',
addRegKey: '添加注册码',
regKey: '注册码',

View File

@@ -35,7 +35,11 @@ const dbInit = {
async v3_0DB(c) {
try {
await c.env.db.prepare(`ALTER TABLE email ADD COLUMN code TEXT NOT NULL DEFAULT '';`).run();
await c.env.db.batch([
await c.env.db.prepare(`ALTER TABLE email ADD COLUMN code TEXT NOT NULL DEFAULT '';`).run(),
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN ai_code INTEGER NOT NULL DEFAULT 1;`).run(),
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN ai_code_filter TEXT NOT NULL DEFAULT '';`).run()
]);
} catch (e) {
console.warn(`跳过字段:${e.message}`);
}
@@ -50,17 +54,6 @@ const dbInit = {
console.warn(`跳过字段:${e.message}`);
}
try {
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN ai_code INTEGER NOT NULL DEFAULT 1;`).run();
} catch (e) {
console.warn(`跳过字段:${e.message}`);
}
try {
await c.env.db.prepare(`ALTER TABLE setting ADD COLUMN ai_code_filter TEXT NOT NULL DEFAULT '';`).run();
} catch (e) {
console.warn(`跳过字段:${e.message}`);
}
},
async v2_9DB(c) {

View File

@@ -22,7 +22,7 @@ const aiService = {
messages: [
{
role: 'system',
content: 'You extract verification codes from emails. Return only JSON like {"code":"123456"} or {"code":""}. Do not explain.'
content: 'You extract verification codes from emails. Return only JSON like {"code":"123456"} or {"code":""}. The code must be 6 characters or fewer and must not contain spaces. If the code is longer than 6 characters or contains spaces, return {"code":""}. Do not explain.'
},
{
role: 'user',
@@ -35,7 +35,15 @@ const aiService = {
const content = typeof result === 'string' ? result : result?.response || '';
const json = JSON.parse(content);
return typeof json.code === 'string' ? json.code.trim().slice(0, 64) : '';
if (typeof json.code !== 'string') {
return '';
}
if (json.code.length > 6 || /\s/.test(json.code)) {
return '';
}
return json.code;
} catch (e) {
console.error('验证码提取失败: ', e);
return '';