index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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="execution">
  19. <basic-container>
  20. <avue-crud
  21. ref="crud"
  22. :page="page"
  23. :data="tableData"
  24. :permission="permissionList"
  25. :table-loading="tableLoading"
  26. :option="tableOption"
  27. @on-load="getList"
  28. @search-change="searchChange"
  29. @refresh-change="refreshChange"
  30. @row-update="handleUpdate"
  31. @row-save="handleSave"
  32. @row-del="rowDel"/>
  33. </basic-container>
  34. </div>
  35. </template>
  36. <script>
  37. import { addObj, delObj, fetchList, putObj } from '@/api/admin/tenant'
  38. import { tableOption } from '@/const/crud/admin/tenant'
  39. import { mapGetters } from 'vuex'
  40. export default {
  41. name: 'Tenant',
  42. data() {
  43. return {
  44. tableData: [],
  45. page: {
  46. total: 0, // 总页数
  47. currentPage: 1, // 当前页数
  48. pageSize: 20 // 每页显示多少条
  49. },
  50. tableLoading: false,
  51. tableOption: tableOption
  52. }
  53. },
  54. computed: {
  55. ...mapGetters(['permissions']),
  56. permissionList() {
  57. return {
  58. addBtn: this.vaildData(this.permissions.admin_systenant_add, false),
  59. delBtn: this.vaildData(this.permissions.admin_systenant_del, false),
  60. editBtn: this.vaildData(this.permissions.admin_systenant_edit, false)
  61. }
  62. }
  63. },
  64. methods: {
  65. getList(page, params) {
  66. this.tableLoading = true
  67. fetchList(Object.assign({
  68. current: page.currentPage,
  69. size: page.pageSize
  70. }, params)).then(response => {
  71. this.tableData = response.data.data.records
  72. this.page.total = response.data.data.total
  73. this.tableLoading = false
  74. }).catch(() => {
  75. this.tableLoading = false
  76. })
  77. },
  78. rowDel: function(row, index) {
  79. var _this = this
  80. this.$confirm('是否确认删除ID为' + row.id, '提示', {
  81. confirmButtonText: '确定',
  82. cancelButtonText: '取消',
  83. type: 'warning'
  84. }).then(function() {
  85. return delObj(row.id)
  86. }).then(data => {
  87. _this.tableData.splice(index, 1)
  88. _this.$message({
  89. showClose: true,
  90. message: '删除成功',
  91. type: 'success'
  92. })
  93. this.getList(this.page)
  94. })
  95. },
  96. /**
  97. * @title 数据更新
  98. * @param row 为当前的数据
  99. * @param index 为当前更新数据的行数
  100. * @param done 为表单关闭函数
  101. *
  102. **/
  103. handleUpdate: function(row, index, done, loading) {
  104. putObj(row).then(data => {
  105. this.tableData.splice(index, 1, Object.assign({}, row))
  106. this.$message({
  107. showClose: true,
  108. message: '修改成功',
  109. type: 'success'
  110. })
  111. done()
  112. this.getList(this.page)
  113. }).catch(() => {
  114. loading()
  115. })
  116. },
  117. /**
  118. * @title 数据添加
  119. * @param row 为当前的数据
  120. * @param done 为表单关闭函数
  121. *
  122. **/
  123. handleSave: function(row, done, loading) {
  124. addObj(row).then(data => {
  125. this.tableData.push(Object.assign({}, row))
  126. this.$message({
  127. showClose: true,
  128. message: '添加成功',
  129. type: 'success'
  130. })
  131. done()
  132. this.getList(this.page)
  133. }).catch(() => {
  134. loading()
  135. })
  136. },
  137. /**
  138. * 搜索回调
  139. */
  140. searchChange(form) {
  141. this.getList(this.page, form)
  142. },
  143. /**
  144. * 刷新回调
  145. */
  146. refreshChange() {
  147. this.getList(this.page)
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. </style>