sms.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page="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-check"
  33. size="small"
  34. v-if="permission.sms_enable"
  35. @click.stop="handleEnable(scope.row)">启用
  36. </el-button>
  37. </template>
  38. <template slot-scope="{row}"
  39. slot="status">
  40. <el-tag>{{row.statusName}}</el-tag>
  41. </template>
  42. <template slot-scope="{row}"
  43. slot="category">
  44. <el-tag>{{row.categoryName}}</el-tag>
  45. </template>
  46. </avue-crud>
  47. </basic-container>
  48. </template>
  49. <script>
  50. import {getList, getDetail, add, update, remove, enable} from "@/api/resource/sms";
  51. import {mapGetters} from "vuex";
  52. import func from "@/util/func";
  53. export default {
  54. data() {
  55. return {
  56. form: {},
  57. query: {},
  58. loading: true,
  59. page: {
  60. pageSize: 10,
  61. currentPage: 1,
  62. total: 0
  63. },
  64. selectionList: [],
  65. option: {
  66. height: 'auto',
  67. calcHeight: 30,
  68. tip: false,
  69. searchShow: true,
  70. searchMenuSpan: 6,
  71. border: true,
  72. index: true,
  73. viewBtn: true,
  74. selection: true,
  75. labelWidth: 100,
  76. dialogWidth: 880,
  77. column: [
  78. {
  79. label: "分类",
  80. type: "radio",
  81. value: 1,
  82. span: 24,
  83. width: 100,
  84. searchLabelWidth: 50,
  85. row: true,
  86. dicUrl: "/api/blade-system/dict/dictionary?code=sms",
  87. props: {
  88. label: "dictValue",
  89. value: "dictKey"
  90. },
  91. dataType: "number",
  92. slot: true,
  93. prop: "category",
  94. search: true,
  95. rules: [{
  96. required: true,
  97. message: "请选择分类",
  98. trigger: "blur"
  99. }]
  100. },
  101. {
  102. label: "资源编号",
  103. prop: "smsCode",
  104. span: 24,
  105. width: 200,
  106. search: true,
  107. rules: [{
  108. required: true,
  109. message: "请输入资源编号",
  110. trigger: "blur"
  111. }]
  112. },
  113. {
  114. label: "模版ID",
  115. prop: "templateId",
  116. span: 24,
  117. width: 200,
  118. search: true,
  119. rules: [{
  120. required: true,
  121. message: "请输入模版ID",
  122. trigger: "blur"
  123. }]
  124. },
  125. {
  126. label: "accessKey",
  127. prop: "accessKey",
  128. span: 24,
  129. overHidden: true,
  130. rules: [{
  131. required: true,
  132. message: "请输入accessKey",
  133. trigger: "blur"
  134. }],
  135. },
  136. {
  137. label: "secretKey",
  138. prop: "secretKey",
  139. span: 24,
  140. overHidden: true,
  141. display: true,
  142. rules: [{
  143. required: true,
  144. message: "请输入secretKey",
  145. trigger: "blur"
  146. }],
  147. },
  148. {
  149. label: "regionId",
  150. prop: "regionId",
  151. span: 24,
  152. hide: true,
  153. display: false
  154. },
  155. {
  156. label: "短信签名",
  157. prop: "signName",
  158. span: 24,
  159. rules: [{
  160. required: true,
  161. message: "请输入短信签名",
  162. trigger: "blur"
  163. }],
  164. },
  165. {
  166. label: "是否启用",
  167. prop: "status",
  168. span: 24,
  169. width: 80,
  170. slot: true,
  171. addDisplay: false,
  172. editDisplay: false,
  173. viewDisplay: false,
  174. },
  175. {
  176. label: "备注",
  177. prop: "remark",
  178. span: 24,
  179. hide: true
  180. },
  181. ]
  182. },
  183. data: []
  184. };
  185. },
  186. watch: {
  187. 'form.category'() {
  188. const category = func.toInt(this.form.category);
  189. this.$refs.crud.option.column.filter(item => {
  190. if (item.prop === "templateId") {
  191. if (category === 1) {
  192. item.label = "模版内容";
  193. } else {
  194. item.label = "模版ID";
  195. }
  196. }
  197. if (item.prop === "accessKey") {
  198. if (category === 1) {
  199. item.label = "apiKey";
  200. } else if (category === 4) {
  201. item.label = "appId";
  202. } else {
  203. item.label = "accessKey";
  204. }
  205. }
  206. if (item.prop === "secretKey") {
  207. item.display = category !== 1;
  208. if (category === 4) {
  209. item.label = "appKey";
  210. } else {
  211. item.label = "secretKey";
  212. }
  213. }
  214. if (item.prop === "regionId") {
  215. item.display = category === 3;
  216. }
  217. });
  218. }
  219. },
  220. computed: {
  221. ...mapGetters(["permission"]),
  222. permissionList() {
  223. return {
  224. addBtn: this.vaildData(this.permission.sms_add, false),
  225. viewBtn: this.vaildData(this.permission.sms_view, false),
  226. delBtn: this.vaildData(this.permission.sms_delete, false),
  227. editBtn: this.vaildData(this.permission.sms_edit, false)
  228. };
  229. },
  230. ids() {
  231. let ids = [];
  232. this.selectionList.forEach(ele => {
  233. ids.push(ele.id);
  234. });
  235. return ids.join(",");
  236. }
  237. },
  238. methods: {
  239. rowSave(row, loading, done) {
  240. add(row).then(() => {
  241. loading();
  242. this.onLoad(this.page);
  243. this.$message({
  244. type: "success",
  245. message: "操作成功!"
  246. });
  247. }, error => {
  248. done();
  249. console.log(error);
  250. });
  251. },
  252. rowUpdate(row, index, loading, done) {
  253. update(row).then(() => {
  254. loading();
  255. this.onLoad(this.page);
  256. this.$message({
  257. type: "success",
  258. message: "操作成功!"
  259. });
  260. }, error => {
  261. done();
  262. console.log(error);
  263. });
  264. },
  265. rowDel(row) {
  266. this.$confirm("确定将选择数据删除?", {
  267. confirmButtonText: "确定",
  268. cancelButtonText: "取消",
  269. type: "warning"
  270. })
  271. .then(() => {
  272. return remove(row.id);
  273. })
  274. .then(() => {
  275. this.onLoad(this.page);
  276. this.$message({
  277. type: "success",
  278. message: "操作成功!"
  279. });
  280. });
  281. },
  282. handleEnable(row) {
  283. this.$confirm("是否确定启用这条配置?", {
  284. confirmButtonText: "确定",
  285. cancelButtonText: "取消",
  286. type: "warning"
  287. })
  288. .then(() => {
  289. return enable(row.id);
  290. })
  291. .then(() => {
  292. this.onLoad(this.page);
  293. this.$message({
  294. type: "success",
  295. message: "操作成功!"
  296. });
  297. this.$refs.crud.toggleSelection();
  298. });
  299. },
  300. handleDelete() {
  301. if (this.selectionList.length === 0) {
  302. this.$message.warning("请选择至少一条数据");
  303. return;
  304. }
  305. this.$confirm("确定将选择数据删除?", {
  306. confirmButtonText: "确定",
  307. cancelButtonText: "取消",
  308. type: "warning"
  309. })
  310. .then(() => {
  311. return remove(this.ids);
  312. })
  313. .then(() => {
  314. this.onLoad(this.page);
  315. this.$message({
  316. type: "success",
  317. message: "操作成功!"
  318. });
  319. this.$refs.crud.toggleSelection();
  320. });
  321. },
  322. beforeOpen(done, type) {
  323. if (["edit", "view"].includes(type)) {
  324. getDetail(this.form.id).then(res => {
  325. this.form = res.data.data;
  326. });
  327. }
  328. done();
  329. },
  330. searchReset() {
  331. this.query = {};
  332. this.onLoad(this.page);
  333. },
  334. searchChange(params, done) {
  335. this.query = params;
  336. this.page.currentPage = 1;
  337. this.onLoad(this.page, params);
  338. done();
  339. },
  340. selectionChange(list) {
  341. this.selectionList = list;
  342. },
  343. selectionClear() {
  344. this.selectionList = [];
  345. this.$refs.crud.toggleSelection();
  346. },
  347. currentChange(currentPage) {
  348. this.page.currentPage = currentPage;
  349. },
  350. sizeChange(pageSize) {
  351. this.page.pageSize = pageSize;
  352. },
  353. refreshChange() {
  354. this.onLoad(this.page, this.query);
  355. },
  356. onLoad(page, params = {}) {
  357. this.loading = true;
  358. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  359. const data = res.data.data;
  360. this.page.total = data.total;
  361. this.data = data.records;
  362. this.loading = false;
  363. this.selectionClear();
  364. });
  365. }
  366. }
  367. };
  368. </script>