Commit cb1f9a580874e27fdd37c7c6a05b414563d94ca1
1 parent
d8d458a0
短信渠道的前端代码的完成
Showing
8 changed files
with
599 additions
and
4 deletions
ruoyi-ui/src/api/system/sms/smsChannel.js
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建短信渠道 | |
| 4 | +export function createSmsChannel(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/system/sms-channel/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新短信渠道 | |
| 13 | +export function updateSmsChannel(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/system/sms-channel/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除短信渠道 | |
| 22 | +export function deleteSmsChannel(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/system/sms-channel/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得短信渠道 | |
| 30 | +export function getSmsChannel(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/system/sms-channel/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得短信渠道分页 | |
| 38 | +export function getSmsChannelPage(query) { | |
| 39 | + return request({ | |
| 40 | + url: '/system/sms-channel/page', | |
| 41 | + method: 'get', | |
| 42 | + params: query | |
| 43 | + }) | |
| 44 | +} | ... | ... |
ruoyi-ui/src/utils/dict.js
| ... | ... | @@ -17,6 +17,7 @@ export const DICT_TYPE = { |
| 17 | 17 | SYS_OPERATE_TYPE: 'sys_operate_type', |
| 18 | 18 | SYS_LOGIN_RESULT: 'sys_login_result', |
| 19 | 19 | SYS_CONFIG_TYPE: 'sys_config_type', |
| 20 | + SYS_SMS_CHANNEL_CODE: 'sys_sms_channel_code', | |
| 20 | 21 | |
| 21 | 22 | INF_REDIS_TIMEOUT_TYPE: 'inf_redis_timeout_type', |
| 22 | 23 | INF_JOB_STATUS: 'inf_job_status', | ... | ... |
ruoyi-ui/src/views/system/sms/smsChannel.vue
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 5 | + <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> | |
| 6 | + <el-form-item label="短信签名" prop="signature"> | |
| 7 | + <el-input v-model="queryParams.signature" placeholder="请输入短信签名" clearable size="small" @keyup.enter.native="handleQuery"/> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="启用状态" prop="status"> | |
| 10 | + <el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable size="small"> | |
| 11 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)" | |
| 12 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 13 | + </el-select> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="创建时间"> | |
| 16 | + <el-date-picker v-model="dateRangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd" | |
| 17 | + type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" /> | |
| 18 | + </el-form-item> | |
| 19 | + <el-form-item> | |
| 20 | + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | |
| 21 | + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | |
| 22 | + </el-form-item> | |
| 23 | + </el-form> | |
| 24 | + | |
| 25 | + <!-- 操作工具栏 --> | |
| 26 | + <el-row :gutter="10" class="mb8"> | |
| 27 | + <el-col :span="1.5"> | |
| 28 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | |
| 29 | + v-hasPermi="['system:sms-channel:create']">新增</el-button> | |
| 30 | + </el-col> | |
| 31 | + <el-col :span="1.5"> | |
| 32 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" | |
| 33 | + v-hasPermi="['system:sms-channel:export']">导出</el-button> | |
| 34 | + </el-col> | |
| 35 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 36 | + </el-row> | |
| 37 | + | |
| 38 | + <!-- 列表 --> | |
| 39 | + <el-table v-loading="loading" :data="list"> | |
| 40 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 41 | + <el-table-column label="短信签名" align="center" prop="signature" /> | |
| 42 | + <el-table-column label="渠道编码" align="center" prop="code"> | |
| 43 | + <template slot-scope="scope"> | |
| 44 | + <span>{{ getDictDataLabel(DICT_TYPE.SYS_SMS_CHANNEL_CODE, scope.row.code) }}</span> | |
| 45 | + </template> | |
| 46 | + </el-table-column>> | |
| 47 | + <el-table-column label="启用状态" align="center" prop="status"> | |
| 48 | + <template slot-scope="scope"> | |
| 49 | + <span>{{ getDictDataLabel(DICT_TYPE.SYS_COMMON_STATUS, scope.row.status) }}</span> | |
| 50 | + </template> | |
| 51 | + </el-table-column>> | |
| 52 | + <el-table-column label="备注" align="center" prop="remark" /> | |
| 53 | + <el-table-column label="短信 API 的账号" align="center" prop="apiKey" /> | |
| 54 | + <el-table-column label="短信 API 的秘钥" align="center" prop="apiSecret" /> | |
| 55 | + <el-table-column label="短信发送回调 URL" align="center" prop="callbackUrl" /> | |
| 56 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 57 | + <template slot-scope="scope"> | |
| 58 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 59 | + </template> | |
| 60 | + </el-table-column> | |
| 61 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 62 | + <template slot-scope="scope"> | |
| 63 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | |
| 64 | + v-hasPermi="['system:sms-channel:update']">修改</el-button> | |
| 65 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 66 | + v-hasPermi="['system:sms-channel:delete']">删除</el-button> | |
| 67 | + </template> | |
| 68 | + </el-table-column> | |
| 69 | + </el-table> | |
| 70 | + <!-- 分页组件 --> | |
| 71 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 72 | + @pagination="getList"/> | |
| 73 | + | |
| 74 | + <!-- 对话框(添加 / 修改) --> | |
| 75 | + <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | |
| 76 | + <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | |
| 77 | + <el-form-item label="短信签名" prop="signature"> | |
| 78 | + <el-input v-model="form.signature" placeholder="请输入短信签名" /> | |
| 79 | + </el-form-item> | |
| 80 | + <el-form-item label="渠道编码" prop="code"> | |
| 81 | + <el-input v-model="form.code" placeholder="请输入渠道编码" /> | |
| 82 | + </el-form-item> | |
| 83 | + <el-form-item label="启用状态"> | |
| 84 | + <el-radio-group v-model="form.status"> | |
| 85 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)" | |
| 86 | + :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio> | |
| 87 | + </el-radio-group> | |
| 88 | + </el-form-item> | |
| 89 | + <el-form-item label="备注" prop="remark"> | |
| 90 | + <el-input v-model="form.remark" placeholder="请输入备注" /> | |
| 91 | + </el-form-item> | |
| 92 | + <el-form-item label="短信 API 的账号" prop="apiKey"> | |
| 93 | + <el-input v-model="form.apiKey" placeholder="请输入短信 API 的账号" /> | |
| 94 | + </el-form-item> | |
| 95 | + <el-form-item label="短信 API 的秘钥" prop="apiSecret"> | |
| 96 | + <el-input v-model="form.apiSecret" placeholder="请输入短信 API 的秘钥" /> | |
| 97 | + </el-form-item> | |
| 98 | + <el-form-item label="短信发送回调 URL" prop="callbackUrl"> | |
| 99 | + <el-input v-model="form.callbackUrl" placeholder="请输入短信发送回调 URL" /> | |
| 100 | + </el-form-item> | |
| 101 | + </el-form> | |
| 102 | + <div slot="footer" class="dialog-footer"> | |
| 103 | + <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 104 | + <el-button @click="cancel">取 消</el-button> | |
| 105 | + </div> | |
| 106 | + </el-dialog> | |
| 107 | + </div> | |
| 108 | +</template> | |
| 109 | + | |
| 110 | +<script> | |
| 111 | +import { createSmsChannel, updateSmsChannel, deleteSmsChannel, getSmsChannel, getSmsChannelPage } from "@/api/system/sms/smsChannel"; | |
| 112 | + | |
| 113 | +export default { | |
| 114 | + name: "SmsChannel", | |
| 115 | + components: { | |
| 116 | + }, | |
| 117 | + data() { | |
| 118 | + return { | |
| 119 | + // 遮罩层 | |
| 120 | + loading: true, | |
| 121 | + // 显示搜索条件 | |
| 122 | + showSearch: true, | |
| 123 | + // 总条数 | |
| 124 | + total: 0, | |
| 125 | + // 短信渠道列表 | |
| 126 | + list: [], | |
| 127 | + // 弹出层标题 | |
| 128 | + title: "", | |
| 129 | + // 是否显示弹出层 | |
| 130 | + open: false, | |
| 131 | + dateRangeCreateTime: [], | |
| 132 | + // 查询参数 | |
| 133 | + queryParams: { | |
| 134 | + pageNo: 1, | |
| 135 | + pageSize: 10, | |
| 136 | + signature: null, | |
| 137 | + status: null, | |
| 138 | + }, | |
| 139 | + // 表单参数 | |
| 140 | + form: {}, | |
| 141 | + // 表单校验 | |
| 142 | + rules: { | |
| 143 | + signature: [{ required: true, message: "短信签名不能为空", trigger: "blur" }], | |
| 144 | + code: [{ required: true, message: "渠道编码不能为空", trigger: "blur" }], | |
| 145 | + status: [{ required: true, message: "启用状态不能为空", trigger: "blur" }], | |
| 146 | + apiKey: [{ required: true, message: "短信 API 的账号不能为空", trigger: "blur" }], | |
| 147 | + } | |
| 148 | + }; | |
| 149 | + }, | |
| 150 | + created() { | |
| 151 | + this.getList(); | |
| 152 | + }, | |
| 153 | + methods: { | |
| 154 | + /** 查询列表 */ | |
| 155 | + getList() { | |
| 156 | + this.loading = true; | |
| 157 | + // 处理查询参数 | |
| 158 | + let params = {...this.queryParams}; | |
| 159 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | |
| 160 | + // 执行查询 | |
| 161 | + getSmsChannelPage(params).then(response => { | |
| 162 | + this.list = response.data.list; | |
| 163 | + this.total = response.data.total; | |
| 164 | + this.loading = false; | |
| 165 | + }); | |
| 166 | + }, | |
| 167 | + /** 取消按钮 */ | |
| 168 | + cancel() { | |
| 169 | + this.open = false; | |
| 170 | + this.reset(); | |
| 171 | + }, | |
| 172 | + /** 表单重置 */ | |
| 173 | + reset() { | |
| 174 | + this.form = { | |
| 175 | + id: undefined, | |
| 176 | + signature: undefined, | |
| 177 | + code: undefined, | |
| 178 | + status: undefined, | |
| 179 | + remark: undefined, | |
| 180 | + apiKey: undefined, | |
| 181 | + apiSecret: undefined, | |
| 182 | + callbackUrl: undefined, | |
| 183 | + }; | |
| 184 | + this.resetForm("form"); | |
| 185 | + }, | |
| 186 | + /** 搜索按钮操作 */ | |
| 187 | + handleQuery() { | |
| 188 | + this.queryParams.pageNo = 1; | |
| 189 | + this.getList(); | |
| 190 | + }, | |
| 191 | + /** 重置按钮操作 */ | |
| 192 | + resetQuery() { | |
| 193 | + this.dateRangeCreateTime = []; | |
| 194 | + this.resetForm("queryForm"); | |
| 195 | + this.handleQuery(); | |
| 196 | + }, | |
| 197 | + /** 新增按钮操作 */ | |
| 198 | + handleAdd() { | |
| 199 | + this.reset(); | |
| 200 | + this.open = true; | |
| 201 | + this.title = "添加短信渠道"; | |
| 202 | + }, | |
| 203 | + /** 修改按钮操作 */ | |
| 204 | + handleUpdate(row) { | |
| 205 | + this.reset(); | |
| 206 | + const id = row.id; | |
| 207 | + getSmsChannel(id).then(response => { | |
| 208 | + this.form = response.data; | |
| 209 | + this.open = true; | |
| 210 | + this.title = "修改短信渠道"; | |
| 211 | + }); | |
| 212 | + }, | |
| 213 | + /** 提交按钮 */ | |
| 214 | + submitForm() { | |
| 215 | + this.$refs["form"].validate(valid => { | |
| 216 | + if (!valid) { | |
| 217 | + return; | |
| 218 | + } | |
| 219 | + // 修改的提交 | |
| 220 | + if (this.form.id != null) { | |
| 221 | + updateSmsChannel(this.form).then(response => { | |
| 222 | + this.msgSuccess("修改成功"); | |
| 223 | + this.open = false; | |
| 224 | + this.getList(); | |
| 225 | + }); | |
| 226 | + return; | |
| 227 | + } | |
| 228 | + // 添加的提交 | |
| 229 | + createSmsChannel(this.form).then(response => { | |
| 230 | + this.msgSuccess("新增成功"); | |
| 231 | + this.open = false; | |
| 232 | + this.getList(); | |
| 233 | + }); | |
| 234 | + }); | |
| 235 | + }, | |
| 236 | + /** 删除按钮操作 */ | |
| 237 | + handleDelete(row) { | |
| 238 | + const id = row.id; | |
| 239 | + this.$confirm('是否确认删除短信渠道编号为"' + id + '"的数据项?', "警告", { | |
| 240 | + confirmButtonText: "确定", | |
| 241 | + cancelButtonText: "取消", | |
| 242 | + type: "warning" | |
| 243 | + }).then(function() { | |
| 244 | + return deleteSmsChannel(id); | |
| 245 | + }).then(() => { | |
| 246 | + this.getList(); | |
| 247 | + this.msgSuccess("删除成功"); | |
| 248 | + }) | |
| 249 | + }, | |
| 250 | + /** 导出按钮操作 */ | |
| 251 | + handleExport() { | |
| 252 | + // 处理查询参数 | |
| 253 | + let params = {...this.queryParams}; | |
| 254 | + params.pageNo = undefined; | |
| 255 | + params.pageSize = undefined; | |
| 256 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | |
| 257 | + // 执行导出 | |
| 258 | + this.$confirm('是否确认导出所有短信渠道数据项?', "警告", { | |
| 259 | + confirmButtonText: "确定", | |
| 260 | + cancelButtonText: "取消", | |
| 261 | + type: "warning" | |
| 262 | + }).then(function() { | |
| 263 | + return exportSmsChannelExcel(params); | |
| 264 | + }).then(response => { | |
| 265 | + this.downloadExcel(response, '短信渠道.xls'); | |
| 266 | + }) | |
| 267 | + } | |
| 268 | + } | |
| 269 | +}; | |
| 270 | +</script><template> | |
| 271 | + <div class="app-container"> | |
| 272 | + | |
| 273 | + <!-- 搜索工作栏 --> | |
| 274 | + <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> | |
| 275 | + <el-form-item label="短信签名" prop="signature"> | |
| 276 | + <el-input v-model="queryParams.signature" placeholder="请输入短信签名" clearable size="small" @keyup.enter.native="handleQuery"/> | |
| 277 | + </el-form-item> | |
| 278 | + <el-form-item label="启用状态" prop="status"> | |
| 279 | + <el-select v-model="queryParams.status" placeholder="请选择启用状态" clearable size="small"> | |
| 280 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)" | |
| 281 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 282 | + </el-select> | |
| 283 | + </el-form-item> | |
| 284 | + <el-form-item label="创建时间"> | |
| 285 | + <el-date-picker v-model="dateRangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd" | |
| 286 | + type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" /> | |
| 287 | + </el-form-item> | |
| 288 | + <el-form-item> | |
| 289 | + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | |
| 290 | + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | |
| 291 | + </el-form-item> | |
| 292 | + </el-form> | |
| 293 | + | |
| 294 | + <!-- 操作工具栏 --> | |
| 295 | + <el-row :gutter="10" class="mb8"> | |
| 296 | + <el-col :span="1.5"> | |
| 297 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | |
| 298 | + v-hasPermi="['system:sms-channel:create']">新增</el-button> | |
| 299 | + </el-col> | |
| 300 | + <el-col :span="1.5"> | |
| 301 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" | |
| 302 | + v-hasPermi="['system:sms-channel:export']">导出</el-button> | |
| 303 | + </el-col> | |
| 304 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 305 | + </el-row> | |
| 306 | + | |
| 307 | + <!-- 列表 --> | |
| 308 | + <el-table v-loading="loading" :data="list"> | |
| 309 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 310 | + <el-table-column label="短信签名" align="center" prop="signature" /> | |
| 311 | + <el-table-column label="渠道编码" align="center" prop="code"> | |
| 312 | + <template slot-scope="scope"> | |
| 313 | + <span>{{ getDictDataLabel(DICT_TYPE.SYS_SMS_CHANNEL_CODE, scope.row.code) }}</span> | |
| 314 | + </template> | |
| 315 | + </el-table-column>> | |
| 316 | + <el-table-column label="启用状态" align="center" prop="status"> | |
| 317 | + <template slot-scope="scope"> | |
| 318 | + <span>{{ getDictDataLabel(DICT_TYPE.SYS_COMMON_STATUS, scope.row.status) }}</span> | |
| 319 | + </template> | |
| 320 | + </el-table-column>> | |
| 321 | + <el-table-column label="备注" align="center" prop="remark" /> | |
| 322 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 323 | + <template slot-scope="scope"> | |
| 324 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 325 | + </template> | |
| 326 | + </el-table-column> | |
| 327 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 328 | + <template slot-scope="scope"> | |
| 329 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | |
| 330 | + v-hasPermi="['system:sms-channel:update']">修改</el-button> | |
| 331 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 332 | + v-hasPermi="['system:sms-channel:delete']">删除</el-button> | |
| 333 | + </template> | |
| 334 | + </el-table-column> | |
| 335 | + </el-table> | |
| 336 | + <!-- 分页组件 --> | |
| 337 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 338 | + @pagination="getList"/> | |
| 339 | + | |
| 340 | + <!-- 对话框(添加 / 修改) --> | |
| 341 | + <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> | |
| 342 | + <el-form ref="form" :model="form" :rules="rules" label-width="130px"> | |
| 343 | + <el-form-item label="短信签名" prop="signature"> | |
| 344 | + <el-input v-model="form.signature" placeholder="请输入短信签名" /> | |
| 345 | + </el-form-item> | |
| 346 | + <el-form-item label="渠道编码" prop="code"> | |
| 347 | + <el-select v-model="form.code" placeholder="请选择渠道编码" :disabled="form.id > 0"> | |
| 348 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYS_SMS_CHANNEL_CODE)" | |
| 349 | + :key="dict.value" :label="dict.label" :value="dict.value" /> | |
| 350 | + </el-select> | |
| 351 | + </el-form-item> | |
| 352 | + <el-form-item label="启用状态"> | |
| 353 | + <el-radio-group v-model="form.status"> | |
| 354 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)" | |
| 355 | + :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio> | |
| 356 | + </el-radio-group> | |
| 357 | + </el-form-item> | |
| 358 | + <el-form-item label="备注" prop="remark"> | |
| 359 | + <el-input v-model="form.remark" placeholder="请输入备注" /> | |
| 360 | + </el-form-item> | |
| 361 | + <el-form-item label="短信 API 的账号" prop="apiKey"> | |
| 362 | + <el-input v-model="form.apiKey" placeholder="请输入短信 API 的账号" /> | |
| 363 | + </el-form-item> | |
| 364 | + <el-form-item v-if="form.code !== 'YUN_PIAN'" label="短信 API 的秘钥" prop="apiSecret"> | |
| 365 | + <el-input v-model="form.apiSecret" placeholder="请输入短信 API 的秘钥" /> | |
| 366 | + </el-form-item> | |
| 367 | + <el-form-item label="短信发送回调 URL" prop="callbackUrl"> | |
| 368 | + <el-input v-model="form.callbackUrl" placeholder="请输入短信发送回调 URL" /> | |
| 369 | + </el-form-item> | |
| 370 | + </el-form> | |
| 371 | + <div slot="footer" class="dialog-footer"> | |
| 372 | + <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 373 | + <el-button @click="cancel">取 消</el-button> | |
| 374 | + </div> | |
| 375 | + </el-dialog> | |
| 376 | + </div> | |
| 377 | +</template> | |
| 378 | + | |
| 379 | +<script> | |
| 380 | +import { createSmsChannel, updateSmsChannel, deleteSmsChannel, getSmsChannel, getSmsChannelPage } from "@/api/system/sms/smsChannel"; | |
| 381 | + | |
| 382 | +export default { | |
| 383 | + name: "SmsChannel", | |
| 384 | + components: { | |
| 385 | + }, | |
| 386 | + data() { | |
| 387 | + return { | |
| 388 | + // 遮罩层 | |
| 389 | + loading: true, | |
| 390 | + // 显示搜索条件 | |
| 391 | + showSearch: true, | |
| 392 | + // 总条数 | |
| 393 | + total: 0, | |
| 394 | + // 短信渠道列表 | |
| 395 | + list: [], | |
| 396 | + // 弹出层标题 | |
| 397 | + title: "", | |
| 398 | + // 是否显示弹出层 | |
| 399 | + open: false, | |
| 400 | + dateRangeCreateTime: [], | |
| 401 | + // 查询参数 | |
| 402 | + queryParams: { | |
| 403 | + pageNo: 1, | |
| 404 | + pageSize: 10, | |
| 405 | + signature: null, | |
| 406 | + status: null, | |
| 407 | + }, | |
| 408 | + // 表单参数 | |
| 409 | + form: {}, | |
| 410 | + // 表单校验 | |
| 411 | + apiKeyEnableChannelCodes: ['YUN_PIAN'], | |
| 412 | + rules: { | |
| 413 | + signature: [{ required: true, message: "短信签名不能为空", trigger: "blur" }], | |
| 414 | + code: [{ required: true, message: "渠道编码不能为空", trigger: "blur" }], | |
| 415 | + status: [{ required: true, message: "启用状态不能为空", trigger: "blur" }], | |
| 416 | + apiKey: [{ required: true, message: "短信 API 的账号不能为空", trigger: "blur" }], | |
| 417 | + apiSecret: [{ required: true, message: "短信 API 的秘钥不能为空", trigger: "blur" }], | |
| 418 | + } | |
| 419 | + }; | |
| 420 | + }, | |
| 421 | + created() { | |
| 422 | + this.getList(); | |
| 423 | + }, | |
| 424 | + methods: { | |
| 425 | + /** 查询列表 */ | |
| 426 | + getList() { | |
| 427 | + this.loading = true; | |
| 428 | + // 处理查询参数 | |
| 429 | + let params = {...this.queryParams}; | |
| 430 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | |
| 431 | + // 执行查询 | |
| 432 | + getSmsChannelPage(params).then(response => { | |
| 433 | + this.list = response.data.list; | |
| 434 | + this.total = response.data.total; | |
| 435 | + this.loading = false; | |
| 436 | + }); | |
| 437 | + }, | |
| 438 | + /** 取消按钮 */ | |
| 439 | + cancel() { | |
| 440 | + this.open = false; | |
| 441 | + this.reset(); | |
| 442 | + }, | |
| 443 | + /** 表单重置 */ | |
| 444 | + reset() { | |
| 445 | + this.form = { | |
| 446 | + id: undefined, | |
| 447 | + signature: undefined, | |
| 448 | + code: undefined, | |
| 449 | + status: undefined, | |
| 450 | + remark: undefined, | |
| 451 | + apiKey: undefined, | |
| 452 | + apiSecret: undefined, | |
| 453 | + callbackUrl: undefined, | |
| 454 | + }; | |
| 455 | + this.resetForm("form"); | |
| 456 | + }, | |
| 457 | + /** 搜索按钮操作 */ | |
| 458 | + handleQuery() { | |
| 459 | + this.queryParams.pageNo = 1; | |
| 460 | + this.getList(); | |
| 461 | + }, | |
| 462 | + /** 重置按钮操作 */ | |
| 463 | + resetQuery() { | |
| 464 | + this.dateRangeCreateTime = []; | |
| 465 | + this.resetForm("queryForm"); | |
| 466 | + this.handleQuery(); | |
| 467 | + }, | |
| 468 | + /** 新增按钮操作 */ | |
| 469 | + handleAdd() { | |
| 470 | + this.reset(); | |
| 471 | + this.open = true; | |
| 472 | + this.title = "添加短信渠道"; | |
| 473 | + }, | |
| 474 | + /** 修改按钮操作 */ | |
| 475 | + handleUpdate(row) { | |
| 476 | + this.reset(); | |
| 477 | + const id = row.id; | |
| 478 | + getSmsChannel(id).then(response => { | |
| 479 | + this.form = response.data; | |
| 480 | + this.open = true; | |
| 481 | + this.title = "修改短信渠道"; | |
| 482 | + }); | |
| 483 | + }, | |
| 484 | + /** 提交按钮 */ | |
| 485 | + submitForm() { | |
| 486 | + this.$refs["form"].validate(valid => { | |
| 487 | + if (!valid) { | |
| 488 | + return; | |
| 489 | + } | |
| 490 | + // 修改的提交 | |
| 491 | + if (this.form.id != null) { | |
| 492 | + updateSmsChannel(this.form).then(response => { | |
| 493 | + this.msgSuccess("修改成功"); | |
| 494 | + this.open = false; | |
| 495 | + this.getList(); | |
| 496 | + }); | |
| 497 | + return; | |
| 498 | + } | |
| 499 | + // 添加的提交 | |
| 500 | + createSmsChannel(this.form).then(response => { | |
| 501 | + this.msgSuccess("新增成功"); | |
| 502 | + this.open = false; | |
| 503 | + this.getList(); | |
| 504 | + }); | |
| 505 | + }); | |
| 506 | + }, | |
| 507 | + /** 删除按钮操作 */ | |
| 508 | + handleDelete(row) { | |
| 509 | + const id = row.id; | |
| 510 | + this.$confirm('是否确认删除短信渠道编号为"' + id + '"的数据项?', "警告", { | |
| 511 | + confirmButtonText: "确定", | |
| 512 | + cancelButtonText: "取消", | |
| 513 | + type: "warning" | |
| 514 | + }).then(function() { | |
| 515 | + return deleteSmsChannel(id); | |
| 516 | + }).then(() => { | |
| 517 | + this.getList(); | |
| 518 | + this.msgSuccess("删除成功"); | |
| 519 | + }) | |
| 520 | + }, | |
| 521 | + /** 导出按钮操作 */ | |
| 522 | + handleExport() { | |
| 523 | + // 处理查询参数 | |
| 524 | + let params = {...this.queryParams}; | |
| 525 | + params.pageNo = undefined; | |
| 526 | + params.pageSize = undefined; | |
| 527 | + this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime'); | |
| 528 | + // 执行导出 | |
| 529 | + this.$confirm('是否确认导出所有短信渠道数据项?', "警告", { | |
| 530 | + confirmButtonText: "确定", | |
| 531 | + cancelButtonText: "取消", | |
| 532 | + type: "warning" | |
| 533 | + }).then(function() { | |
| 534 | + return exportSmsChannelExcel(params); | |
| 535 | + }).then(response => { | |
| 536 | + this.downloadExcel(response, '短信渠道.xls'); | |
| 537 | + }) | |
| 538 | + } | |
| 539 | + } | |
| 540 | +}; | |
| 541 | +</script> | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/sms/core/client/impl/SmsClientFactoryImpl.java
| ... | ... | @@ -42,7 +42,8 @@ public class SmsClientFactoryImpl implements SmsClientFactory { |
| 42 | 42 | // 初始化 channelCodeClients 集合 |
| 43 | 43 | Arrays.stream(SmsChannelEnum.values()).forEach(channel -> { |
| 44 | 44 | // 创建一个空的 SmsChannelProperties 对象 |
| 45 | - SmsChannelProperties properties = new SmsChannelProperties().setCode(channel.getCode()); | |
| 45 | + SmsChannelProperties properties = new SmsChannelProperties().setCode(channel.getCode()) | |
| 46 | + .setApiKey("default").setApiSecret("default"); | |
| 46 | 47 | // 创建 Sms 客户端 |
| 47 | 48 | AbstractSmsClient smsClient = createSmsClient(properties); |
| 48 | 49 | channelCodeClients.put(channel.getCode(), smsClient); | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/sms/core/client/impl/aliyun/AliyunSmsClient.java
| 1 | 1 | package cn.iocoder.dashboard.framework.sms.core.client.impl.aliyun; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.lang.Assert; | |
| 3 | 4 | import cn.hutool.core.util.StrUtil; |
| 4 | 5 | import cn.iocoder.dashboard.common.core.KeyValue; |
| 5 | 6 | import cn.iocoder.dashboard.framework.sms.core.client.SmsCommonResult; |
| ... | ... | @@ -50,6 +51,8 @@ public class AliyunSmsClient extends AbstractSmsClient { |
| 50 | 51 | |
| 51 | 52 | public AliyunSmsClient(SmsChannelProperties properties) { |
| 52 | 53 | super(properties, new AliyunSmsCodeMapping()); |
| 54 | + Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空"); | |
| 55 | + Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空"); | |
| 53 | 56 | } |
| 54 | 57 | |
| 55 | 58 | @Override | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/sms/core/client/impl/yunpian/YunpianSmsClient.java
| 1 | 1 | package cn.iocoder.dashboard.framework.sms.core.client.impl.yunpian; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.hutool.core.lang.Assert; | |
| 4 | 5 | import cn.hutool.core.util.StrUtil; |
| 5 | 6 | import cn.hutool.core.util.URLUtil; |
| 6 | 7 | import cn.iocoder.dashboard.common.core.KeyValue; |
| ... | ... | @@ -41,6 +42,7 @@ public class YunpianSmsClient extends AbstractSmsClient { |
| 41 | 42 | |
| 42 | 43 | public YunpianSmsClient(SmsChannelProperties properties) { |
| 43 | 44 | super(properties, new YunpianSmsCodeMapping()); |
| 45 | + Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空"); | |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | 48 | @Override | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java
src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/vo/channel/SysSmsChannelBaseVO.java
| ... | ... | @@ -2,6 +2,7 @@ package cn.iocoder.dashboard.modules.system.controller.sms.vo.channel; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.annotations.ApiModelProperty; |
| 4 | 4 | import lombok.Data; |
| 5 | +import org.hibernate.validator.constraints.URL; | |
| 5 | 6 | |
| 6 | 7 | import javax.validation.constraints.NotNull; |
| 7 | 8 | |
| ... | ... | @@ -16,8 +17,8 @@ public class SysSmsChannelBaseVO { |
| 16 | 17 | @NotNull(message = "短信签名不能为空") |
| 17 | 18 | private String signature; |
| 18 | 19 | |
| 19 | - @ApiModelProperty(value = "任务状态", required = true, example = "1") | |
| 20 | - @NotNull(message = "任务状态不能为空") | |
| 20 | + @ApiModelProperty(value = "启用状态", required = true, example = "1") | |
| 21 | + @NotNull(message = "启用状态不能为空") | |
| 21 | 22 | private Integer status; |
| 22 | 23 | |
| 23 | 24 | @ApiModelProperty(value = "备注", example = "好吃!") |
| ... | ... | @@ -31,6 +32,8 @@ public class SysSmsChannelBaseVO { |
| 31 | 32 | private String apiSecret; |
| 32 | 33 | |
| 33 | 34 | @ApiModelProperty(value = "短信发送回调 URL", example = "http://www.iocoder.cn") |
| 35 | + @URL(message = "回调 URL 格式不正确") | |
| 34 | 36 | private String callbackUrl; |
| 35 | 37 | |
| 38 | + | |
| 36 | 39 | } | ... | ... |