index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 ref="crud"
  21. :page="page"
  22. :data="tableData"
  23. :table-loading="tableLoading"
  24. :option="tableOption"
  25. @on-load="getList"
  26. @refresh-change="refreshChange"
  27. @row-update="handleUpdate"
  28. @row-save="handleSave"
  29. @row-del="rowDel">
  30. <template slot-scope="scope"
  31. slot="menu">
  32. <el-button type="text"
  33. v-if="permissions.sys_client_edit"
  34. icon="el-icon-check"
  35. size="mini"
  36. plain
  37. @click="handleEdit(scope.row,scope.index)">编辑</el-button>
  38. <el-button type="text"
  39. v-if="permissions.sys_client_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/admin/client'
  51. import { tableOption } from '@/const/crud/admin/client'
  52. import { mapGetters } from 'vuex'
  53. export default {
  54. name: 'client',
  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. current: page.currentPage,
  78. size: 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('是否确认删除ID为' + row.clientId, '提示', {
  102. confirmButtonText: '确定',
  103. cancelButtonText: '取消',
  104. type: 'warning'
  105. })
  106. .then(function() {
  107. return delObj(row.clientId)
  108. })
  109. .then(data => {
  110. _this.tableData.splice(index, 1)
  111. _this.$message({
  112. showClose: true,
  113. message: '删除成功',
  114. type: 'success'
  115. })
  116. this.refreshChange()
  117. })
  118. .catch(function(err) { })
  119. },
  120. /**
  121. * @title 数据更新
  122. * @param row 为当前的数据
  123. * @param index 为当前更新数据的行数
  124. * @param done 为表单关闭函数
  125. *
  126. **/
  127. handleUpdate: function(row, index, done) {
  128. putObj(row).then(data => {
  129. this.tableData.splice(index, 1, Object.assign({}, row))
  130. this.$message({
  131. showClose: true,
  132. message: '修改成功',
  133. type: 'success'
  134. })
  135. this.refreshChange()
  136. done()
  137. })
  138. },
  139. /**
  140. * @title 数据添加
  141. * @param row 为当前的数据
  142. * @param done 为表单关闭函数
  143. *
  144. **/
  145. handleSave: function(row, done) {
  146. addObj(row).then(data => {
  147. this.tableData.push(Object.assign({}, row))
  148. this.$message({
  149. showClose: true,
  150. message: '添加成功',
  151. type: 'success'
  152. })
  153. this.refreshChange()
  154. done()
  155. })
  156. },
  157. /**
  158. * 刷新回调
  159. */
  160. refreshChange() {
  161. this.getList(this.page)
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. </style>