sms.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page.sync="page"
  7. :permission="permissionList"
  8. :before-open="beforeOpen"
  9. v-model="form"
  10. ref="crud"
  11. @row-update="rowUpdate"
  12. @row-save="rowSave"
  13. @row-del="rowDel"
  14. @search-change="searchChange"
  15. @search-reset="searchReset"
  16. @selection-change="selectionChange"
  17. @current-change="currentChange"
  18. @size-change="sizeChange"
  19. @refresh-change="refreshChange"
  20. @on-load="onLoad">
  21. <template slot="menuLeft">
  22. <el-button type="danger"
  23. size="small"
  24. icon="el-icon-delete"
  25. plain
  26. v-if="permission.sms_delete"
  27. @click="handleDelete">删 除
  28. </el-button>
  29. </template>
  30. <template slot-scope="scope" slot="menu">
  31. <el-button type="text"
  32. icon="el-icon-video-play"
  33. size="small"
  34. v-if="userInfo.role_name.includes('admin')"
  35. @click="handleDebug(scope.row)">调试
  36. </el-button>
  37. <el-button type="text"
  38. icon="el-icon-circle-check"
  39. size="small"
  40. v-if="permission.sms_enable"
  41. @click.stop="handleEnable(scope.row)">启用
  42. </el-button>
  43. </template>
  44. <template slot-scope="{row}"
  45. slot="status">
  46. <el-tag>{{row.statusName}}</el-tag>
  47. </template>
  48. <template slot-scope="{row}"
  49. slot="category">
  50. <el-tag>{{row.categoryName}}</el-tag>
  51. </template>
  52. </avue-crud>
  53. <el-dialog title="手机短信发送调试"
  54. append-to-body
  55. :visible.sync="box"
  56. width="550px">
  57. <avue-form :option="debugOption" v-model="debugForm" @submit="handleSend"/>
  58. </el-dialog>
  59. </basic-container>
  60. </template>
  61. <script>
  62. import {getList, getDetail, add, update, remove, enable, send} from "@/api/resource/sms";
  63. import {mapGetters} from "vuex";
  64. import func from "@/util/func";
  65. export default {
  66. data() {
  67. return {
  68. form: {},
  69. query: {},
  70. loading: true,
  71. box: false,
  72. page: {
  73. pageSize: 10,
  74. currentPage: 1,
  75. total: 0
  76. },
  77. selectionList: [],
  78. option: {
  79. height: 'auto',
  80. calcHeight: 30,
  81. tip: false,
  82. searchShow: true,
  83. searchMenuSpan: 6,
  84. border: true,
  85. index: true,
  86. viewBtn: true,
  87. selection: true,
  88. menuWidth: 300,
  89. labelWidth: 100,
  90. dialogWidth: 880,
  91. dialogClickModal: false,
  92. column: [
  93. {
  94. label: "分类",
  95. type: "radio",
  96. value: 1,
  97. span: 24,
  98. width: 100,
  99. searchLabelWidth: 50,
  100. row: true,
  101. dicUrl: "/api/blade-system/dict/dictionary?code=sms",
  102. props: {
  103. label: "dictValue",
  104. value: "dictKey"
  105. },
  106. dataType: "number",
  107. slot: true,
  108. prop: "category",
  109. search: true,
  110. rules: [{
  111. required: true,
  112. message: "请选择分类",
  113. trigger: "blur"
  114. }]
  115. },
  116. {
  117. label: "资源编号",
  118. prop: "smsCode",
  119. span: 24,
  120. width: 200,
  121. search: true,
  122. rules: [{
  123. required: true,
  124. message: "请输入资源编号",
  125. trigger: "blur"
  126. }]
  127. },
  128. {
  129. label: "模版ID",
  130. prop: "templateId",
  131. span: 24,
  132. width: 200,
  133. search: true,
  134. rules: [{
  135. required: true,
  136. message: "请输入模版ID",
  137. trigger: "blur"
  138. }]
  139. },
  140. {
  141. label: "accessKey",
  142. prop: "accessKey",
  143. span: 24,
  144. overHidden: true,
  145. rules: [{
  146. required: true,
  147. message: "请输入accessKey",
  148. trigger: "blur"
  149. }],
  150. },
  151. {
  152. label: "secretKey",
  153. prop: "secretKey",
  154. span: 24,
  155. overHidden: true,
  156. display: true,
  157. hide: true,
  158. rules: [{
  159. required: true,
  160. message: "请输入secretKey",
  161. trigger: "blur"
  162. }],
  163. },
  164. {
  165. label: "regionId",
  166. prop: "regionId",
  167. span: 24,
  168. value: "cn-hangzhou",
  169. hide: true,
  170. display: false
  171. },
  172. {
  173. label: "短信签名",
  174. prop: "signName",
  175. span: 24,
  176. width: 200,
  177. rules: [{
  178. required: true,
  179. message: "请输入短信签名",
  180. trigger: "blur"
  181. }],
  182. },
  183. {
  184. label: "是否启用",
  185. prop: "status",
  186. span: 24,
  187. width: 80,
  188. align: "center",
  189. slot: true,
  190. addDisplay: false,
  191. editDisplay: false,
  192. viewDisplay: false,
  193. },
  194. {
  195. label: "备注",
  196. prop: "remark",
  197. span: 24,
  198. hide: true
  199. },
  200. ]
  201. },
  202. data: [],
  203. debugForm: {
  204. code: '',
  205. },
  206. debugOption: {
  207. submitText: "发送",
  208. column: [
  209. {
  210. label: "资源编号",
  211. prop: "code",
  212. disabled: true,
  213. span: 24,
  214. },
  215. {
  216. label: "发送手机",
  217. prop: "phones",
  218. span: 24,
  219. },
  220. {
  221. label: "发送参数",
  222. prop: "params",
  223. span: 24,
  224. placeholder: "例: {'code':2333,'title':'通知标题'}",
  225. },
  226. ]
  227. }
  228. };
  229. },
  230. watch: {
  231. 'form.category'() {
  232. const category = func.toInt(this.form.category);
  233. this.$refs.crud.option.column.filter(item => {
  234. if (item.prop === "templateId") {
  235. if (category === 1) {
  236. item.label = "模版内容";
  237. } else {
  238. item.label = "模版ID";
  239. }
  240. }
  241. if (item.prop === "accessKey") {
  242. if (category === 1) {
  243. item.label = "apiKey";
  244. } else if (category === 4) {
  245. item.label = "appId";
  246. } else {
  247. item.label = "accessKey";
  248. }
  249. }
  250. if (item.prop === "secretKey") {
  251. item.display = category !== 1;
  252. if (category === 4) {
  253. item.label = "appKey";
  254. } else {
  255. item.label = "secretKey";
  256. }
  257. }
  258. if (item.prop === "regionId") {
  259. if (category === 3) {
  260. item.display = true;
  261. item.value = "cn-hangzhou";
  262. } else {
  263. item.display = false;
  264. }
  265. }
  266. });
  267. }
  268. },
  269. computed: {
  270. ...mapGetters(["userInfo", "permission"]),
  271. permissionList() {
  272. return {
  273. addBtn: this.vaildData(this.permission.sms_add, false),
  274. viewBtn: this.vaildData(this.permission.sms_view, false),
  275. delBtn: this.vaildData(this.permission.sms_delete, false),
  276. editBtn: this.vaildData(this.permission.sms_edit, false)
  277. };
  278. },
  279. ids() {
  280. let ids = [];
  281. this.selectionList.forEach(ele => {
  282. ids.push(ele.id);
  283. });
  284. return ids.join(",");
  285. }
  286. },
  287. methods: {
  288. rowSave(row, done, loading) {
  289. add(row).then(() => {
  290. this.onLoad(this.page);
  291. this.$message({
  292. type: "success",
  293. message: "操作成功!"
  294. });
  295. done();
  296. }, error => {
  297. window.console.log(error);
  298. loading();
  299. });
  300. },
  301. rowUpdate(row, index, done, loading) {
  302. update(row).then(() => {
  303. this.onLoad(this.page);
  304. this.$message({
  305. type: "success",
  306. message: "操作成功!"
  307. });
  308. done();
  309. }, error => {
  310. window.console.log(error);
  311. loading();
  312. });
  313. },
  314. rowDel(row) {
  315. this.$confirm("确定将选择数据删除?", {
  316. confirmButtonText: "确定",
  317. cancelButtonText: "取消",
  318. type: "warning"
  319. })
  320. .then(() => {
  321. return remove(row.id);
  322. })
  323. .then(() => {
  324. this.onLoad(this.page);
  325. this.$message({
  326. type: "success",
  327. message: "操作成功!"
  328. });
  329. });
  330. },
  331. handleEnable(row) {
  332. this.$confirm("是否确定启用这条配置?", {
  333. confirmButtonText: "确定",
  334. cancelButtonText: "取消",
  335. type: "warning"
  336. })
  337. .then(() => {
  338. return enable(row.id);
  339. })
  340. .then(() => {
  341. this.onLoad(this.page);
  342. this.$message({
  343. type: "success",
  344. message: "操作成功!"
  345. });
  346. this.$refs.crud.toggleSelection();
  347. });
  348. },
  349. handleDebug(row) {
  350. this.box = true;
  351. this.debugForm.code = row.smsCode;
  352. },
  353. handleSend(form, done, loading) {
  354. send(form.code, form.phones, form.params).then((res) => {
  355. this.$message({
  356. type: "success",
  357. message: "发送成功!"
  358. });
  359. done();
  360. window.console.log(res);
  361. this.box = false;
  362. }, error => {
  363. window.console.log(error);
  364. loading();
  365. });
  366. },
  367. handleDelete() {
  368. if (this.selectionList.length === 0) {
  369. this.$message.warning("请选择至少一条数据");
  370. return;
  371. }
  372. this.$confirm("确定将选择数据删除?", {
  373. confirmButtonText: "确定",
  374. cancelButtonText: "取消",
  375. type: "warning"
  376. })
  377. .then(() => {
  378. return remove(this.ids);
  379. })
  380. .then(() => {
  381. this.onLoad(this.page);
  382. this.$message({
  383. type: "success",
  384. message: "操作成功!"
  385. });
  386. this.$refs.crud.toggleSelection();
  387. });
  388. },
  389. beforeOpen(done, type) {
  390. if (["edit", "view"].includes(type)) {
  391. getDetail(this.form.id).then(res => {
  392. this.form = res.data.data;
  393. });
  394. }
  395. done();
  396. },
  397. searchReset() {
  398. this.query = {};
  399. this.onLoad(this.page);
  400. },
  401. searchChange(params, done) {
  402. this.query = params;
  403. this.page.currentPage = 1;
  404. this.onLoad(this.page, params);
  405. done();
  406. },
  407. selectionChange(list) {
  408. this.selectionList = list;
  409. },
  410. selectionClear() {
  411. this.selectionList = [];
  412. this.$refs.crud.toggleSelection();
  413. },
  414. currentChange(currentPage) {
  415. this.page.currentPage = currentPage;
  416. },
  417. sizeChange(pageSize) {
  418. this.page.pageSize = pageSize;
  419. },
  420. refreshChange() {
  421. this.onLoad(this.page, this.query);
  422. },
  423. onLoad(page, params = {}) {
  424. this.loading = true;
  425. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  426. const data = res.data.data;
  427. this.page.total = data.total;
  428. this.data = data.records;
  429. this.loading = false;
  430. this.selectionClear();
  431. });
  432. }
  433. }
  434. };
  435. </script>