更新邮件服务和SMTP配置功能
This commit is contained in:
@@ -30,3 +30,7 @@ export async function setPrimarySmtpConfig(configId) {
|
||||
return data
|
||||
}
|
||||
|
||||
export async function clearPrimarySmtpConfig() {
|
||||
const { data } = await api.post('/smtp/configs/primary/clear')
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { cleanupEmailLogs, fetchEmailLogs, fetchEmailSettings, fetchEmailStats, updateEmailSettings } from '../api/email'
|
||||
import {
|
||||
createSmtpConfig,
|
||||
clearPrimarySmtpConfig,
|
||||
deleteSmtpConfig,
|
||||
fetchSmtpConfigs,
|
||||
setPrimarySmtpConfig,
|
||||
@@ -85,6 +86,7 @@ const smtpConfigs = ref([])
|
||||
const smtpDialogOpen = ref(false)
|
||||
const smtpEditMode = ref(false)
|
||||
const smtpHasPassword = ref(false)
|
||||
const smtpIsPrimary = ref(false)
|
||||
|
||||
const smtpForm = reactive({
|
||||
id: null,
|
||||
@@ -231,6 +233,7 @@ function resetSmtpForm() {
|
||||
smtpForm.daily_limit = 0
|
||||
smtpForm.priority = 0
|
||||
smtpHasPassword.value = false
|
||||
smtpIsPrimary.value = false
|
||||
smtpTemplateKey.value = 'custom'
|
||||
}
|
||||
|
||||
@@ -270,6 +273,7 @@ function openEditSmtp(row) {
|
||||
smtpForm.daily_limit = row.daily_limit ?? 0
|
||||
smtpForm.priority = row.priority ?? 0
|
||||
smtpHasPassword.value = Boolean(row.has_password)
|
||||
smtpIsPrimary.value = Boolean(row.is_primary)
|
||||
smtpTemplateKey.value = inferSmtpTemplateKey(row)
|
||||
|
||||
smtpDialogOpen.value = true
|
||||
@@ -398,6 +402,32 @@ async function doSetPrimary() {
|
||||
}
|
||||
}
|
||||
|
||||
async function doClearPrimary() {
|
||||
if (!smtpEditMode.value) return
|
||||
try {
|
||||
await ElMessageBox.confirm('确定取消主配置吗?取消后将按优先级选择可用SMTP。', '取消主配置', {
|
||||
confirmButtonText: '取消主配置',
|
||||
cancelButtonText: '保留',
|
||||
type: 'warning',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await clearPrimarySmtpConfig()
|
||||
if (!res?.success) {
|
||||
ElMessage.error(res?.error || '操作失败')
|
||||
return
|
||||
}
|
||||
ElMessage.success('已取消主配置')
|
||||
smtpDialogOpen.value = false
|
||||
await loadSmtpConfigs()
|
||||
} catch {
|
||||
// handled by interceptor
|
||||
}
|
||||
}
|
||||
|
||||
async function doDeleteSmtp() {
|
||||
if (!smtpEditMode.value || !smtpForm.id) return
|
||||
try {
|
||||
@@ -781,7 +811,8 @@ onMounted(refreshAll)
|
||||
<template #footer>
|
||||
<div class="dialog-actions">
|
||||
<el-button @click="doTestSmtp">测试连接</el-button>
|
||||
<el-button v-if="smtpEditMode" @click="doSetPrimary">设为主配置</el-button>
|
||||
<el-button v-if="smtpEditMode && smtpIsPrimary" type="warning" plain @click="doClearPrimary">取消主配置</el-button>
|
||||
<el-button v-if="smtpEditMode && !smtpIsPrimary" @click="doSetPrimary">设为主配置</el-button>
|
||||
<el-button v-if="smtpEditMode" type="danger" plain @click="doDeleteSmtp">删除配置</el-button>
|
||||
<div class="spacer"></div>
|
||||
<el-button @click="smtpDialogOpen = false">取消</el-button>
|
||||
|
||||
Reference in New Issue
Block a user