统一暗色模式页面/顶栏/Handsontable 选中色,调整下单到仓方式文案与提示,CustomLeftMenu 卡片统一 60px;补充揽收单、问题件处理与 H5 相关页面。 Co-authored-by: Cursor <cursoragent@cursor.com>
1114 lines
31 KiB
Vue
1114 lines
31 KiB
Vue
<template>
|
||
<div class="batch-email-container">
|
||
<div class="batch-email-layout">
|
||
<div class="batch-email-left">
|
||
<div class="batch-email-card panel-card">
|
||
<div class="table-toolbar">
|
||
<div class="toolbar-left">
|
||
<a-space :size="8" wrap>
|
||
<span class="toolbar-label">{{ t('system.batchEmail.template') }}</span>
|
||
<a-select
|
||
v-model="selectedTemplateName"
|
||
:style="{ width: '220px' }"
|
||
:placeholder="t('system.batchEmail.selectTemplate')"
|
||
allow-clear
|
||
@change="onTemplateChange"
|
||
>
|
||
<a-option v-for="name in templateNames" :key="name" :value="name">{{ name }}</a-option>
|
||
</a-select>
|
||
<a-tag v-if="recipientCount > 0" color="arcoblue" class="recipient-tag">
|
||
{{ t('system.batchEmail.recipientCount', { n: recipientCount }) }}
|
||
</a-tag>
|
||
</a-space>
|
||
</div>
|
||
<div class="toolbar-right">
|
||
<a-button class="toolbar-btn" :loading="accountLoading" @click="openEmailConfigModal">
|
||
{{ t('system.batchEmail.emailConfig') }}
|
||
</a-button>
|
||
<a-button
|
||
class="toolbar-btn app-btn-toolbar"
|
||
:loading="sending"
|
||
:disabled="sending || recipientCount === 0"
|
||
@click="startBatchSend"
|
||
>
|
||
{{ t('system.batchEmail.send') }}
|
||
<template v-if="recipientCount > 0"> ({{ recipientCount }})</template>
|
||
</a-button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section-block recipient-section">
|
||
<div class="section-title">{{ t('system.batchEmail.recipients') }}</div>
|
||
<a-tabs v-model:active-key="recipientMode" type="rounded" size="small" class="recipient-tabs">
|
||
<a-tab-pane key="manual" :title="t('system.batchEmail.recipientMode.manual')">
|
||
<a-textarea
|
||
v-model="manualEmailsText"
|
||
:placeholder="t('system.batchEmail.manualEmailsPlaceholder')"
|
||
:auto-size="{ minRows: 6, maxRows: 12 }"
|
||
class="manual-email-textarea"
|
||
/>
|
||
</a-tab-pane>
|
||
<a-tab-pane key="excel" :title="t('system.batchEmail.recipientMode.excel')">
|
||
<div class="excel-import-panel">
|
||
<a-space :size="8" wrap>
|
||
<a-button class="toolbar-btn app-btn-toolbar" @click="triggerImport">
|
||
{{ t('system.batchEmail.import') }}
|
||
</a-button>
|
||
<span class="hint-text">{{ t('system.batchEmail.excelImportHint') }}</span>
|
||
</a-space>
|
||
</div>
|
||
</a-tab-pane>
|
||
</a-tabs>
|
||
|
||
<div v-if="recipientMode === 'excel' && recipientCount > 0" class="recipient-preview">
|
||
<div class="preview-header">
|
||
<span class="preview-title">{{ t('system.batchEmail.recipientPreview') }}</span>
|
||
<a-button type="text" size="small" @click="clearRecipients">
|
||
{{ t('system.batchEmail.clearRecipients') }}
|
||
</a-button>
|
||
</div>
|
||
<a-table
|
||
:columns="recipientColumns"
|
||
:data="recipientPreviewRows"
|
||
:pagination="false"
|
||
size="mini"
|
||
row-key="key"
|
||
class="recipient-preview-table"
|
||
/>
|
||
<div v-if="recipientCount > recipientPreviewLimit" class="preview-more">
|
||
{{ t('system.batchEmail.recipientPreviewMore', { n: recipientCount - recipientPreviewLimit }) }}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="section-block preview-section">
|
||
<div class="section-title">{{ t('system.batchEmail.preview') }}</div>
|
||
<div class="preview-toolbar">
|
||
<a-space :size="8" wrap>
|
||
<a-button class="toolbar-btn" @click="openSaveTemplateModal">{{ t('system.batchEmail.saveTpl') }}</a-button>
|
||
<a-button class="toolbar-btn" status="danger" @click="deleteCurrentTemplate">
|
||
{{ t('system.batchEmail.deleteTpl') }}
|
||
</a-button>
|
||
<span class="hint-text">{{ t('system.batchEmail.placeholderHint') }}</span>
|
||
</a-space>
|
||
</div>
|
||
<div class="subject-row">
|
||
<span class="subject-label">{{ t('system.batchEmail.subject') }}</span>
|
||
<a-input v-model="subjectDraft" :placeholder="t('system.batchEmail.subjectPlaceholder')" class="subject-input" />
|
||
</div>
|
||
<a-textarea
|
||
v-model="contentDraft"
|
||
:placeholder="t('system.batchEmail.contentPlaceholder')"
|
||
class="content-textarea"
|
||
/>
|
||
</div>
|
||
|
||
<input
|
||
ref="fileInputRef"
|
||
type="file"
|
||
accept=".xlsx,.xls"
|
||
class="file-input-hidden"
|
||
aria-hidden="true"
|
||
@change="onExcelSelected"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="batch-email-right">
|
||
<div class="batch-email-card panel-card record-card">
|
||
<div class="record-header">
|
||
<div class="section-title">{{ t('system.batchEmail.recordList') }}</div>
|
||
<PaginationPro
|
||
:total-count="recordTotal"
|
||
v-model:current-page="recordPage"
|
||
v-model:page-size="recordPageSize"
|
||
:page-sizes="[10, 30, 50, 100]"
|
||
@page-change="loadRecords"
|
||
@page-size-change="handleRecordPageSizeChange"
|
||
/>
|
||
</div>
|
||
<div class="list-wrap">
|
||
<a-table
|
||
:columns="recordColumns"
|
||
:data="recordList"
|
||
:loading="recordLoading"
|
||
:pagination="false"
|
||
:scroll="{ y: '100%' }"
|
||
row-key="id"
|
||
size="small"
|
||
class="record-table"
|
||
>
|
||
<template #content="{ record }">
|
||
<a-tooltip :content="record.content">
|
||
<span class="record-content-cell">{{ record.content }}</span>
|
||
</a-tooltip>
|
||
</template>
|
||
</a-table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<a-modal
|
||
v-model:visible="saveTplModalVisible"
|
||
:title="t('system.batchEmail.saveTplModalTitle')"
|
||
:ok-loading="saveTplLoading"
|
||
@before-ok="onBeforeSaveTemplateOk"
|
||
>
|
||
<a-input v-model="newTemplateName" :placeholder="t('system.batchEmail.saveTplNamePlaceholder')" />
|
||
</a-modal>
|
||
|
||
<a-modal
|
||
v-model:visible="emailConfigModalVisible"
|
||
:title="t('system.batchEmail.emailConfig')"
|
||
:width="520"
|
||
:footer="false"
|
||
unmount-on-close
|
||
>
|
||
<a-spin :loading="accountLoading" class="email-config-spin">
|
||
<a-form layout="vertical" class="email-config-form">
|
||
<a-form-item :label="t('system.batchEmail.account')" required>
|
||
<a-input v-model="accountUsername" allow-clear />
|
||
</a-form-item>
|
||
<a-form-item :label="t('system.batchEmail.password')" required>
|
||
<a-input-password
|
||
v-model="accountPassword"
|
||
:placeholder="accountPasswordPlaceholder"
|
||
allow-clear
|
||
/>
|
||
<div v-if="accountConfigured" class="hint-text password-hint">
|
||
{{ t('system.batchEmail.passwordSavedHint') }}
|
||
</div>
|
||
</a-form-item>
|
||
<a-form-item :label="t('system.batchEmail.serverType')">
|
||
<a-select v-model="serverType">
|
||
<a-option value="qiye">{{ t('system.batchEmail.server.qiye') }}</a-option>
|
||
<a-option value="qiye_ssl">{{ t('system.batchEmail.server.qiyeSsl') }}</a-option>
|
||
<a-option value="aliyun">{{ t('system.batchEmail.server.aliyun') }}</a-option>
|
||
<a-option value="aliyun_ssl">{{ t('system.batchEmail.server.aliyunSsl') }}</a-option>
|
||
<a-option value="mxhichina">{{ t('system.batchEmail.server.mxhichina') }}</a-option>
|
||
</a-select>
|
||
</a-form-item>
|
||
</a-form>
|
||
<div class="email-config-footer">
|
||
<a-space :size="8">
|
||
<a-button class="toolbar-btn" @click="emailConfigModalVisible = false">
|
||
{{ t('system.batchEmail.confirmCancel') }}
|
||
</a-button>
|
||
<a-button class="toolbar-btn" :loading="testing" @click="testConnection">
|
||
{{ t('system.batchEmail.testConnection') }}
|
||
</a-button>
|
||
<a-button type="primary" class="toolbar-btn" :loading="savingConfig" @click="saveAccountConfigFromModal">
|
||
{{ t('system.batchEmail.saveConfig') }}
|
||
</a-button>
|
||
</a-space>
|
||
</div>
|
||
</a-spin>
|
||
</a-modal>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
defineOptions({ name: 'SystemBatchEmail' })
|
||
import { computed, onMounted, ref } from 'vue'
|
||
import { useI18n } from 'vue-i18n'
|
||
import * as XLSX from 'xlsx'
|
||
import dayjs from 'dayjs'
|
||
import { Message, Modal } from '@arco-design/web-vue'
|
||
import PaginationPro from '@/components/PaginationPro/index.vue'
|
||
import {
|
||
deleteBatchEmailTemplate,
|
||
getBatchEmailAccount,
|
||
isSmtpSecretMask,
|
||
listBatchEmailRecords,
|
||
listBatchEmailTemplates,
|
||
saveBatchEmailAccount,
|
||
saveBatchEmailTemplate,
|
||
sendBatchEmailOne,
|
||
SMTP_SECRET_MASK,
|
||
testBatchEmailConnection,
|
||
type BatchEmailSendRecord,
|
||
type BatchEmailServerType,
|
||
} from '@/api/system/batchEmail'
|
||
|
||
const { t } = useI18n()
|
||
|
||
interface OrderRow {
|
||
客户单号: string
|
||
最新轨迹: string
|
||
换单号: string
|
||
寄件人邮箱: string
|
||
}
|
||
|
||
interface TemplateData {
|
||
content: string
|
||
subject: string
|
||
}
|
||
|
||
const DEFAULT_TEMPLATE_NAME = '默认模板'
|
||
const DEFAULT_TEMPLATE: TemplateData = {
|
||
subject: '订单通知 - {客户单号}',
|
||
content: `尊敬的客户:您好!
|
||
|
||
感谢您选择阿里巴巴及我们的物流服务,衷心感谢您的信任与支持!
|
||
|
||
|
||
|
||
您的订单{客户单号},最新物流轨迹显示:{最新轨迹}。为避免包裹滞留或退回,烦请您及时联系收件人核实以下信息:
|
||
|
||
|
||
|
||
1.收件地址是否准确、完整(含邮编、门牌号等);
|
||
|
||
2.收件人联系方式是否畅通;
|
||
|
||
3.是否需协调二次派送时间。
|
||
|
||
|
||
|
||
后续如有物流疑问,可随时通过平台客服联系我们,我们将全力协助处理!
|
||
|
||
顺祝商祺!
|
||
|
||
|
||
|
||
Alibaba.com Logistics
|
||
|
||
一代国际深圳仓客户服务中心`,
|
||
}
|
||
|
||
const EMAIL_SPLIT_RE = /[\n,;,;\s]+/
|
||
const EMAIL_VALID_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||
|
||
const fileInputRef = ref<HTMLInputElement | null>(null)
|
||
const orderData = ref<OrderRow[]>([])
|
||
const recipientMode = ref<'manual' | 'excel'>('manual')
|
||
const manualEmailsText = ref('')
|
||
const templates = ref<Record<string, TemplateData>>({})
|
||
const selectedTemplateName = ref<string>('')
|
||
const contentDraft = ref('')
|
||
const subjectDraft = ref('')
|
||
const accountUsername = ref('')
|
||
const accountPassword = ref('')
|
||
const accountConfigured = ref(false)
|
||
const serverType = ref<BatchEmailServerType>('qiye')
|
||
const sending = ref(false)
|
||
const testing = ref(false)
|
||
const savingConfig = ref(false)
|
||
const accountLoading = ref(false)
|
||
const emailConfigModalVisible = ref(false)
|
||
|
||
const saveTplModalVisible = ref(false)
|
||
const newTemplateName = ref('')
|
||
const saveTplLoading = ref(false)
|
||
|
||
const recordList = ref<BatchEmailSendRecord[]>([])
|
||
const recordTotal = ref(0)
|
||
const recordPage = ref(1)
|
||
const recordPageSize = ref(30)
|
||
const recordLoading = ref(false)
|
||
const recipientPreviewLimit = 8
|
||
|
||
const templateNames = computed(() => Object.keys(templates.value))
|
||
|
||
const accountPasswordPlaceholder = computed(() =>
|
||
accountConfigured.value
|
||
? t('system.batchEmail.passwordPlaceholderEdit')
|
||
: t('system.batchEmail.passwordPlaceholder'),
|
||
)
|
||
|
||
const recipientCount = computed(() => {
|
||
if (recipientMode.value === 'manual') {
|
||
return parseEmailTokens(manualEmailsText.value).valid.length
|
||
}
|
||
return orderData.value.length
|
||
})
|
||
|
||
const recipientColumns = computed(() => [
|
||
{ title: t('system.batchEmail.record.toEmail'), dataIndex: 'email', ellipsis: true, tooltip: true },
|
||
{ title: t('system.batchEmail.previewOrderNo'), dataIndex: 'orderNo', width: 140, ellipsis: true, tooltip: true },
|
||
{ title: t('system.batchEmail.previewTrack'), dataIndex: 'track', ellipsis: true, tooltip: true },
|
||
])
|
||
|
||
const recipientPreviewRows = computed(() =>
|
||
orderData.value.slice(0, recipientPreviewLimit).map((row, index) => ({
|
||
key: `${row.寄件人邮箱}-${index}`,
|
||
email: row.寄件人邮箱,
|
||
orderNo: row.客户单号 || '-',
|
||
track: row.最新轨迹 || '-',
|
||
})),
|
||
)
|
||
|
||
const recordColumns = computed(() => [
|
||
{ title: t('system.batchEmail.record.toEmail'), dataIndex: 'toEmail', width: 160, ellipsis: true, tooltip: true },
|
||
{ title: t('system.batchEmail.record.subject'), dataIndex: 'subject', width: 140, ellipsis: true, tooltip: true },
|
||
{ title: t('system.batchEmail.record.content'), dataIndex: 'content', slotName: 'content', ellipsis: true },
|
||
{ title: t('system.batchEmail.record.sendTime'), dataIndex: 'sendTime', width: 160 },
|
||
{ title: t('system.batchEmail.record.sender'), dataIndex: 'sender', width: 100, ellipsis: true, tooltip: true },
|
||
])
|
||
|
||
function templatesToMap(list: Array<{ name: string; subject: string; content: string }>): Record<string, TemplateData> {
|
||
const out: Record<string, TemplateData> = {}
|
||
list.forEach((item) => {
|
||
out[item.name] = { subject: item.subject, content: item.content }
|
||
})
|
||
return out
|
||
}
|
||
|
||
function parseEmailTokens(text: string) {
|
||
const tokens = text
|
||
.split(EMAIL_SPLIT_RE)
|
||
.map((item) => item.trim())
|
||
.filter(Boolean)
|
||
const valid: string[] = []
|
||
const seen = new Set<string>()
|
||
let invalid = 0
|
||
tokens.forEach((token) => {
|
||
if (!EMAIL_VALID_RE.test(token)) {
|
||
invalid += 1
|
||
return
|
||
}
|
||
const key = token.toLowerCase()
|
||
if (seen.has(key)) return
|
||
seen.add(key)
|
||
valid.push(token)
|
||
})
|
||
return { valid, invalid }
|
||
}
|
||
|
||
function buildOrderRowsFromEmails(emails: string[]): OrderRow[] {
|
||
return emails.map((email) => ({
|
||
客户单号: '',
|
||
最新轨迹: '',
|
||
换单号: '',
|
||
寄件人邮箱: email,
|
||
}))
|
||
}
|
||
|
||
function getRecipientsForSend(): OrderRow[] {
|
||
if (recipientMode.value === 'manual') {
|
||
return buildOrderRowsFromEmails(parseEmailTokens(manualEmailsText.value).valid)
|
||
}
|
||
return orderData.value
|
||
}
|
||
|
||
function clearRecipients() {
|
||
orderData.value = []
|
||
manualEmailsText.value = ''
|
||
}
|
||
|
||
async function loadTemplatesFromApi() {
|
||
try {
|
||
const list = await listBatchEmailTemplates()
|
||
templates.value = templatesToMap(list)
|
||
if (!Object.keys(templates.value).length) {
|
||
templates.value = { [DEFAULT_TEMPLATE_NAME]: { ...DEFAULT_TEMPLATE } }
|
||
}
|
||
} catch (e: unknown) {
|
||
const msg = (e as Error)?.message || t('system.batchEmail.errUnknown')
|
||
Message.error(`${t('system.batchEmail.errLoadTemplates')}: ${msg}`)
|
||
templates.value = { [DEFAULT_TEMPLATE_NAME]: { ...DEFAULT_TEMPLATE } }
|
||
}
|
||
}
|
||
|
||
async function loadAccountFromApi() {
|
||
accountLoading.value = true
|
||
try {
|
||
const account = await getBatchEmailAccount()
|
||
if (!account) {
|
||
accountConfigured.value = false
|
||
accountUsername.value = ''
|
||
accountPassword.value = ''
|
||
serverType.value = 'qiye'
|
||
return
|
||
}
|
||
accountConfigured.value = true
|
||
accountUsername.value = account.smtpUsername
|
||
accountPassword.value = account.smtpPassword || SMTP_SECRET_MASK
|
||
if (account.serverType) serverType.value = account.serverType
|
||
} catch (e: unknown) {
|
||
const msg = (e as Error)?.message || t('system.batchEmail.errUnknown')
|
||
Message.error(msg)
|
||
} finally {
|
||
accountLoading.value = false
|
||
}
|
||
}
|
||
|
||
function resolvePasswordForRequest(): string {
|
||
const trimmed = accountPassword.value.trim()
|
||
if (trimmed && !isSmtpSecretMask(trimmed)) return trimmed
|
||
if (accountConfigured.value) return SMTP_SECRET_MASK
|
||
return trimmed
|
||
}
|
||
|
||
function hasUsableSmtpAuth(): boolean {
|
||
if (!accountUsername.value.trim()) return false
|
||
const trimmed = accountPassword.value.trim()
|
||
if (trimmed && !isSmtpSecretMask(trimmed)) return true
|
||
return accountConfigured.value
|
||
}
|
||
|
||
async function openEmailConfigModal() {
|
||
emailConfigModalVisible.value = true
|
||
await loadAccountFromApi()
|
||
}
|
||
|
||
function formatSendTime(value?: string) {
|
||
if (!value) return '-'
|
||
const parsed = dayjs(value)
|
||
return parsed.isValid() ? parsed.format('YYYY-MM-DD HH:mm:ss') : value
|
||
}
|
||
|
||
async function loadRecords() {
|
||
recordLoading.value = true
|
||
try {
|
||
const { items, total } = await listBatchEmailRecords({
|
||
page: recordPage.value,
|
||
pageSize: recordPageSize.value,
|
||
})
|
||
recordList.value = items.map((item) => ({
|
||
...item,
|
||
sendTime: formatSendTime(item.sendTime),
|
||
}))
|
||
recordTotal.value = total
|
||
} catch (e: unknown) {
|
||
Message.error((e as Error)?.message || t('system.batchEmail.errLoadRecords'))
|
||
} finally {
|
||
recordLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleRecordPageSizeChange(size: number) {
|
||
recordPageSize.value = size
|
||
recordPage.value = 1
|
||
loadRecords()
|
||
}
|
||
|
||
function applyTemplateByName(name: string | undefined) {
|
||
if (!name || !templates.value[name]) return
|
||
const tpl = templates.value[name]
|
||
contentDraft.value = tpl.content
|
||
subjectDraft.value = tpl.subject
|
||
}
|
||
|
||
function onTemplateChange(name: string | undefined) {
|
||
applyTemplateByName(name)
|
||
}
|
||
|
||
function triggerImport() {
|
||
fileInputRef.value?.click()
|
||
}
|
||
|
||
function detectColumns(rows: Record<string, unknown>[]) {
|
||
if (!rows.length) return { orderIdCol: null as string | null, trackCol: null as string | null, emailCol: null as string | null, changeCol: null as string | null }
|
||
const cols = Object.keys(rows[0])
|
||
let orderIdCol: string | null = null
|
||
let trackCol: string | null = null
|
||
let emailCol: string | null = null
|
||
let changeCol: string | null = null
|
||
for (const col of cols) {
|
||
const lower = String(col).toLowerCase()
|
||
if (orderIdCol == null && (String(col).includes('单号') || String(col).includes('订单') || lower.includes('order'))) {
|
||
orderIdCol = col
|
||
}
|
||
}
|
||
for (const col of cols) {
|
||
const lower = String(col).toLowerCase()
|
||
if (trackCol == null && (String(col).includes('轨迹') || lower.includes('track') || String(col).includes('物流'))) {
|
||
trackCol = col
|
||
}
|
||
}
|
||
for (const col of cols) {
|
||
const lower = String(col).toLowerCase()
|
||
if (
|
||
emailCol == null &&
|
||
(String(col).includes('邮箱') || lower.includes('email') || lower.includes('mail') || String(col).includes('寄件人'))
|
||
) {
|
||
emailCol = col
|
||
}
|
||
}
|
||
for (const col of cols) {
|
||
if (String(col).trim() === '换单号') {
|
||
changeCol = col
|
||
break
|
||
}
|
||
}
|
||
return { orderIdCol, trackCol, emailCol, changeCol }
|
||
}
|
||
|
||
function onExcelSelected(ev: Event) {
|
||
const input = ev.target as HTMLInputElement
|
||
const file = input.files?.[0]
|
||
input.value = ''
|
||
if (!file) return
|
||
|
||
const reader = new FileReader()
|
||
reader.onload = (e) => {
|
||
try {
|
||
const data = new Uint8Array(e.target?.result as ArrayBuffer)
|
||
const workbook = XLSX.read(data, { type: 'array' })
|
||
const sheetName = workbook.SheetNames[0]
|
||
const worksheet = workbook.Sheets[sheetName]
|
||
const jsonData = XLSX.utils.sheet_to_json<Record<string, unknown>>(worksheet)
|
||
const { orderIdCol, trackCol, emailCol, changeCol } = detectColumns(jsonData)
|
||
|
||
if (!orderIdCol || !emailCol) {
|
||
Message.error(t('system.batchEmail.errMissingColumns'))
|
||
return
|
||
}
|
||
|
||
const list: OrderRow[] = []
|
||
jsonData.forEach((row) => {
|
||
const emailRaw = row[emailCol!]
|
||
const email = emailRaw != null && emailRaw !== '' ? String(emailRaw).trim() : ''
|
||
if (!email || !email.includes('@')) return
|
||
const order: OrderRow = {
|
||
客户单号: row[orderIdCol!] != null && row[orderIdCol!] !== '' ? String(row[orderIdCol!]) : '',
|
||
最新轨迹:
|
||
trackCol && row[trackCol] != null && row[trackCol] !== '' ? String(row[trackCol]) : '',
|
||
换单号:
|
||
changeCol && row[changeCol] != null && row[changeCol] !== '' ? String(row[changeCol]) : '',
|
||
寄件人邮箱: email,
|
||
}
|
||
list.push(order)
|
||
})
|
||
|
||
orderData.value = list
|
||
recipientMode.value = 'excel'
|
||
Message.success(t('system.batchEmail.msgImportOk', { n: list.length }))
|
||
} catch (err) {
|
||
const msg = err instanceof Error ? err.message : String(err)
|
||
Message.error(msg)
|
||
}
|
||
}
|
||
reader.readAsArrayBuffer(file)
|
||
}
|
||
|
||
function fillPlaceholders(text: string, order: OrderRow): string {
|
||
if (!text) return ''
|
||
return text
|
||
.replaceAll('{客户单号}', order.客户单号)
|
||
.replaceAll('{最新轨迹}', order.最新轨迹)
|
||
.replaceAll('{换单号}', order.换单号)
|
||
}
|
||
|
||
function openSaveTemplateModal() {
|
||
const c = contentDraft.value.trim()
|
||
if (!c) {
|
||
Message.warning(t('system.batchEmail.warnEmptyContent'))
|
||
return
|
||
}
|
||
newTemplateName.value = selectedTemplateName.value || ''
|
||
saveTplModalVisible.value = true
|
||
}
|
||
|
||
async function doSaveTemplate(name: string, content: string) {
|
||
saveTplLoading.value = true
|
||
try {
|
||
const subj = subjectDraft.value.trim() || name
|
||
await saveBatchEmailTemplate({ name, subject: subj, content })
|
||
templates.value = {
|
||
...templates.value,
|
||
[name]: { content, subject: subj },
|
||
}
|
||
selectedTemplateName.value = name
|
||
Message.success(t('system.batchEmail.msgSaveTplOk', { name }))
|
||
saveTplModalVisible.value = false
|
||
} finally {
|
||
saveTplLoading.value = false
|
||
}
|
||
}
|
||
|
||
/** Arco Modal before-ok:返回 false 阻止关闭 */
|
||
async function onBeforeSaveTemplateOk(): Promise<boolean> {
|
||
const content = contentDraft.value.trim()
|
||
const name = newTemplateName.value.trim()
|
||
if (!content) {
|
||
Message.warning(t('system.batchEmail.warnEmptyContent'))
|
||
return false
|
||
}
|
||
if (!name) {
|
||
Message.warning(t('system.batchEmail.warnEmptyName'))
|
||
return false
|
||
}
|
||
if (templates.value[name] && name !== selectedTemplateName.value) {
|
||
return new Promise((resolve) => {
|
||
Modal.confirm({
|
||
title: t('system.batchEmail.confirmOverwriteTitle'),
|
||
content: t('system.batchEmail.confirmOverwriteBody', { name }),
|
||
okText: t('system.batchEmail.confirmOk'),
|
||
cancelText: t('system.batchEmail.confirmCancel'),
|
||
onOk: async () => {
|
||
await doSaveTemplate(name, content)
|
||
resolve(true)
|
||
},
|
||
onCancel: () => resolve(false),
|
||
})
|
||
})
|
||
}
|
||
await doSaveTemplate(name, content)
|
||
return true
|
||
}
|
||
|
||
function deleteCurrentTemplate() {
|
||
const name = selectedTemplateName.value
|
||
if (!name) {
|
||
Message.warning(t('system.batchEmail.warnSelectTplDelete'))
|
||
return
|
||
}
|
||
if (!templates.value[name]) {
|
||
Message.warning(t('system.batchEmail.warnTplMissing'))
|
||
return
|
||
}
|
||
Modal.confirm({
|
||
title: t('system.batchEmail.confirmDeleteTitle'),
|
||
content: t('system.batchEmail.confirmDeleteBody', { name }),
|
||
okText: t('system.batchEmail.confirmOk'),
|
||
cancelText: t('system.batchEmail.confirmCancel'),
|
||
onOk: async () => {
|
||
try {
|
||
await deleteBatchEmailTemplate({ name })
|
||
await loadTemplatesFromApi()
|
||
const keys = Object.keys(templates.value)
|
||
selectedTemplateName.value = keys[0] ?? ''
|
||
applyTemplateByName(keys[0])
|
||
Message.success(t('system.batchEmail.msgDeleteTplOk', { name }))
|
||
} catch (e: unknown) {
|
||
const msg = (e as Error)?.message || t('system.batchEmail.errUnknown')
|
||
Message.error(msg)
|
||
}
|
||
},
|
||
})
|
||
}
|
||
|
||
async function saveAccountConfig() {
|
||
const u = accountUsername.value.trim()
|
||
const p = resolvePasswordForRequest()
|
||
if (!u) {
|
||
Message.warning(t('system.batchEmail.warnAccount'))
|
||
return false
|
||
}
|
||
if (!accountConfigured.value && (!p || isSmtpSecretMask(p))) {
|
||
Message.warning(t('system.batchEmail.warnPassword'))
|
||
return false
|
||
}
|
||
try {
|
||
await saveBatchEmailAccount({
|
||
smtpUsername: u,
|
||
smtpPassword: p || SMTP_SECRET_MASK,
|
||
serverType: serverType.value,
|
||
})
|
||
accountConfigured.value = true
|
||
if (!accountPassword.value.trim() || isSmtpSecretMask(accountPassword.value)) {
|
||
accountPassword.value = SMTP_SECRET_MASK
|
||
}
|
||
Message.success(t('system.batchEmail.msgSaveConfigOk'))
|
||
return true
|
||
} catch (e: unknown) {
|
||
const msg = (e as Error)?.message || t('system.batchEmail.errUnknown')
|
||
Message.error(msg)
|
||
return false
|
||
}
|
||
}
|
||
|
||
async function saveAccountConfigFromModal() {
|
||
savingConfig.value = true
|
||
try {
|
||
const ok = await saveAccountConfig()
|
||
if (ok) emailConfigModalVisible.value = false
|
||
} finally {
|
||
savingConfig.value = false
|
||
}
|
||
}
|
||
|
||
async function testConnection() {
|
||
if (!hasUsableSmtpAuth()) {
|
||
Message.warning(t('system.batchEmail.warnAccount'))
|
||
return
|
||
}
|
||
testing.value = true
|
||
try {
|
||
await testBatchEmailConnection({
|
||
smtpUsername: accountUsername.value.trim(),
|
||
smtpPassword: resolvePasswordForRequest(),
|
||
serverType: serverType.value,
|
||
})
|
||
Message.success(t('system.batchEmail.msgTestOk'))
|
||
} catch (e: unknown) {
|
||
const msg =
|
||
(e as { response?: { data?: { msg?: string; Msg?: string; message?: string } } })?.response?.data?.msg ??
|
||
(e as { response?: { data?: { Msg?: string } } })?.response?.data?.Msg ??
|
||
(e as Error)?.message ??
|
||
t('system.batchEmail.errUnknown')
|
||
Message.error(msg)
|
||
} finally {
|
||
testing.value = false
|
||
}
|
||
}
|
||
|
||
function ensureRecipientsReady(): boolean {
|
||
if (!getRecipientsForSend().length) {
|
||
Message.warning(t('system.batchEmail.warnNoRecipients'))
|
||
return false
|
||
}
|
||
return true
|
||
}
|
||
|
||
async function startBatchSend() {
|
||
if (!ensureRecipientsReady()) return
|
||
const recipients = getRecipientsForSend()
|
||
const bodyContent = contentDraft.value.trim()
|
||
if (!bodyContent) {
|
||
Message.warning(t('system.batchEmail.warnNoTemplate'))
|
||
return
|
||
}
|
||
const u = accountUsername.value.trim()
|
||
if (!hasUsableSmtpAuth()) {
|
||
Message.error(t('system.batchEmail.errNoAccount'))
|
||
return
|
||
}
|
||
const p = resolvePasswordForRequest()
|
||
|
||
sending.value = true
|
||
let successCount = 0
|
||
let failCount = 0
|
||
|
||
for (let i = 0; i < recipients.length; i += 1) {
|
||
const order = recipients[i]
|
||
const email = order.寄件人邮箱?.trim() ?? ''
|
||
try {
|
||
if (!email || !email.includes('@')) {
|
||
failCount += 1
|
||
continue
|
||
}
|
||
const body = fillPlaceholders(bodyContent, order)
|
||
if (!body) {
|
||
failCount += 1
|
||
continue
|
||
}
|
||
const subjBase = subjectDraft.value.trim() || selectedTemplateName.value || t('system.batchEmail.fallbackSubject')
|
||
const subject = fillPlaceholders(subjBase, order)
|
||
await sendBatchEmailOne({
|
||
smtpUsername: u,
|
||
smtpPassword: p,
|
||
serverType: serverType.value,
|
||
to: email,
|
||
subject,
|
||
body,
|
||
bodyType: 'plain',
|
||
})
|
||
successCount += 1
|
||
} catch {
|
||
failCount += 1
|
||
}
|
||
}
|
||
|
||
await loadRecords()
|
||
Message.info(t('system.batchEmail.msgSendDone', { successCount, failCount }))
|
||
sending.value = false
|
||
}
|
||
|
||
onMounted(async () => {
|
||
await Promise.all([loadTemplatesFromApi(), loadAccountFromApi(), loadRecords()])
|
||
const names = templateNames.value
|
||
if (names.length) {
|
||
selectedTemplateName.value = names[0]
|
||
applyTemplateByName(names[0])
|
||
}
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="less">
|
||
.batch-email-container {
|
||
width: 100%;
|
||
box-sizing: border-box;
|
||
padding: 16px 16px 24px;
|
||
background-color: var(--app-page-bg);
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.batch-email-layout {
|
||
display: flex;
|
||
gap: 16px;
|
||
flex: 1;
|
||
min-height: 0;
|
||
align-items: stretch;
|
||
}
|
||
|
||
.batch-email-left {
|
||
flex: 1 1 54%;
|
||
min-width: 480px;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.batch-email-right {
|
||
flex: 1 1 46%;
|
||
min-width: 400px;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.panel-card {
|
||
flex: 1;
|
||
min-height: 0;
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.batch-email-card {
|
||
background: var(--app-card-bg);
|
||
border-radius: 8px;
|
||
padding: 0 0 16px;
|
||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.record-card {
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.recipient-section {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.preview-section {
|
||
flex: 1;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: auto;
|
||
}
|
||
|
||
.record-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
gap: 8px;
|
||
padding: 16px 16px 0;
|
||
margin-bottom: 16px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.list-wrap {
|
||
flex: 1;
|
||
min-height: 0;
|
||
padding: 0 16px 16px;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
.record-table {
|
||
flex: 1;
|
||
min-height: 0;
|
||
|
||
:deep(.arco-table) {
|
||
height: 100%;
|
||
}
|
||
|
||
:deep(.arco-table-container) {
|
||
height: 100%;
|
||
}
|
||
}
|
||
|
||
.record-content-cell {
|
||
display: inline-block;
|
||
max-width: 100%;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.table-toolbar {
|
||
padding: 16px 16px 0;
|
||
margin-bottom: 16px;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.toolbar-left,
|
||
.toolbar-right {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
.toolbar-label {
|
||
font-size: 14px;
|
||
color: var(--color-text-1);
|
||
}
|
||
|
||
.recipient-tag {
|
||
margin-left: 4px;
|
||
}
|
||
|
||
.toolbar-btn {
|
||
height: 32px;
|
||
border-radius: 4px;
|
||
}
|
||
|
||
.file-input-hidden {
|
||
position: fixed;
|
||
left: -100px;
|
||
top: 0;
|
||
width: 1px;
|
||
height: 1px;
|
||
opacity: 0;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.section-block {
|
||
padding: 0 16px;
|
||
margin-bottom: 16px;
|
||
}
|
||
|
||
.section-title {
|
||
font-size: 14px;
|
||
font-weight: 500;
|
||
color: var(--color-text-1);
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.recipient-tabs {
|
||
:deep(.arco-tabs-content) {
|
||
padding-top: 12px;
|
||
}
|
||
}
|
||
|
||
.manual-email-textarea {
|
||
:deep(textarea) {
|
||
font-family: inherit;
|
||
}
|
||
}
|
||
|
||
.excel-import-panel {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
.recipient-preview {
|
||
margin-top: 12px;
|
||
padding: 12px;
|
||
background: var(--color-fill-2);
|
||
border-radius: 4px;
|
||
}
|
||
|
||
.preview-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.preview-title {
|
||
font-size: 13px;
|
||
color: var(--color-text-2);
|
||
font-weight: 500;
|
||
}
|
||
|
||
.preview-more {
|
||
margin-top: 8px;
|
||
font-size: 12px;
|
||
color: var(--color-text-3);
|
||
}
|
||
|
||
.recipient-preview-table {
|
||
:deep(.arco-table-th) {
|
||
background: var(--color-fill-2);
|
||
}
|
||
}
|
||
|
||
.preview-toolbar {
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.hint-text {
|
||
font-size: 13px;
|
||
color: var(--color-text-3);
|
||
}
|
||
|
||
.warn-text {
|
||
color: rgb(var(--orange-6));
|
||
}
|
||
|
||
.content-textarea {
|
||
margin-top: 4px;
|
||
flex: 1;
|
||
min-height: 140px;
|
||
|
||
:deep(textarea) {
|
||
height: 100% !important;
|
||
min-height: 140px;
|
||
}
|
||
}
|
||
|
||
.password-hint {
|
||
margin-top: 4px;
|
||
}
|
||
|
||
.email-config-spin {
|
||
display: block;
|
||
width: 100%;
|
||
}
|
||
|
||
.email-config-form {
|
||
:deep(.arco-form-item) {
|
||
margin-bottom: 16px;
|
||
}
|
||
}
|
||
|
||
.email-config-footer {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
padding-top: 8px;
|
||
border-top: 1px solid var(--color-border-2);
|
||
}
|
||
|
||
.subject-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
margin-bottom: 8px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.subject-label {
|
||
flex: 0 0 72px;
|
||
font-size: 14px;
|
||
color: var(--color-text-1);
|
||
}
|
||
|
||
.subject-input {
|
||
flex: 1;
|
||
min-width: 240px;
|
||
}
|
||
|
||
@media (max-width: 1200px) {
|
||
.batch-email-layout {
|
||
flex-direction: column;
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.batch-email-left,
|
||
.batch-email-right {
|
||
min-width: 0;
|
||
flex: none;
|
||
min-height: 480px;
|
||
}
|
||
}
|
||
</style>
|