|
|
|
|
@ -578,10 +578,21 @@
|
|
|
|
|
|
|
|
|
|
<!-- 收件人详情 -->
|
|
|
|
|
<div class="detail-section">
|
|
|
|
|
<h4 class="section-title">
|
|
|
|
|
<i class="el-icon-user-solid"></i>
|
|
|
|
|
收件人详情 ({{ detailRecord.recipients.length }}人)
|
|
|
|
|
</h4>
|
|
|
|
|
<div class="section-title-row">
|
|
|
|
|
<h4 class="section-title">
|
|
|
|
|
<i class="el-icon-user-solid"></i>
|
|
|
|
|
收件人详情 ({{ detailRecord.recipients.length }}人)
|
|
|
|
|
</h4>
|
|
|
|
|
<el-button
|
|
|
|
|
v-if="detailRecord.failCount > 0"
|
|
|
|
|
size="small"
|
|
|
|
|
type="danger"
|
|
|
|
|
plain
|
|
|
|
|
@click="exportFailedRecipients">
|
|
|
|
|
<i class="el-icon-download"></i>
|
|
|
|
|
导出发送失败 ({{ detailRecord.failCount }}人)
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
<el-table :data="detailRecord.recipients" size="small" :max-height="300">
|
|
|
|
|
<el-table-column prop="email" label="邮箱地址" min-width="200"></el-table-column>
|
|
|
|
|
<el-table-column label="发送状态" width="120">
|
|
|
|
|
@ -743,7 +754,7 @@
|
|
|
|
|
<script>
|
|
|
|
|
import { saveEmailTemplate, getEmailTemplateList, deleteEmailTemplate } from '@/api/email/index'
|
|
|
|
|
import { uploadEmailRecord } from '@/api/email/index'
|
|
|
|
|
import { saveEmailRecord, getEmailRecordList, sendEmail } from '@/api/email/index'
|
|
|
|
|
import { saveEmailRecord, getEmailRecordList, getEmailRecordDetail, sendEmail } from '@/api/email/index'
|
|
|
|
|
|
|
|
|
|
import { indexStudy } from '@/api/student/index.js'
|
|
|
|
|
|
|
|
|
|
@ -845,7 +856,7 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
validEmailsCount() {
|
|
|
|
|
return this.recipients.filter(user => user.email && user.email.includes('@')).length
|
|
|
|
|
return this.recipients.filter(user => this.normalizeEmailValue(user.email).includes('@')).length
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
previewRecipients() {
|
|
|
|
|
@ -913,6 +924,11 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
|
normalizeEmailValue(value) {
|
|
|
|
|
if (value == null || value === '') return ''
|
|
|
|
|
return String(value).trim()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadTemplates() {
|
|
|
|
|
getEmailTemplateList().then(res => {
|
|
|
|
|
// 处理API返回的数据结构
|
|
|
|
|
@ -1062,8 +1078,9 @@ export default {
|
|
|
|
|
uploadEmailRecord(formData)
|
|
|
|
|
.then(res => {
|
|
|
|
|
// 直接用res作为数组
|
|
|
|
|
const newUsers = (res || []).map(item => ({
|
|
|
|
|
email: item.email,
|
|
|
|
|
const list = Array.isArray(res) ? res : (res.data || [])
|
|
|
|
|
const newUsers = list.map(item => ({
|
|
|
|
|
email: this.normalizeEmailValue(item.email),
|
|
|
|
|
...item.var_data
|
|
|
|
|
}))
|
|
|
|
|
// 自动收集所有字段,跳过email字段
|
|
|
|
|
@ -1311,22 +1328,98 @@ export default {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 发送记录相关方法
|
|
|
|
|
toggleHistoryDetail(record) {
|
|
|
|
|
// 设置详情数据并显示模态框
|
|
|
|
|
this.detailRecord = {
|
|
|
|
|
subject: record.subject,
|
|
|
|
|
templateName: record.email_template ? record.email_template.title : '未知模板',
|
|
|
|
|
templateContent: record.email_template ? record.email_template.content : '',
|
|
|
|
|
totalRecipients: record.email_record_users_count,
|
|
|
|
|
successCount: record.success_count,
|
|
|
|
|
failCount: record.fail_count,
|
|
|
|
|
status: record.status,
|
|
|
|
|
statusText: this.getStatusText(record.status),
|
|
|
|
|
sendTime: record.send_time || record.created_at,
|
|
|
|
|
createdTime: record.created_at,
|
|
|
|
|
recipients: record.email_record_users || []
|
|
|
|
|
async toggleHistoryDetail(record) {
|
|
|
|
|
const loading = this.$loading({
|
|
|
|
|
lock: true,
|
|
|
|
|
text: '正在加载发送详情...',
|
|
|
|
|
spinner: 'el-icon-loading',
|
|
|
|
|
background: 'rgba(0, 0, 0, 0.7)'
|
|
|
|
|
})
|
|
|
|
|
try {
|
|
|
|
|
const res = await getEmailRecordDetail({
|
|
|
|
|
id: record.id,
|
|
|
|
|
show_relation: ['emailTemplate', 'emailRecordUsers']
|
|
|
|
|
})
|
|
|
|
|
const detail = res.data || res
|
|
|
|
|
this.detailRecord = {
|
|
|
|
|
id: detail.id,
|
|
|
|
|
subject: detail.subject,
|
|
|
|
|
templateName: detail.email_template ? detail.email_template.title : '未知模板',
|
|
|
|
|
templateContent: detail.email_template ? detail.email_template.content : '',
|
|
|
|
|
totalRecipients: detail.email_record_users_count || (detail.email_record_users || []).length,
|
|
|
|
|
successCount: detail.success_count || 0,
|
|
|
|
|
failCount: detail.fail_count || 0,
|
|
|
|
|
status: detail.status,
|
|
|
|
|
statusText: this.getStatusText(detail.status),
|
|
|
|
|
sendTime: detail.send_time || detail.created_at,
|
|
|
|
|
createdTime: detail.created_at,
|
|
|
|
|
recipients: detail.email_record_users || []
|
|
|
|
|
}
|
|
|
|
|
this.showDetailModal = true
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('获取发送详情失败:', error)
|
|
|
|
|
this.$message.error('获取发送详情失败')
|
|
|
|
|
} finally {
|
|
|
|
|
loading.close()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
exportFailedRecipients() {
|
|
|
|
|
if (!this.detailRecord || !this.detailRecord.recipients || this.detailRecord.recipients.length === 0) {
|
|
|
|
|
this.$message.warning('暂无收件人数据')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const failedList = this.detailRecord.recipients.filter(item => Number(item.status) === 2)
|
|
|
|
|
if (failedList.length === 0) {
|
|
|
|
|
this.$message.warning('没有发送失败的记录')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.showDetailModal = true
|
|
|
|
|
|
|
|
|
|
const varFieldSet = new Set()
|
|
|
|
|
failedList.forEach(item => {
|
|
|
|
|
const varData = item.var_data || {}
|
|
|
|
|
Object.keys(varData).forEach(key => {
|
|
|
|
|
if (key !== 'email') {
|
|
|
|
|
varFieldSet.add(key)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
const varFields = Array.from(varFieldSet)
|
|
|
|
|
const headers = ['邮箱', '失败原因', '发送时间', ...varFields]
|
|
|
|
|
const rows = failedList.map(item => {
|
|
|
|
|
const varData = item.var_data || {}
|
|
|
|
|
return [
|
|
|
|
|
item.email != null ? String(item.email) : '',
|
|
|
|
|
item.reason || '',
|
|
|
|
|
item.send_time || '',
|
|
|
|
|
...varFields.map(field => (varData[field] != null ? String(varData[field]) : ''))
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const XLSX = require('xlsx')
|
|
|
|
|
const workbook = XLSX.utils.book_new()
|
|
|
|
|
const worksheet = XLSX.utils.aoa_to_sheet([headers, ...rows])
|
|
|
|
|
worksheet['!cols'] = headers.map((header, index) => ({
|
|
|
|
|
wch: index === 0 ? 28 : index === 1 ? 24 : 16
|
|
|
|
|
}))
|
|
|
|
|
XLSX.utils.book_append_sheet(workbook, worksheet, '发送失败')
|
|
|
|
|
|
|
|
|
|
const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' })
|
|
|
|
|
const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
|
|
|
|
|
const link = document.createElement('a')
|
|
|
|
|
const url = URL.createObjectURL(blob)
|
|
|
|
|
const safeSubject = (this.detailRecord.subject || '邮件记录').replace(/[\\/:*?"<>|]/g, '_').slice(0, 30)
|
|
|
|
|
|
|
|
|
|
link.setAttribute('href', url)
|
|
|
|
|
link.setAttribute('download', `发送失败_${safeSubject}_${new Date().toISOString().slice(0, 10)}.xlsx`)
|
|
|
|
|
link.style.visibility = 'hidden'
|
|
|
|
|
document.body.appendChild(link)
|
|
|
|
|
link.click()
|
|
|
|
|
document.body.removeChild(link)
|
|
|
|
|
URL.revokeObjectURL(url)
|
|
|
|
|
|
|
|
|
|
this.$message.success(`已导出 ${failedList.length} 条发送失败记录`)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 工具方法
|
|
|
|
|
@ -3856,6 +3949,23 @@ export default {
|
|
|
|
|
border-bottom: 2px solid #f0f0f0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.section-title-row {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
gap: 16px;
|
|
|
|
|
margin-bottom: 20px;
|
|
|
|
|
padding-bottom: 12px;
|
|
|
|
|
border-bottom: 2px solid #f0f0f0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.section-title-row .section-title {
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding-bottom: 0;
|
|
|
|
|
border-bottom: none;
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.section-title i {
|
|
|
|
|
color: #409EFF;
|
|
|
|
|
font-size: 20px;
|
|
|
|
|
|