1. 编写短信模板的前端

This commit is contained in:
YunaiV 2021-04-10 01:39:27 +08:00
parent 9f794ecb15
commit 73a2f4d84c
21 changed files with 181 additions and 58 deletions

7
ruoyi-ui/.env.demo1024 Normal file
View File

@ -0,0 +1,7 @@
NODE_ENV = production
# 测试环境配置
ENV = 'staging'
# 芋道管理系统/测试环境
VUE_APP_BASE_API = 'http://127.0.0.1:48080'

View File

@ -8,6 +8,7 @@
"dev": "vue-cli-service serve",
"build:prod": "vue-cli-service build",
"build:stage": "vue-cli-service build --mode staging",
"build:demo1024": "vue-cli-service build --mode demo1024",
"preview": "node build/index.js --preview",
"lint": "eslint --ext .js,.vue src"
},

View File

@ -42,3 +42,11 @@ export function getSmsChannelPage(query) {
params: query
})
}
// 获得短信渠道精简列表
export function getSimpleSmsChannels() {
return request({
url: '/system/sms-channel/list-all-simple',
method: 'get',
})
}

View File

@ -108,7 +108,8 @@
</template>
<script>
import { createSmsChannel, updateSmsChannel, deleteSmsChannel, getSmsChannel, getSmsChannelPage } from "@/api/system/sms/smsChannel";
import { createSmsChannel, updateSmsChannel, deleteSmsChannel, getSmsChannel, getSmsChannelPage,
getSimpleSmsChannels } from "@/api/system/sms/smsChannel";
export default {
name: "SmsChannel",
@ -144,7 +145,7 @@ export default {
code: [{ required: true, message: "渠道编码不能为空", trigger: "blur" }],
status: [{ required: true, message: "启用状态不能为空", trigger: "blur" }],
apiKey: [{ required: true, message: "短信 API 的账号不能为空", trigger: "blur" }],
}
},
};
},
created() {

View File

@ -4,7 +4,7 @@
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="150px">
<el-form-item label="短信类型" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择短信签名" clearable size="small">
<el-select v-model="queryParams.type" placeholder="请选择短信类型" clearable size="small">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYS_SMS_TEMPLATE_TYPE)"
:key="dict.value" :label="dict.label" :value="dict.value"/>
</el-select>
@ -23,7 +23,9 @@
</el-form-item>
<el-form-item label="短信渠道编号" prop="channelId">
<el-select v-model="queryParams.channelId" placeholder="请选择短信渠道编号" clearable size="small">
<el-option label="请选择字典生成" value="" />
<el-option v-for="channel in channelOptions"
:key="channel.id" :value="channel.id"
:label="channel.signature + '【' + getDictDataLabel(DICT_TYPE.SYS_SMS_CHANNEL_CODE, channel.code) + '】'" />
</el-select>
</el-form-item>
<el-form-item label="创建时间">
@ -66,9 +68,10 @@
</el-table-column>>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="短信 API 的模板编号" align="center" prop="apiTemplateId" width="180" />
<el-table-column label="短信签名" align="center">
<el-table-column label="短信渠道" align="center">
<template slot-scope="scope">
<span>{{ getDictDataLabel(DICT_TYPE.SYS_SMS_CHANNEL_CODE, scope.row.channelCode) }}</span>
<div>{{ formatChannelSignature(scope.row.channelId) }}</div>
<div>{{ getDictDataLabel(DICT_TYPE.SYS_SMS_CHANNEL_CODE, scope.row.channelCode) }}</div>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
@ -76,8 +79,10 @@
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-share" @click="handleUpdate(scope.row)"
v-hasPermi="['system:sms-template:update']">测试</el-button>
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
v-hasPermi="['system:sms-template:update']">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
@ -91,39 +96,41 @@
<!-- 对话框(添加 / 修改) -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="短信签名" prop="type">
<el-select v-model="form.type" placeholder="请选择短信签名">
<el-form ref="form" :model="form" :rules="rules" label-width="140px">
<el-form-item label="短信渠道编号" prop="channelId">
<el-select v-model="form.channelId" placeholder="请选择短信渠道编号">
<el-option v-for="channel in channelOptions"
:key="channel.id" :value="channel.id"
:label="channel.signature + '【' + getDictDataLabel(DICT_TYPE.SYS_SMS_CHANNEL_CODE, channel.code) + '】'" />
</el-select>
</el-form-item>
<el-form-item label="短信类型" prop="type">
<el-select v-model="form.type" placeholder="请选择短信类型">
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYS_SMS_TEMPLATE_TYPE)"
:key="dict.value" :label="dict.label" :value="parseInt(dict.value)" />
</el-select>
</el-form-item>
<el-form-item label="开启状态">
<el-form-item label="模板编号" prop="code">
<el-input v-model="form.code" placeholder="请输入模板编号" />
</el-form-item>
<el-form-item label="模板名称" prop="name">
<el-input v-model="form.name" placeholder="请输入模板名称" />
</el-form-item>
<el-form-item label="模板内容" prop="content">
<el-input type="textarea" v-model="form.content" placeholder="请输入模板内容" />
</el-form-item>
<el-form-item label="开启状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.SYS_COMMON_STATUS)"
:key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="模板编码" prop="code">
<el-input v-model="form.code" placeholder="请输入模板编码" />
</el-form-item>
<el-form-item label="模板名称" prop="name">
<el-input v-model="form.name" placeholder="请输入模板名称" />
</el-form-item>
<el-form-item label="模板内容">
<el-input type="textarea" v-model="form.content" placeholder="请输入模板内容" />
<el-form-item label="短信 API 模板编号" prop="apiTemplateId">
<el-input v-model="form.apiTemplateId" placeholder="请输入短信 API 的模板编号" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" placeholder="请输入备注" />
</el-form-item>
<el-form-item label="短信 API 的模板编号" prop="apiTemplateId">
<el-input v-model="form.apiTemplateId" placeholder="请输入短信 API 的模板编号" />
</el-form-item>
<el-form-item label="短信渠道编号" prop="channelId">
<el-select v-model="form.channelId" placeholder="请选择短信渠道编号">
<el-option label="请选择字典生成" value="" />
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
@ -135,13 +142,10 @@
<script>
import { createSmsTemplate, updateSmsTemplate, deleteSmsTemplate, getSmsTemplate, getSmsTemplatePage, exportSmsTemplateExcel } from "@/api/system/sms/smsTemplate";
import Editor from '@/components/Editor';
import { getSimpleSmsChannels } from "@/api/system/sms/smsChannel";
export default {
name: "SmsTemplate",
components: {
Editor,
},
data() {
return {
//
@ -172,18 +176,24 @@ export default {
form: {},
//
rules: {
type: [{ required: true, message: "短信签名不能为空", trigger: "change" }],
type: [{ required: true, message: "短信类型不能为空", trigger: "change" }],
status: [{ required: true, message: "开启状态不能为空", trigger: "blur" }],
code: [{ required: true, message: "模板编码不能为空", trigger: "blur" }],
name: [{ required: true, message: "模板名称不能为空", trigger: "blur" }],
content: [{ required: true, message: "模板内容不能为空", trigger: "blur" }],
apiTemplateId: [{ required: true, message: "短信 API 的模板编号不能为空", trigger: "blur" }],
channelId: [{ required: true, message: "短信渠道编号不能为空", trigger: "change" }],
}
},
//
channelOptions: [],
};
},
created() {
this.getList();
//
getSimpleSmsChannels().then(response => {
this.channelOptions = response.data;
})
},
methods: {
/** 查询列表 */
@ -300,6 +310,15 @@ export default {
}).then(response => {
this.downloadExcel(response, '短信模板.xls');
})
},
/** 格式化短信渠道 */
formatChannelSignature(channelId) {
for (const channel of this.channelOptions) {
if (channel.id === channelId) {
return channel.signature;
}
}
return '找不到签名:' + channelId;
}
}
};

