better-staridc-MNBT
1<template>
2 <div class="td-page">
3 <div class="td-page-head">
4 <div>
5 <h3 class="td-page-title"><i class="mdi mdi-email-outline"></i>邮箱设置</h3>
6 <p class="td-page-subtitle">SMTP 发信参数,用于监控通知与系统邮件</p>
7 </div>
8 </div>
9
10 <div class="td-set-card">
11 <div class="td-set-card-hd">
12 <div class="td-set-icon"><i class="mdi mdi-email-outline"></i></div>
13 <div>
14 <h4>邮箱配置</h4>
15 <p>SMTP 发信参数</p>
16 </div>
17 </div>
18 <div class="td-set-card-bd">
19 <t-loading :loading="loading" text="保存中…" size="small">
20 <div class="td-form">
21 <div class="td-form-row">
22 <label>SMTP 服务器</label>
23 <t-input v-model="form.mailhost" placeholder="请输入邮箱服务器地址" clearable>
24 <template #prefix-icon><i class="mdi mdi-server-network"></i></template>
25 </t-input>
26 <div class="td-form-hint">例如 smtp.qq.com / smtp.163.com / smtp.gmail.com</div>
27 </div>
28
29 <div class="td-form-row">
30 <label>邮箱账号</label>
31 <t-input v-model="form.mailuser" placeholder="请输入邮箱账号" clearable>
32 <template #prefix-icon><i class="mdi mdi-email"></i></template>
33 </t-input>
34 </div>
35
36 <div class="td-form-row">
37 <label>邮箱密码 / 授权码</label>
38 <t-input
39 v-model="form.mailpassword"
40 placeholder="请输入邮箱密码或授权码"
41 clearable
42 >
43 <template #prefix-icon><i class="mdi mdi-lock"></i></template>
44 </t-input>
45 <div class="td-form-hint">部分邮箱服务商需使用授权码而非登录密码</div>
46 </div>
47
48 <div class="td-form-row">
49 <label>端口</label>
50 <t-input v-model="form.mailport" placeholder="请输入邮箱端口">
51 <template #prefix-icon><i class="mdi mdi-ethernet-cable"></i></template>
52 </t-input>
53 <div class="td-form-hint">常见: SSL 465 / TLS 587 / 明文 25</div>
54 </div>
55
56 <div class="td-form-note">
57 <b>提示:</b> 邮箱配置保存后将用于域名/文件监控通知、密码找回等场景。请确认邮箱已开启 SMTP 服务。
58 </div>
59
60 <div class="td-form-actions">
61 <t-button theme="primary" :loading="loading" @click="save">
62 <i class="mdi mdi-content-save-outline"></i> 保存修改
63 </t-button>
64 </div>
65 </div>
66 </t-loading>
67 </div>
68 </div>
69 </div>
70</template>
71
72<script setup>
73import { reactive, ref } from 'vue'
74import { MessagePlugin } from 'tdesign-vue-next'
75import { setMail } from '@/admin/api/settings'
76
77const boot = window.__TD_BOOT__ || {}
78const conf = boot.conf || {}
79const loading = ref(false)
80
81const form = reactive({
82 mailhost: conf.mailhost || '',
83 mailuser: conf.mailuser || '',
84 mailpassword: conf.mailpassword || '',
85 mailport: conf.mailport || '',
86})
87
88async function save() {
89 if (!form.mailhost || !form.mailuser || !form.mailpassword || !form.mailport) {
90 MessagePlugin.warning('请填写完整的邮箱配置')
91 return
92 }
93 loading.value = true
94 const r = await setMail({
95 host: form.mailhost,
96 user: form.mailuser,
97 password: form.mailpassword,
98 port: form.mailport,
99 })
100 loading.value = false
101 if (r.ok) MessagePlugin.success('保存成功')
102}
103</script>