KtTable.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div>
  3. <!--表格栏-->
  4. <el-table :data="data.content" :highlight-current-row="highlightCurrentRow" @selection-change="selectionChange"
  5. @current-change="handleCurrentChange" v-loading="loading" :element-loading-text="$t('action.loading')" :border="border" :stripe="stripe"
  6. :show-overflow-tooltip="showOverflowTooltip" :max-height="maxHeight" :height="height" :size="size" :align="align" style="width:100%;" >
  7. <el-table-column type="selection" width="40" v-if="showBatchDelete & showOperation"></el-table-column>
  8. <el-table-column v-for="column in columns" header-align="center" align="center"
  9. :prop="column.prop" :label="column.label" :width="column.width" :min-width="column.minWidth"
  10. :fixed="column.fixed" :key="column.prop" :type="column.type" :formatter="column.formatter"
  11. :sortable="column.sortable==null?true:column.sortable">
  12. </el-table-column>
  13. <el-table-column :label="$t('action.operation')" width="185" fixed="right" v-if="showOperation" header-align="center" align="center">
  14. <template slot-scope="scope">
  15. <kt-button icon="fa fa-edit" :label="$t('action.edit')" :perms="permsEdit" :size="size" @click="handleEdit(scope.$index, scope.row)" />
  16. <kt-button icon="fa fa-trash" :label="$t('action.delete')" :perms="permsDelete" :size="size" type="danger" @click="handleDelete(scope.$index, scope.row)" />
  17. </template>
  18. </el-table-column>
  19. </el-table>
  20. <!--分页栏-->
  21. <div class="toolbar" style="padding:10px;">
  22. <kt-button :label="$t('action.batchDelete')" :perms="permsDelete" :size="size" type="danger" @click="handleBatchDelete()"
  23. :disabled="this.selections.length===0" style="float:left;" v-if="showBatchDelete & showOperation"/>
  24. <el-pagination layout="total, prev, pager, next, jumper" @current-change="refreshPageRequest"
  25. :current-page="pageRequest.pageNum" :page-size="pageRequest.pageSize" :total="data.totalSize" style="float:right;">
  26. </el-pagination>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import KtButton from "@/views/Core/KtButton"
  32. export default {
  33. name: 'KtTable',
  34. components:{
  35. KtButton
  36. },
  37. props: {
  38. columns: Array, // 表格列配置
  39. data: Object, // 表格分页数据
  40. permsEdit: String, // 编辑权限标识
  41. permsDelete: String, // 删除权限标识
  42. size: { // 尺寸样式
  43. type: String,
  44. default: 'mini'
  45. },
  46. align: { // 文本对齐方式
  47. type: String,
  48. default: 'left'
  49. },
  50. maxHeight: { // 表格最大高度
  51. type: Number,
  52. default: 420
  53. },
  54. height: { // 表格最大高度
  55. type: Number,
  56. default: 250
  57. },
  58. showOperation: { // 是否显示操作组件
  59. type: Boolean,
  60. default: true
  61. },
  62. border: { // 是否显示边框
  63. type: Boolean,
  64. default: true
  65. },
  66. stripe: { // 是否显示斑马线
  67. type: Boolean,
  68. default: true
  69. },
  70. highlightCurrentRow: { // // 是否高亮当前行
  71. type: Boolean,
  72. default: true
  73. },
  74. showOverflowTooltip: { // 是否单行显示
  75. type: Boolean,
  76. default: true
  77. },
  78. showBatchDelete: { // 是否显示操作组件
  79. type: Boolean,
  80. default: true
  81. }
  82. },
  83. data() {
  84. return {
  85. // 分页信息
  86. pageRequest: {
  87. pageNum: 1,
  88. pageSize: 10
  89. },
  90. loading: false, // 加载标识
  91. selections: [] // 列表选中列
  92. }
  93. },
  94. methods: {
  95. // 分页查询
  96. findPage: function () {
  97. this.loading = true
  98. let callback = res => {
  99. this.loading = false
  100. }
  101. this.$emit('findPage', {pageRequest:this.pageRequest, callback:callback})
  102. },
  103. // 选择切换
  104. selectionChange: function (selections) {
  105. this.selections = selections
  106. this.$emit('selectionChange', {selections:selections})
  107. },
  108. // 选择切换
  109. handleCurrentChange: function (val) {
  110. this.$emit('handleCurrentChange', {val:val})
  111. },
  112. // 换页刷新
  113. refreshPageRequest: function (pageNum) {
  114. this.pageRequest.pageNum = pageNum
  115. this.findPage()
  116. },
  117. // 编辑
  118. handleEdit: function (index, row) {
  119. this.$emit('handleEdit', {index:index, row:row})
  120. },
  121. // 删除
  122. handleDelete: function (index, row) {
  123. this.delete(row.id)
  124. },
  125. // 批量删除
  126. handleBatchDelete: function () {
  127. let ids = this.selections.map(item => item.id).toString()
  128. this.delete(ids)
  129. },
  130. // 删除操作
  131. delete: function (ids) {
  132. this.$confirm('确认删除选中记录吗?', '提示', {
  133. type: 'warning'
  134. }).then(() => {
  135. let params = []
  136. let idArray = (ids+'').split(',')
  137. for(var i=0; i<idArray.length; i++) {
  138. params.push({'id':idArray[i]})
  139. }
  140. this.loading = true
  141. let callback = res => {
  142. if(res.code == 200) {
  143. this.$message({message: '删除成功', type: 'success'})
  144. this.findPage()
  145. } else {
  146. this.$message({message: '操作失败, ' + res.msg, type: 'error'})
  147. }
  148. this.loading = false
  149. }
  150. this.$emit('handleDelete', {params:params, callback:callback})
  151. }).catch(() => {
  152. })
  153. }
  154. },
  155. mounted() {
  156. this.refreshPageRequest(1)
  157. }
  158. }
  159. </script>
  160. <style scoped>
  161. </style>