index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="yd-page-container">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="邮件模板详情"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. />
  9. <!-- 详情内容 -->
  10. <view>
  11. <wd-cell-group border>
  12. <wd-cell title="模板编号" :value="String(formData?.id ?? '-')" />
  13. <wd-cell title="模板名称" :value="String(formData?.name ?? '-')" />
  14. <wd-cell title="模板编码" :value="String(formData?.code ?? '-')" />
  15. <wd-cell title="邮箱账号" :value="String(getAccountMail(formData?.accountId) || formData?.accountId || '-')" />
  16. <wd-cell title="发送人名称" :value="String(formData?.nickname ?? '-')" />
  17. <wd-cell title="模板标题" :value="String(formData?.title ?? '-')" />
  18. <wd-cell title="开启状态">
  19. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="formData?.status" />
  20. </wd-cell>
  21. <wd-cell title="模板内容" :value="String(formData?.content ?? '-')" />
  22. <wd-cell title="备注" :value="String(formData?.remark ?? '-')" />
  23. <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />
  24. </wd-cell-group>
  25. </view>
  26. <!-- 发送测试邮件弹窗 -->
  27. <SendForm v-model="sendVisible" :template="formData" />
  28. <!-- 底部操作按钮 -->
  29. <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx">
  30. <view class="w-full flex gap-24rpx">
  31. <wd-button
  32. v-if="hasAccessByCodes(['system:mail-template:send-mail'])"
  33. class="flex-1" type="primary" @click="handleSendTest"
  34. >
  35. 测试
  36. </wd-button>
  37. <wd-button
  38. v-if="hasAccessByCodes(['system:mail-template:update'])"
  39. class="flex-1" type="warning" @click="handleEdit"
  40. >
  41. 编辑
  42. </wd-button>
  43. <wd-button
  44. v-if="hasAccessByCodes(['system:mail-template:delete'])"
  45. class="flex-1" type="error" :loading="deleting" @click="handleDelete"
  46. >
  47. 删除
  48. </wd-button>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script lang="ts" setup>
  54. import type { MailAccount } from '@/api/system/mail/account'
  55. import type { MailTemplate } from '@/api/system/mail/template'
  56. import { onMounted, ref } from 'vue'
  57. import { useToast } from 'wot-design-uni'
  58. import { getSimpleMailAccountList } from '@/api/system/mail/account'
  59. import { deleteMailTemplate, getMailTemplate } from '@/api/system/mail/template'
  60. import { useAccess } from '@/hooks/useAccess'
  61. import { navigateBackPlus } from '@/utils'
  62. import { DICT_TYPE } from '@/utils/constants'
  63. import { formatDateTime } from '@/utils/date'
  64. import SendForm from './components/send-form.vue'
  65. const props = defineProps<{
  66. id?: number | any
  67. }>()
  68. definePage({
  69. style: {
  70. navigationBarTitleText: '',
  71. navigationStyle: 'custom',
  72. },
  73. })
  74. const { hasAccessByCodes } = useAccess()
  75. const toast = useToast()
  76. const formData = ref<MailTemplate>()
  77. const deleting = ref(false)
  78. // 发送测试邮件相关
  79. const sendVisible = ref(false)
  80. /** 邮箱账号列表 */
  81. const accountList = ref<MailAccount[]>([])
  82. /** 获取邮箱账号名称 */
  83. function getAccountMail(accountId?: number) {
  84. return accountList.value.find((item: MailAccount) => item.id === accountId)?.mail
  85. }
  86. /** 返回上一页 */
  87. function handleBack() {
  88. navigateBackPlus('/pages-system/mail/index')
  89. }
  90. /** 加载邮箱账号列表 */
  91. async function loadAccountList() {
  92. try {
  93. accountList.value = await getSimpleMailAccountList()
  94. } catch {
  95. accountList.value = []
  96. }
  97. }
  98. /** 加载详情 */
  99. async function getDetail() {
  100. if (!props.id) {
  101. return
  102. }
  103. try {
  104. toast.loading('加载中...')
  105. formData.value = await getMailTemplate(props.id)
  106. } finally {
  107. toast.close()
  108. }
  109. }
  110. /** 编辑 */
  111. function handleEdit() {
  112. uni.navigateTo({
  113. url: `/pages-system/mail/template/form/index?id=${props.id}`,
  114. })
  115. }
  116. /** 删除 */
  117. function handleDelete() {
  118. if (!props.id) {
  119. return
  120. }
  121. uni.showModal({
  122. title: '提示',
  123. content: '确定要删除该邮件模板吗?',
  124. success: async (res) => {
  125. if (!res.confirm) {
  126. return
  127. }
  128. deleting.value = true
  129. try {
  130. await deleteMailTemplate(props.id)
  131. toast.success('删除成功')
  132. setTimeout(() => {
  133. handleBack()
  134. }, 500)
  135. } finally {
  136. deleting.value = false
  137. }
  138. },
  139. })
  140. }
  141. /** 打开发送测试邮件弹窗 */
  142. function handleSendTest() {
  143. sendVisible.value = true
  144. }
  145. /** 初始化 */
  146. onMounted(async () => {
  147. await loadAccountList()
  148. await getDetail()
  149. })
  150. </script>
  151. <style lang="scss" scoped>
  152. </style>