index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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="短信类型">
  16. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE" :value="formData?.type" />
  17. </wd-cell>
  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="API 模板编号" :value="String(formData?.apiTemplateId ?? '-')" />
  23. <wd-cell title="短信渠道">
  24. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE" :value="formData?.channelCode" />
  25. </wd-cell>
  26. <wd-cell title="备注" :value="String(formData?.remark ?? '-')" />
  27. <wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />
  28. </wd-cell-group>
  29. </view>
  30. <!-- 发送测试短信弹窗 -->
  31. <SendForm v-model="sendVisible" :template="formData" />
  32. <!-- 底部操作按钮 -->
  33. <view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx">
  34. <view class="w-full flex gap-24rpx">
  35. <wd-button
  36. v-if="hasAccessByCodes(['system:sms-template:send-sms'])"
  37. class="flex-1" type="primary" @click="handleSendTest"
  38. >
  39. 测试
  40. </wd-button>
  41. <wd-button
  42. v-if="hasAccessByCodes(['system:sms-template:update'])"
  43. class="flex-1" type="warning" @click="handleEdit"
  44. >
  45. 编辑
  46. </wd-button>
  47. <wd-button
  48. v-if="hasAccessByCodes(['system:sms-template:delete'])"
  49. class="flex-1" type="error" :loading="deleting" @click="handleDelete"
  50. >
  51. 删除
  52. </wd-button>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script lang="ts" setup>
  58. import type { SmsTemplate } from '@/api/system/sms'
  59. import { onMounted, ref } from 'vue'
  60. import { useToast } from 'wot-design-uni'
  61. import { deleteSmsTemplate, getSmsTemplate } from '@/api/system/sms'
  62. import { useAccess } from '@/hooks/useAccess'
  63. import { navigateBackPlus } from '@/utils'
  64. import { DICT_TYPE } from '@/utils/constants'
  65. import { formatDateTime } from '@/utils/date'
  66. import SendForm from './components/send-form.vue'
  67. const props = defineProps<{
  68. id?: number | any
  69. }>()
  70. definePage({
  71. style: {
  72. navigationBarTitleText: '',
  73. navigationStyle: 'custom',
  74. },
  75. })
  76. const { hasAccessByCodes } = useAccess()
  77. const toast = useToast()
  78. const formData = ref<SmsTemplate>()
  79. const deleting = ref(false)
  80. // 发送测试短信相关
  81. const sendVisible = ref(false)
  82. /** 返回上一页 */
  83. function handleBack() {
  84. navigateBackPlus('/pages-system/sms/index')
  85. }
  86. /** 加载详情 */
  87. async function getDetail() {
  88. if (!props.id) {
  89. return
  90. }
  91. try {
  92. toast.loading('加载中...')
  93. formData.value = await getSmsTemplate(props.id)
  94. } finally {
  95. toast.close()
  96. }
  97. }
  98. /** 编辑 */
  99. function handleEdit() {
  100. uni.navigateTo({
  101. url: `/pages-system/sms/template/form/index?id=${props.id}`,
  102. })
  103. }
  104. /** 删除 */
  105. function handleDelete() {
  106. if (!props.id) {
  107. return
  108. }
  109. uni.showModal({
  110. title: '提示',
  111. content: '确定要删除该短信模板吗?',
  112. success: async (res) => {
  113. if (!res.confirm) {
  114. return
  115. }
  116. deleting.value = true
  117. try {
  118. await deleteSmsTemplate(props.id)
  119. toast.success('删除成功')
  120. setTimeout(() => {
  121. handleBack()
  122. }, 500)
  123. } finally {
  124. deleting.value = false
  125. }
  126. },
  127. })
  128. }
  129. /** 打开发送测试短信弹窗 */
  130. function handleSendTest() {
  131. sendVisible.value = true
  132. }
  133. /** 初始化 */
  134. onMounted(() => {
  135. getDetail()
  136. })
  137. </script>
  138. <style lang="scss" scoped>
  139. </style>