index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <!--
  2. - Copyright (c) 2018-2025, lengleng All rights reserved.
  3. -
  4. - Redistribution and use in source and binary forms, with or without
  5. - modification, are permitted provided that the following conditions are met:
  6. -
  7. - Redistributions of source code must retain the above copyright notice,
  8. - this list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright
  10. - notice, this list of conditions and the following disclaimer in the
  11. - documentation and/or other materials provided with the distribution.
  12. - Neither the name of the pig4cloud.com developer nor the names of its
  13. - contributors may be used to endorse or promote products derived from
  14. - this software without specific prior written permission.
  15. - Author: lengleng (wangiegie@gmail.com)
  16. -->
  17. <template>
  18. <div class="app-container pull-auto">
  19. <basic-container>
  20. <avue-crud ref="crud"
  21. :page="page"
  22. :data="tableData"
  23. :table-loading="tableLoading"
  24. :option="tableOption"
  25. @on-load="getList"
  26. @row-update="handleUpdate"
  27. @row-save="handleSave"
  28. @search-change="searchChange"
  29. @row-del="rowDel">
  30. <template slot-scope="scope"
  31. slot="menu">
  32. <el-button type="primary"
  33. v-if="permissions.sys_dict_edit"
  34. icon="el-icon-check"
  35. size="mini"
  36. plain
  37. @click="handleEdit(scope.row,scope.index)">编辑</el-button>
  38. <el-button type="danger"
  39. v-if="permissions.sys_dict_del"
  40. icon="el-icon-delete"
  41. size="mini"
  42. plain
  43. @click="handleDel(scope.row,scope.index)">删除</el-button>
  44. </template>
  45. </avue-crud>
  46. </basic-container>
  47. </div>
  48. </template>
  49. <script>
  50. import { fetchList, addObj, putObj, delObj } from '@/api/dict'
  51. import { tableOption } from '@/const/crud/dict'
  52. import { mapGetters } from 'vuex'
  53. export default {
  54. name: 'dict',
  55. data () {
  56. return {
  57. tableData: [],
  58. page: {
  59. total: 0, // 总页数
  60. currentPage: 1, // 当前页数
  61. pageSize: 20 // 每页显示多少条
  62. },
  63. tableLoading: false,
  64. tableOption: tableOption
  65. }
  66. },
  67. created () {
  68. },
  69. mounted: function () { },
  70. computed: {
  71. ...mapGetters(['permissions'])
  72. },
  73. methods: {
  74. getList (page,params) {
  75. this.tableLoading = true
  76. fetchList(Object.assign({
  77. page: page.currentPage,
  78. limit: page.pageSize
  79. }, params)).then(response => {
  80. this.tableData = response.data.data.records
  81. this.page.total = response.data.data.total
  82. this.tableLoading = false
  83. })
  84. },
  85. /**
  86. * @title 打开新增窗口
  87. * @detail 调用crud的handleadd方法即可
  88. *
  89. **/
  90. handleAdd: function () {
  91. this.$refs.crud.rowAdd()
  92. },
  93. handleEdit (row, index) {
  94. this.$refs.crud.rowEdit(row, index)
  95. },
  96. handleDel (row, index) {
  97. this.$refs.crud.rowDel(row, index)
  98. },
  99. rowDel: function (row, index) {
  100. var _this = this
  101. this.$confirm('是否确认删除标签名为"' + row.label + '",数据类型为"' + row.type + '"的数据项?', '警告', {
  102. confirmButtonText: '确定',
  103. cancelButtonText: '取消',
  104. type: 'warning'
  105. })
  106. .then(function () {
  107. return delObj(row)
  108. })
  109. .then(() => {
  110. this.getList(this.page)
  111. _this.$message({
  112. showClose: true,
  113. message: '删除成功',
  114. type: 'success'
  115. })
  116. })
  117. .catch(function () { })
  118. },
  119. /**
  120. * @title 数据更新
  121. * @param row 为当前的数据
  122. * @param index 为当前更新数据的行数
  123. * @param done 为表单关闭函数
  124. *
  125. **/
  126. handleUpdate: function (row, index, done) {
  127. putObj(row).then(() => {
  128. this.tableData.splice(index, 1, Object.assign({}, row))
  129. this.$message({
  130. showClose: true,
  131. message: '修改成功',
  132. type: 'success'
  133. })
  134. this.getList(this.page)
  135. done()
  136. })
  137. },
  138. /**
  139. * @title 数据添加
  140. * @param row 为当前的数据
  141. * @param done 为表单关闭函数
  142. *
  143. **/
  144. handleSave: function (row, done) {
  145. addObj(row).then(data => {
  146. this.tableData.push(Object.assign({}, row))
  147. this.$message({
  148. showClose: true,
  149. message: '添加成功',
  150. type: 'success'
  151. })
  152. this.getList(this.page)
  153. done()
  154. })
  155. },
  156. searchChange (form) {
  157. this.getList(this.page,form)
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. </style>