Ver código fonte

feat:【system】邮箱管理的开发:100%
feat:【system】短信管理的开发:修复 todo

YunaiV 4 meses atrás
pai
commit
6c3b86666d

+ 6 - 0
src/api/system/mail/account/index.ts

@@ -14,26 +14,32 @@ export interface MailAccount {
   createTime?: string
 }
 
+/** 获取邮箱账号分页列表 */
 export function getMailAccountPage(params: PageParam) {
   return http.get<PageResult<MailAccount>>('/system/mail-account/page', params)
 }
 
+/** 获取邮箱账号(精简)列表 */
 export function getSimpleMailAccountList() {
   return http.get<MailAccount[]>('/system/mail-account/simple-list')
 }
 
+/** 获取邮箱账号详情 */
 export function getMailAccount(id: number) {
   return http.get<MailAccount>(`/system/mail-account/get?id=${id}`)
 }
 
+/** 创建邮箱账号 */
 export function createMailAccount(data: MailAccount) {
   return http.post<number>('/system/mail-account/create', data)
 }
 
+/** 更新邮箱账号 */
 export function updateMailAccount(data: MailAccount) {
   return http.put<boolean>('/system/mail-account/update', data)
 }
 
+/** 删除邮箱账号 */
 export function deleteMailAccount(id: number) {
   return http.delete<boolean>(`/system/mail-account/delete?id=${id}`)
 }

+ 6 - 0
src/api/system/mail/log/index.ts

@@ -23,6 +23,12 @@ export interface MailLog {
   createTime?: string
 }
 
+/** 获取邮件日志分页列表 */
 export function getMailLogPage(params: PageParam) {
   return http.get<PageResult<MailLog>>('/system/mail-log/page', params)
 }
+
+/** 获取邮件日志详情 */
+export function getMailLog(id: number) {
+  return http.get<MailLog>(`/system/mail-log/get?id=${id}`)
+}

+ 6 - 0
src/api/system/mail/template/index.ts

@@ -25,26 +25,32 @@ export interface MailSendReqVO {
   bccMails?: string[]
 }
 
+/** 获取邮件模板分页列表 */
 export function getMailTemplatePage(params: PageParam) {
   return http.get<PageResult<MailTemplate>>('/system/mail-template/page', params)
 }
 
+/** 获取邮件模板详情 */
 export function getMailTemplate(id: number) {
   return http.get<MailTemplate>(`/system/mail-template/get?id=${id}`)
 }
 
+/** 创建邮件模板 */
 export function createMailTemplate(data: MailTemplate) {
   return http.post<number>('/system/mail-template/create', data)
 }
 
+/** 更新邮件模板 */
 export function updateMailTemplate(data: MailTemplate) {
   return http.put<boolean>('/system/mail-template/update', data)
 }
 
+/** 删除邮件模板 */
 export function deleteMailTemplate(id: number) {
   return http.delete<boolean>(`/system/mail-template/delete?id=${id}`)
 }
 
+/** 发送邮件 */
 export function sendMail(data: MailSendReqVO) {
   return http.post<number>('/system/mail-template/send-mail', data)
 }

+ 5 - 0
src/api/system/sms/log/index.ts

