Commit 9983590fdfb73c5bafead473bce663733d14f33f
1 parent
b4ee4342
feat: vue3 add sensms
Showing
2 changed files
with
68 additions
and
13 deletions
yudao-ui-admin-vue3/src/api/system/sms/smsTemplate/index.ts
| 1 | 1 | import { useAxios } from '@/hooks/web/useAxios' |
| 2 | -import type { SmsTemplateVO, SmsSendVO } from './types' | |
| 2 | +import type { SmsTemplateVO } from './types' | |
| 3 | 3 | |
| 4 | 4 | const request = useAxios() |
| 5 | 5 | |
| ... | ... | @@ -29,7 +29,7 @@ export const deleteSmsTemplateApi = (id: number) => { |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // 发送短信 |
| 32 | -export function sendSms(data: SmsSendVO) { | |
| 32 | +export const sendSmsApi = (data) => { | |
| 33 | 33 | return request.post({ url: '/system/sms-template/send-sms', data }) |
| 34 | 34 | } |
| 35 | 35 | ... | ... |
yudao-ui-admin-vue3/src/views/system/sms/smsTemplate/index.vue
| 1 | 1 | <script setup lang="ts"> |
| 2 | -import { reactive, ref, unref } from 'vue' | |
| 2 | +import { ref, unref } from 'vue' | |
| 3 | 3 | import dayjs from 'dayjs' |
| 4 | -import { ElMessage } from 'element-plus' | |
| 4 | +import { ElMessage, ElForm, ElFormItem, ElInput } from 'element-plus' | |
| 5 | 5 | import { DICT_TYPE } from '@/utils/dict' |
| 6 | 6 | import { useTable } from '@/hooks/web/useTable' |
| 7 | 7 | import { useI18n } from '@/hooks/web/useI18n' |
| ... | ... | @@ -82,23 +82,45 @@ const handleDetail = async (row: SmsTemplateVO) => { |
| 82 | 82 | detailRef.value = row |
| 83 | 83 | setDialogTile('detail') |
| 84 | 84 | } |
| 85 | -const sendSmsForm = reactive({ | |
| 85 | +// ========== 测试相关 ========== | |
| 86 | +const sendSmsForm = ref({ | |
| 86 | 87 | content: '', |
| 87 | - params: '', | |
| 88 | - mobile: '', | |
| 88 | + params: {}, | |
| 89 | + mobile: '141', | |
| 89 | 90 | templateCode: '', |
| 90 | 91 | templateParams: {} |
| 91 | 92 | }) |
| 92 | -// TODO 发送短信 | |
| 93 | -// ========== 测试相关 ========== | |
| 93 | +const sendSmsRules = ref({ | |
| 94 | + mobile: [{ required: true, message: '手机不能为空', trigger: 'blur' }], | |
| 95 | + templateCode: [{ required: true, message: '手机不能为空', trigger: 'blur' }], | |
| 96 | + templateParams: {} | |
| 97 | +}) | |
| 98 | +const sendVisible = ref(false) | |
| 99 | + | |
| 94 | 100 | const handleSendSms = (row: any) => { |
| 95 | - sendSmsForm.content = row.content | |
| 96 | - sendSmsForm.params = row.params | |
| 97 | - sendSmsForm.templateCode = row.code | |
| 98 | - sendSmsForm.templateParams = row.params.reduce(function (obj, item) { | |
| 101 | + sendSmsForm.value.content = row.content | |
| 102 | + sendSmsForm.value.params = row.params | |
| 103 | + sendSmsForm.value.templateCode = row.code | |
| 104 | + sendSmsForm.value.templateParams = row.params.reduce(function (obj, item) { | |
| 99 | 105 | obj[item] = undefined |
| 100 | 106 | return obj |
| 101 | 107 | }, {}) |
| 108 | + sendSmsRules.value.templateParams = row.params.reduce(function (obj, item) { | |
| 109 | + obj[item] = { required: true, message: '参数 ' + item + ' 不能为空', trigger: 'change' } | |
| 110 | + return obj | |
| 111 | + }, {}) | |
| 112 | + sendVisible.value = true | |
| 113 | +} | |
| 114 | + | |
| 115 | +const sendSmsTest = () => { | |
| 116 | + const data = { | |
| 117 | + mobile: sendSmsForm.value.mobile, | |
| 118 | + templateCode: sendSmsForm.value.templateCode, | |
| 119 | + templateParams: sendSmsForm.value.templateParams | |
| 120 | + } | |
| 121 | + SmsTemplateApi.sendSmsApi(data) | |
| 122 | + ElMessage.info('发送成功') | |
| 123 | + sendVisible.value = false | |
| 102 | 124 | } |
| 103 | 125 | |
| 104 | 126 | // ========== 初始化 ========== |
| ... | ... | @@ -213,4 +235,37 @@ getList() |
| 213 | 235 | <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button> |
| 214 | 236 | </template> |
| 215 | 237 | </Dialog> |
| 238 | + <Dialog v-model="sendVisible" title="测试"> | |
| 239 | + <el-form :model="sendSmsForm" :rules="sendSmsRules" label-width="140px"> | |
| 240 | + <el-form-item label="模板内容" prop="content"> | |
| 241 | + <el-input | |
| 242 | + v-model="sendSmsForm.content" | |
| 243 | + type="textarea" | |
| 244 | + placeholder="请输入模板内容" | |
| 245 | + readonly | |
| 246 | + /> | |
| 247 | + </el-form-item> | |
| 248 | + <el-form-item label="手机号" prop="mobile"> | |
| 249 | + <el-input v-model="sendSmsForm.mobile" placeholder="请输入手机号" /> | |
| 250 | + </el-form-item> | |
| 251 | + <el-form-item | |
| 252 | + v-for="param in sendSmsForm.params" | |
| 253 | + :key="param" | |
| 254 | + :label="'参数 {' + param + '}'" | |
| 255 | + :prop="'templateParams.' + param" | |
| 256 | + > | |
| 257 | + <el-input | |
| 258 | + v-model="sendSmsForm.templateParams[param]" | |
| 259 | + :placeholder="'请输入 ' + param + ' 参数'" | |
| 260 | + /> | |
| 261 | + </el-form-item> | |
| 262 | + </el-form> | |
| 263 | + <!-- 操作按钮 --> | |
| 264 | + <template #footer> | |
| 265 | + <el-button type="primary" :loading="loading" @click="sendSmsTest"> | |
| 266 | + {{ t('action.test') }} | |
| 267 | + </el-button> | |
| 268 | + <el-button @click="sendVisible = false">{{ t('dialog.close') }}</el-button> | |
| 269 | + </template> | |
| 270 | + </Dialog> | |
| 216 | 271 | </template> | ... | ... |