index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索工作栏 -->
  4. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  5. <el-form-item label="模板名称" prop="name">
  6. <el-input v-model="queryParams.name" placeholder="请输入模板名称" clearable @keyup.enter.native="handleQuery"/>
  7. </el-form-item>
  8. <el-form-item label="模版编码" prop="code">
  9. <el-input v-model="queryParams.code" placeholder="请输入模版编码" clearable @keyup.enter.native="handleQuery"/>
  10. </el-form-item>
  11. <el-form-item label="状态" prop="status">
  12. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  13. <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
  14. :key="dict.value" :label="dict.label" :value="dict.value"/>
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="创建时间" prop="createTime">
  18. <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
  19. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  23. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  24. </el-form-item>
  25. </el-form>
  26. <!-- 操作工具栏 -->
  27. <el-row :gutter="10" class="mb8">
  28. <el-col :span="1.5">
  29. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  30. v-hasPermi="['system:notify-template:create']">新增</el-button>
  31. </el-col>
  32. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  33. </el-row>
  34. <!-- 列表 -->
  35. <el-table v-loading="loading" :data="list">
  36. <el-table-column label="模板编码" align="center" prop="code" />
  37. <el-table-column label="模板名称" align="center" prop="name" />
  38. <el-table-column label="类型" align="center" prop="type">
  39. <template v-slot="scope">
  40. <dict-tag :type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE" :value="scope.row.type" />
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="发送人名称" align="center" prop="nickname" />
  44. <el-table-column label="模板内容" align="center" prop="content" width="300" />
  45. <el-table-column label="开启状态" align="center" prop="status">
  46. <template slot-scope="scope">
  47. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="备注" align="center" prop="remark" />
  51. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  52. <template slot-scope="scope">
  53. <span>{{ parseTime(scope.row.createTime) }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
  57. <template slot-scope="scope">
  58. <el-button size="mini" type="text" icon="el-icon-share" @click="handleSendNotify(scope.row)"
  59. v-hasPermi="['system:notify-template:send-notify']">发送</el-button>
  60. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  61. v-hasPermi="['system:notify-template:update']">修改</el-button>
  62. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  63. v-hasPermi="['system:notify-template:delete']">删除</el-button>
  64. </template>
  65. </el-table-column>
  66. </el-table>
  67. <!-- 分页组件 -->
  68. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  69. @pagination="getList"/>
  70. <!-- 对话框(添加 / 修改) -->
  71. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  72. <el-form ref="form" :model="form" :rules="rules" label-width="140px">
  73. <el-form-item label="模板编号" prop="code">
  74. <el-input v-model="form.code" placeholder="请输入模板编号" />
  75. </el-form-item>
  76. <el-form-item label="模板名称" prop="name">
  77. <el-input v-model="form.name" placeholder="请输入模版名称" />
  78. </el-form-item>
  79. <el-form-item label="发件人名称" prop="nickname">
  80. <el-input v-model="form.nickname" placeholder="请输入发件人名称" />
  81. </el-form-item>
  82. <el-form-item label="模板内容" prop="content">
  83. <el-input type="textarea" v-model="form.content" placeholder="请输入模板内容" />
  84. </el-form-item>
  85. <el-form-item label="类型" prop="type">
  86. <el-select v-model="form.type" placeholder="请选择类型">
  87. <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE)"
  88. :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" />
  89. </el-select>
  90. </el-form-item>
  91. <el-form-item label="开启状态" prop="status">
  92. <el-radio-group v-model="form.status">
  93. <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
  94. :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
  95. </el-radio-group>
  96. </el-form-item>
  97. <el-form-item label="备注" prop="remark">
  98. <el-input v-model="form.remark" placeholder="请输入备注" />
  99. </el-form-item>
  100. </el-form>
  101. <div slot="footer" class="dialog-footer">
  102. <el-button type="primary" @click="submitForm">确 定</el-button>
  103. <el-button @click="cancel">取 消</el-button>
  104. </div>
  105. </el-dialog>
  106. <!-- 对话框(发送站内信) -->
  107. <el-dialog title="发送站内信" :visible.sync="sendNotifyOpen" width="500px" append-to-body>
  108. <el-form ref="sendNotifyForm" :model="sendNotifyForm" :rules="sendNotifyRules" label-width="140px">
  109. <el-form-item label="模板内容" prop="content">
  110. <el-input v-model="sendNotifyForm.content" type="textarea" placeholder="请输入模板内容" readonly />
  111. </el-form-item>
  112. <el-form-item label="接收人" prop="userId">
  113. <el-select v-model="sendNotifyForm.userId" placeholder="请输入接收人" clearable style="width: 100%">
  114. <el-option v-for="item in users" :key="parseInt(item.id)" :label="item.nickname" :value="parseInt(item.id)" />
  115. </el-select>
  116. </el-form-item>
  117. <el-form-item v-for="param in sendNotifyForm.params" :key="param" :label="'参数 {' + param + '}'" :prop="'templateParams.' + param">
  118. <el-input v-model="sendNotifyForm.templateParams[param]" :placeholder="'请输入 ' + param + ' 参数'" />
  119. </el-form-item>
  120. </el-form>
  121. <div slot="footer" class="dialog-footer">
  122. <el-button type="primary" @click="submitSendNotifyForm">确 定</el-button>
  123. <el-button @click="cancelSendNotify">取 消</el-button>
  124. </div>
  125. </el-dialog>
  126. </div>
  127. </template>
  128. <script>
  129. import { createNotifyTemplate, updateNotifyTemplate, deleteNotifyTemplate, getNotifyTemplate, getNotifyTemplatePage,
  130. sendNotify } from "@/api/system/notify/template";
  131. import {listSimpleUsers} from "@/api/system/user";
  132. import {CommonStatusEnum} from "@/utils/constants";
  133. export default {
  134. name: "NotifyTemplate",
  135. data() {
  136. return {
  137. // 遮罩层
  138. loading: true,
  139. // 显示搜索条件
  140. showSearch: true,
  141. // 总条数
  142. total: 0,
  143. // 短信模板列表
  144. list: [],
  145. // 弹出层标题
  146. title: "",
  147. // 是否显示弹出层
  148. open: false,
  149. // 查询参数
  150. queryParams: {
  151. pageNo: 1,
  152. pageSize: 10,
  153. status: null,
  154. code: null,
  155. title: null,
  156. createTime: []
  157. },
  158. // 表单参数
  159. form: {},
  160. // 表单校验
  161. rules: {
  162. name: [{ required: true, message: "模板名称不能为空", trigger: "blur" }],
  163. code: [{ required: true, message: "模版编码不能为空", trigger: "blur" }],
  164. nickname: [{ required: true, message: "发件人名称不能为空", trigger: "blur" }],
  165. content: [{ required: true, message: "模版内容不能为空", trigger: "blur" }],
  166. type: [{ required: true, message: "类型不能为空", trigger: "change" }],
  167. status: [{ required: true, message: "状态不能为空", trigger: "blur" }],
  168. },
  169. // 用户列表
  170. users: [],
  171. // 发送短信
  172. sendNotifyOpen: false,
  173. sendNotifyForm: {
  174. params: [], // 模板的参数列表
  175. },
  176. sendNotifyRules: {
  177. userId: [{ required: true, message: "接收人不能为空", trigger: "blur" }],
  178. templateCode: [{ required: true, message: "模版编号不能为空", trigger: "blur" }],
  179. templateParams: { }
  180. }
  181. };
  182. },
  183. created() {
  184. this.getList();
  185. // 获得用户列表
  186. listSimpleUsers().then(response => {
  187. this.users = response.data;
  188. })
  189. },
  190. methods: {
  191. /** 查询列表 */
  192. getList() {
  193. this.loading = true;
  194. // 执行查询
  195. getNotifyTemplatePage(this.queryParams).then(response => {
  196. this.list = response.data.list;
  197. this.total = response.data.total;
  198. this.loading = false;
  199. });
  200. },
  201. /** 取消按钮 */
  202. cancel() {
  203. this.open = false;
  204. this.reset();
  205. },
  206. /** 表单重置 */
  207. reset() {
  208. this.form = {
  209. id: undefined,
  210. name: undefined,
  211. code: undefined,
  212. nickname: undefined,
  213. content: undefined,
  214. type: undefined,
  215. params: undefined,
  216. status: CommonStatusEnum.ENABLE,
  217. remark: undefined,
  218. };
  219. this.resetForm("form");
  220. },
  221. /** 搜索按钮操作 */
  222. handleQuery() {
  223. this.queryParams.pageNo = 1;
  224. this.getList();
  225. },
  226. /** 重置按钮操作 */
  227. resetQuery() {
  228. this.resetForm("queryForm");
  229. this.handleQuery();
  230. },
  231. /** 新增按钮操作 */
  232. handleAdd() {
  233. this.reset();
  234. this.open = true;
  235. this.title = "添加站内信模板";
  236. },
  237. /** 修改按钮操作 */
  238. handleUpdate(row) {
  239. this.reset();
  240. const id = row.id;
  241. getNotifyTemplate(id).then(response => {
  242. this.form = response.data;
  243. this.open = true;
  244. this.title = "修改站内信模板";
  245. });
  246. },
  247. /** 提交按钮 */
  248. submitForm() {
  249. this.$refs["form"].validate(valid => {
  250. if (!valid) {
  251. return;
  252. }
  253. // 修改的提交
  254. if (this.form.id != null) {
  255. updateNotifyTemplate(this.form).then(response => {
  256. this.$modal.msgSuccess("修改成功");
  257. this.open = false;
  258. this.getList();
  259. });
  260. return;
  261. }
  262. // 添加的提交
  263. createNotifyTemplate(this.form).then(response => {
  264. this.$modal.msgSuccess("新增成功");
  265. this.open = false;
  266. this.getList();
  267. });
  268. });
  269. },
  270. /** 删除按钮操作 */
  271. handleDelete(row) {
  272. const id = row.id;
  273. this.$modal.confirm('是否确认删除站内信模板编号为"' + id + '"的数据项?').then(function() {
  274. return deleteNotifyTemplate(id);
  275. }).then(() => {
  276. this.getList();
  277. this.$modal.msgSuccess("删除成功");
  278. }).catch(() => {});
  279. },
  280. /** 发送站内信按钮 */
  281. handleSendNotify(row) {
  282. this.resetSendNotify(row);
  283. // 设置参数
  284. this.sendNotifyForm.content = row.content;
  285. this.sendNotifyForm.params = row.params;
  286. this.sendNotifyForm.templateCode = row.code;
  287. this.sendNotifyForm.templateParams = row.params.reduce(function(obj, item) {
  288. obj[item] = undefined;
  289. return obj;
  290. }, {});
  291. // 根据 row 重置 rules
  292. this.sendNotifyRules.templateParams = row.params.reduce(function(obj, item) {
  293. obj[item] = { required: true, message: '参数 ' + item + " 不能为空", trigger: "change" };
  294. return obj;
  295. }, {});
  296. // 设置打开
  297. this.sendNotifyOpen = true;
  298. },
  299. /** 重置发送站内信的表单 */
  300. resetSendNotify() {
  301. // 根据 row 重置表单
  302. this.sendNotifyForm = {
  303. content: undefined,
  304. params: undefined,
  305. userId: undefined,
  306. templateCode: undefined,
  307. templateParams: {}
  308. };
  309. this.resetForm("sendNotifyForm");
  310. },
  311. /** 取消发送站内信 */
  312. cancelSendNotify() {
  313. this.sendNotifyOpen = false;
  314. this.resetSendNotify();
  315. },
  316. /** 提交按钮 */
  317. submitSendNotifyForm() {
  318. this.$refs["sendNotifyForm"].validate(valid => {
  319. if (!valid) {
  320. return;
  321. }
  322. // 添加的提交
  323. sendNotify(this.sendNotifyForm).then(response => {
  324. this.$modal.msgSuccess("提交发送成功!发送结果,见发送日志编号:" + response.data);
  325. this.sendNotifyOpen = false;
  326. });
  327. });
  328. },
  329. }
  330. };
  331. </script>