@@ -32,3 +32,8 @@ export interface SmsLog {
 export function getSmsLogPage(params: PageParam) {
   return http.get<PageResult<SmsLog>>('/system/sms-log/page', params)
 }
+
+/** 获取短信日志详情 */
+export function getSmsLog(id: number) {
+  return http.get<SmsLog>(`/system/sms-log/get?id=${id}`)
+}

+ 3 - 8
src/pages-system/mail/log/detail/index.vue

@@ -33,7 +33,7 @@
 import type { MailLog } from '@/api/system/mail/log'
 import { onMounted, ref } from 'vue'
 import { useToast } from 'wot-design-uni'
-import { getMailLogPage } from '@/api/system/mail/log'
+import { getMailLog } from '@/api/system/mail/log'
 import { navigateBackPlus } from '@/utils'
 import { DICT_TYPE } from '@/utils/constants'
 import { formatDateTime } from '@/utils/date'
@@ -75,19 +75,14 @@ function formatReceiveInfo(data?: MailLog) {
   return lines.length > 0 ? lines.join(';') : '-'
 }
 
-/** 加载详情 - 由于没有单独的获取详情接口,通过列表接口获取 */
+/** 加载详情 */
 async function getDetail() {
   if (!props.id) {
     return
   }
   try {
     toast.loading('加载中...')
-    // 通过分页接口获取单条数据
-    // TODO @AI:使用 getMailLog 认为它存在!我去支持下;
-    const data = await getMailLogPage({ pageNo: 1, pageSize: 1, id: props.id })
-    if (data.list && data.list.length > 0) {
-      formData.value = data.list[0]
-    }
+    formData.value = await getMailLog(Number(props.id))
   } finally {
     toast.close()
   }

+ 23 - 5
src/pages-system/mail/template/detail/components/send-form.vue

@@ -61,6 +61,7 @@ import type { MailTemplate } from '@/api/system/mail/template'
 import { computed, ref, watch } from 'vue'
 import { useToast } from 'wot-design-uni'
 import { sendMail } from '@/api/system/mail/template'
+import { isEmail } from '@/utils/validator'
 
 const props = defineProps<{
   modelValue: boolean
@@ -107,12 +108,17 @@ const sendFormRules = computed(() => {
 })
 
 /** 格式化邮箱列表 */
-// TODO @AI:需要 isEmail 校验下,validator 里有
 function normalizeMailList(text: string) {
-  return text
+  const list = text
     .split(/[,,;;\s]+/)
     .map(s => s.trim())
     .filter(Boolean)
+  const invalid = list.find(item => !isEmail(item))
+  if (invalid) {
+    toast.warning(`邮箱格式不正确:${invalid}`)
+    return null
+  }
+  return list
 }
 
 /** 初始化发送表单 */
@@ -146,15 +152,27 @@ async function handleSendSubmit() {
   if (!valid) {
     return
   }
+  const toMails = normalizeMailList(sendFormData.value.toMails)
+  if (!toMails || toMails.length === 0) {
+    return
+  }
+  const ccMails = normalizeMailList(sendFormData.value.ccMails)
+  if (ccMails === null) {
+    return
+  }
+  const bccMails = normalizeMailList(sendFormData.value.bccMails)
+  if (bccMails === null) {
+    return
+  }
 
   sendLoading.value = true
   try {
     await sendMail({
       templateCode: props.template?.code || '',
       templateParams: sendFormData.value.templateParams,
-      toMails: normalizeMailList(sendFormData.value.toMails),
-      ccMails: normalizeMailList(sendFormData.value.ccMails),
-      bccMails: normalizeMailList(sendFormData.value.bccMails),
+      toMails,
+      ccMails: ccMails.length > 0 ? ccMails : undefined,
+      bccMails: bccMails.length > 0 ? bccMails : undefined,
     })
     toast.success('邮件发送成功')
     emit('success')

+ 3 - 10
src/pages-system/mail/template/form/index.vue

@@ -30,7 +30,9 @@
           <wd-cell title="邮箱账号" title-width="200rpx" prop="accountId" center>
             <wd-picker
               v-model="formData.accountId"
-              :columns="accountOptions"
+              :columns="accountList"
+              label-key="mail"
+              value-key="id"
               placeholder="请选择邮箱账号"
             />
           </wd-cell>
@@ -143,15 +145,6 @@ const formRef = ref()
 /** 邮箱账号列表 */
 const accountList = ref<MailAccount[]>([])
 
-/** 邮箱账号选项 */
-// TODO @AI:直接使用 accountList,参考 https://wot-ui.cn/component/picker.html ,支持通过 label-key 和 value-key;
-const accountOptions = computed(() => {
-  return accountList.value.map(item => ({
-    value: item.id,
-    label: item.mail,
-  }))
-})
-
 /** 返回上一页 */
 function handleBack() {
   navigateBackPlus('/pages-system/mail/index')

+ 3 - 10
src/pages-system/sms/channel/form/index.vue

@@ -22,7 +22,9 @@
           <wd-cell title="渠道编码" title-width="200rpx" prop="code" center>
             <wd-picker
               v-model="formData.code"
-              :columns="channelCodeOptions"
+              :columns="getStrDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE)"
+              label-key="label"
+              value-key="value"
               placeholder="请选择渠道编码"
             />
           </wd-cell>
@@ -128,15 +130,6 @@ const formRules = {
 }
 const formRef = ref()
 
-/** 渠道编码选项 */
-// TODO @AI:直接使用 getStrDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE) 在 html 里;别的模块,也是这么干的
-const channelCodeOptions = computed(() => {
-  return getStrDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE).map(item => ({
-    value: item.value,
-    label: item.label,
-  }))
-})
-
 /** 返回上一页 */
 function handleBack() {
   navigateBackPlus('/pages-system/sms/index')

+ 3 - 8
src/pages-system/sms/log/detail/index.vue

@@ -44,7 +44,7 @@
 import type { SmsLog } from '@/api/system/sms/log'
 import { onMounted, ref } from 'vue'
 import { useToast } from 'wot-design-uni'
-import { getSmsLogPage } from '@/api/system/sms/log'
+import { getSmsLog } from '@/api/system/sms/log'
 import { navigateBackPlus } from '@/utils'
 import { DICT_TYPE } from '@/utils/constants'
 import { formatDateTime } from '@/utils/date'
@@ -68,19 +68,14 @@ function handleBack() {
   navigateBackPlus('/pages-system/sms/index')
 }
 
-/** 加载详情 - 由于没有单独的获取详情接口,通过列表接口获取 */
+/** 加载详情 */
 async function getDetail() {
   if (!props.id) {
     return
   }
   try {
     toast.loading('加载中...')
-    // 通过分页接口获取单条数据
-    // TODO @AI:使用 getMailLog 认为它存在!我去支持下;
-    const data = await getSmsLogPage({ pageNo: 1, pageSize: 1, id: props.id })
-    if (data.list && data.list.length > 0) {
-      formData.value = data.list[0]
-    }
+    formData.value = await getSmsLog(Number(props.id))
   } finally {
     toast.close()
   }