|
| 1 | +<script setup lang='ts'> |
| 2 | +import { onMounted, ref } from 'vue' |
| 3 | +import { NButton, NInput, NSpin, useMessage } from 'naive-ui' |
| 4 | +import type { ConfigState, MailConfig } from './model' |
| 5 | +import { fetchChatConfig, fetchUpdateMail } from '@/api' |
| 6 | +import { t } from '@/locales' |
| 7 | +
|
| 8 | +const ms = useMessage() |
| 9 | +
|
| 10 | +const loading = ref(false) |
| 11 | +
|
| 12 | +const config = ref<MailConfig>() |
| 13 | +
|
| 14 | +async function fetchConfig() { |
| 15 | + try { |
| 16 | + loading.value = true |
| 17 | + const { data } = await fetchChatConfig<ConfigState>() |
| 18 | + config.value = data.mailConfig |
| 19 | + } |
| 20 | + finally { |
| 21 | + loading.value = false |
| 22 | + } |
| 23 | +} |
| 24 | +
|
| 25 | +async function updateMailInfo(mail?: MailConfig) { |
| 26 | + if (!mail) |
| 27 | + return |
| 28 | +
|
| 29 | + const { data } = await fetchUpdateMail(mail) |
| 30 | + config.value = data |
| 31 | + ms.success(t('common.success')) |
| 32 | +} |
| 33 | +
|
| 34 | +onMounted(() => { |
| 35 | + fetchConfig() |
| 36 | +}) |
| 37 | +</script> |
| 38 | + |
| 39 | +<template> |
| 40 | + <NSpin :show="loading"> |
| 41 | + <div class="p-4 space-y-5 min-h-[200px]"> |
| 42 | + <div class="space-y-6"> |
| 43 | + <div class="flex items-center space-x-4"> |
| 44 | + <span class="flex-shrink-0 w-[100px]">{{ $t('setting.smtpHost') }}</span> |
| 45 | + <div class="flex-1"> |
| 46 | + <NInput |
| 47 | + :value="config && config.smtpHost" placeholder="" |
| 48 | + @input="(val) => { if (config) config.smtpHost = val }" |
| 49 | + /> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + <div class="flex items-center space-x-4"> |
| 53 | + <span class="flex-shrink-0 w-[100px]">{{ $t('setting.smtpPort') }}</span> |
| 54 | + <div class="flex-1"> |
| 55 | + <NInput |
| 56 | + :value="config && config.smtpPort !== undefined ? String(config.smtpPort) : undefined" |
| 57 | + placeholder="" |
| 58 | + @input="(val) => { if (config) config.smtpPort = typeof val === 'string' ? Number(val) : undefined }" |
| 59 | + /> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + <div class="flex items-center space-x-4"> |
| 63 | + <span class="flex-shrink-0 w-[100px]">{{ $t('setting.smtpTsl') }}</span> |
| 64 | + <div class="flex-1"> |
| 65 | + <NInput |
| 66 | + :value="config && config.smtpTsl !== undefined ? String(config.smtpTsl) : undefined" |
| 67 | + placeholder="" |
| 68 | + @input="(val) => { if (config) config.smtpTsl = typeof val === 'string' ? Boolean(val) : undefined }" |
| 69 | + /> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + <div class="flex items-center space-x-4"> |
| 73 | + <span class="flex-shrink-0 w-[100px]">{{ $t('setting.smtpUserName') }}</span> |
| 74 | + <div class="flex-1"> |
| 75 | + <NInput |
| 76 | + :value="config && config.smtpUserName" placeholder="" |
| 77 | + @input="(val) => { if (config) config.smtpUserName = val }" |
| 78 | + /> |
| 79 | + </div> |
| 80 | + </div> |
| 81 | + <div class="flex items-center space-x-4"> |
| 82 | + <span class="flex-shrink-0 w-[100px]">{{ $t('setting.smtpPassword') }}</span> |
| 83 | + <div class="flex-1"> |
| 84 | + <NInput |
| 85 | + :value="config && config.smtpPassword" placeholder="" |
| 86 | + @input="(val) => { if (config) config.smtpPassword = val }" |
| 87 | + /> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + <div class="flex items-center space-x-4"> |
| 91 | + <span class="flex-shrink-0 w-[100px]" /> |
| 92 | + <NButton type="primary" @click="updateMailInfo(config)"> |
| 93 | + {{ $t('common.save') }} |
| 94 | + </NButton> |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + </NSpin> |
| 99 | +</template> |
0 commit comments