View File

@ -74,7 +74,7 @@ public class CommonResult<T> implements Serializable {
@JsonIgnore // 避免 jackson 序列化
public boolean isSuccess() {
return isSuccess(GlobalErrorCodeConstants.SUCCESS.getCode());
return isSuccess(code);
}
@JsonIgnore // 避免 jackson 序列化

View File

@ -15,17 +15,17 @@ public interface SmsFrameworkErrorCodeConstants {
ErrorCode SMS_CHANNEL_API_KEY_MISSING = new ErrorCode(2001000101, "API Key 不存在");
ErrorCode SMS_CHANNEL_PERMISSION_DENY = new ErrorCode(2001000102, "没有发送短信的权限");
// ========== 模板相关(200 开头) ==========
ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(200, "短信模板不存在");
ErrorCode SMS_TEMPLATE_DISABLE = new ErrorCode(201, "短信模板被禁用"); // 例如说我们在管理后台禁用了
ErrorCode SMS_TEMPLATE_INVALID = new ErrorCode(202, "短信模板不可用"); // 例如说短信模板正在审核中
ErrorCode SMS_TEMPLATE_PARAM_ERROR = new ErrorCode(203, "模板参数不正确");
// ========== 模板相关(2001000200 开头) ==========
ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(2001000200, "短信模板不存在");
ErrorCode SMS_TEMPLATE_DISABLE = new ErrorCode(2001000201, "短信模板被禁用"); // 例如说我们在管理后台禁用了
ErrorCode SMS_TEMPLATE_INVALID = new ErrorCode(2001000202, "短信模板不可用"); // 例如说短信模板正在审核中
ErrorCode SMS_TEMPLATE_PARAM_ERROR = new ErrorCode(2001000203, "模板参数不正确");
// ========== 其它相关(900 开头) ==========
ErrorCode SMS_API_PARAM_ERROR = new ErrorCode(900, "请求参数缺失");
// ========== 其它相关(2001000900 开头) ==========
ErrorCode SMS_API_PARAM_ERROR = new ErrorCode(2001000900, "请求参数缺失");
ErrorCode SMS_SEND_LIMIT_CONTROL = new ErrorCode(997, "业务限流"); // 将短信发送频率限制在正常的业务限流范围内默认短信验证码使用同一签名对同一个手机号验证码支持 1 / 分钟5 / 小时累计 10 /
ErrorCode EXCEPTION = new ErrorCode(998, "调用异常");
ErrorCode SMS_UNKNOWN = new ErrorCode(999, "未知错误,需要解析");
ErrorCode SMS_SEND_LIMIT_CONTROL = new ErrorCode(2001000997, "业务限流"); // 将短信发送频率限制在正常的业务限流范围内默认短信验证码使用同一签名对同一个手机号验证码支持 1 / 分钟5 / 小时累计 10 /
ErrorCode EXCEPTION = new ErrorCode(2001000998, "调用异常");
ErrorCode SMS_UNKNOWN = new ErrorCode(2001000999, "未知错误,需要解析");
}

View File

@ -61,7 +61,7 @@ public class SysDictDataController {
@GetMapping("/list-all-simple")
@ApiOperation(value = "获得全部字典数据列表", notes = "一般用于管理后台缓存字典数据在本地")
// 无需添加权限认证因为前端全局都需要
public CommonResult<List<SysDictDataSimpleVO>> getSimpleDictDatas() {
public CommonResult<List<SysDictDataSimpleRespVO>> getSimpleDictDatas() {
List<SysDictDataDO> list = dictDataService.getDictDatas();
return success(SysDictDataConvert.INSTANCE.convertList(list));
}

View File

@ -4,9 +4,9 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("数据字典精简 VO")
@ApiModel("数据字典精简 Response VO")
@Data
public class SysDictDataSimpleVO {
public class SysDictDataSimpleRespVO {
@ApiModelProperty(value = "字典类型", required = true, example = "gender")
private String dictType;

View File

@ -2,10 +2,7 @@ package cn.iocoder.dashboard.modules.system.controller.sms;
import cn.iocoder.dashboard.common.pojo.CommonResult;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.SysSmsChannelPageReqVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.SysSmsChannelRespVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.*;
import cn.iocoder.dashboard.modules.system.convert.sms.SysSmsChannelConvert;
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO;
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsChannelService;
@ -17,6 +14,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Comparator;
import java.util.List;
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
@ -69,4 +68,13 @@ public class SysSmsChannelController {
return success(SysSmsChannelConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/list-all-simple")
@ApiOperation(value = "获得短信渠道精简列表", notes = "包含被禁用的短信渠道")
public CommonResult<List<SysSmsChannelSimpleRespVO>> getSimpleSmsChannels() {
List<SysSmsChannelDO> list = smsChannelService.getSmsChannelList();
// 排序后返回给前端
list.sort(Comparator.comparing(SysSmsChannelDO::getId));
return success(SysSmsChannelConvert.INSTANCE.convertList03(list));
}
}

View File

@ -0,0 +1,12 @@
### 请求 /menu/list 接口 => 成功
POST {{baseUrl}}/system/sms-template/send-sms
Authorization: Bearer {{token}}
Content-Type: application/json
{
"code": "test_01",
"params": {
"key01": "value01",
"key02": "value02"
}
}

View File

@ -84,4 +84,11 @@ public class SysSmsTemplateController {
ExcelUtils.write(response, "短信模板.xls", "数据", SysSmsTemplateExcelVO.class, datas);
}
@PostMapping("/send-sms")
@ApiOperation("导出短信模板 Excel")
@PreAuthorize("@ss.hasPermission('system:sms-template:send-sms')")
public CommonResult<Boolean> sendSms(@Valid @RequestBody SysSmsTemplateSendReqVO sendReqVO) {
return success(true);
}
}

View File

@ -0,0 +1,24 @@
package cn.iocoder.dashboard.modules.system.controller.sms.vo.channel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
@ApiModel("短信渠道精简 Response VO")
@Data
public class SysSmsChannelSimpleRespVO {
@ApiModelProperty(value = "编号", required = true, example = "1024")
@NotNull(message = "编号不能为空")
private Long id;
@ApiModelProperty(value = "短信签名", required = true, example = "芋道源码")
@NotNull(message = "短信签名不能为空")
private String signature;
@ApiModelProperty(value = "渠道编码", required = true, example = "YUN_PIAN", notes = "参见 SmsChannelEnum 枚举类")
private String code;
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.dashboard.modules.system.controller.sms.vo.template;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.Map;
@ApiModel("短信模板的发送 Request VO")
@Data
public class SysSmsTemplateSendReqVO {
@ApiModelProperty(value = "模板编码", required = true, example = "test_01")
@NotNull(message = "模板编码不能为空")
private String code;
@ApiModelProperty(value = "模板参数")
private Map<String, Object> params;
}

View File

@ -13,7 +13,7 @@ public interface SysDictDataConvert {
SysDictDataConvert INSTANCE = Mappers.getMapper(SysDictDataConvert.class);
List<SysDictDataSimpleVO> convertList(List<SysDictDataDO> list);
List<SysDictDataSimpleRespVO> convertList(List<SysDictDataDO> list);
SysDictDataRespVO convert(SysDictDataDO bean);

View File

@ -4,6 +4,7 @@ import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperties;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.SysSmsChannelCreateReqVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.SysSmsChannelRespVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.SysSmsChannelSimpleRespVO;
import cn.iocoder.dashboard.modules.system.controller.sms.vo.channel.SysSmsChannelUpdateReqVO;
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO;
import org.mapstruct.Mapper;
@ -33,4 +34,6 @@ public interface SysSmsChannelConvert {
List<SmsChannelProperties> convertList02(List<SysSmsChannelDO> list);
List<SysSmsChannelSimpleRespVO> convertList03(List<SysSmsChannelDO> list);
}

View File

@ -31,7 +31,7 @@ public interface SysErrorCodeConstants {
// ========== 角色模块 1002003000 ==========
ErrorCode ROLE_NOT_EXISTS = new ErrorCode(1002003000, "角色不存在");
ErrorCode ROLE_NAME_DUPLICATE = new ErrorCode(1002003001, "已经存在名为【{}}】的角色");
ErrorCode ROLE_CODE_DUPLICATE = new ErrorCode(1002003002, "已经存在编码为【{}}】的角色");
ErrorCode ROLE_CODE_DUPLICATE = new ErrorCode(1002003002, "已经存在编码为【{}】的角色");
ErrorCode ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE = new ErrorCode(1002003004, "不能操作类型为系统内置的角色");
// ========== 用户模块 1002004000 ==========
@ -84,7 +84,7 @@ public interface SysErrorCodeConstants {
// ========== 短信模板 1002011000 ==========
ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(1002011000, "短信模板不存在");
ErrorCode SMS_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002011001, "已经存在编码为【{}}】的短信模板");
ErrorCode SMS_TEMPLATE_CODE_DUPLICATE = new ErrorCode(1002011001, "已经存在编码为【{}】的短信模板");
// ========== 短信发送 1002012000 ==========
ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1002012000, "手机号不存在");

View File

@ -61,6 +61,13 @@ public interface SysSmsChannelService {
*/
List<SysSmsChannelDO> getSmsChannelList(Collection<Long> ids);
/**
* 获得所有短信渠道列表
*
* @return 短信渠道列表
*/
List<SysSmsChannelDO> getSmsChannelList();
/**
* 获得短信渠道分页
*

View File

@ -90,6 +90,11 @@ public class SysSmsChannelServiceImpl implements SysSmsChannelService {
return smsChannelMapper.selectBatchIds(ids);
}
@Override
public List<SysSmsChannelDO> getSmsChannelList() {
return smsChannelMapper.selectList();
}
@Override
public PageResult<SysSmsChannelDO> getSmsChannelPage(SysSmsChannelPageReqVO pageReqVO) {
return smsChannelMapper.selectPage(pageReqVO);

View File

@ -162,10 +162,10 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService {
}
// 如果 id 为空说明不用比较是否为相同 id 的字典类型
if (id == null) {
throw exception(SMS_TEMPLATE_CODE_DUPLICATE);
throw exception(SMS_TEMPLATE_CODE_DUPLICATE, code);
}
if (!template.getId().equals(id)) {
throw exception(SMS_TEMPLATE_CODE_DUPLICATE);
throw exception(SMS_TEMPLATE_CODE_DUPLICATE, code);
}
}

View File

@ -137,7 +137,7 @@
</el-select>
</el-form-item>
#elseif($column.htmlType == "checkbox")## 多选框
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${javaField}">
<el-checkbox-group v-model="form.${javaField}">
#if ("" != $dictType)## 有数据字典
<el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
@ -148,7 +148,7 @@
</el-checkbox-group>
</el-form-item>
#elseif($column.htmlType == "radio")## 单选框
<el-form-item label="${comment}">
<el-form-item label="${comment}" prop="${javaField}">
<el-radio-group v-model="form.${javaField}">
#if ("" != $dictType)## 有数据字典
<el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"