ProTable.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <script setup lang="ts">
  2. import { ElMessageBox } from 'element-plus'
  3. const props = defineProps({
  4. request: {
  5. type: Function,
  6. default: () => {}
  7. },
  8. pageSize: {
  9. type: Number,
  10. default: 10
  11. }
  12. })
  13. // ============== 查询部分开始 ===============
  14. const query = ref({})
  15. const handleQuery = () => {
  16. curPage.value = 1
  17. getTableData()
  18. }
  19. const handleReset = () => {
  20. query.value = {}
  21. }
  22. // ============== 查询部分结束 ===============
  23. // ============== 表格部分开始 ===============
  24. const tableData = ref([])
  25. const total = ref(0)
  26. const curPage = ref(1)
  27. const getTableData = () => {
  28. props
  29. .request({
  30. ...query.value,
  31. pageSize: props.pageSize,
  32. page: curPage.value
  33. })
  34. .then((res: any) => {
  35. tableData.value = res.data
  36. total.value = res.total
  37. })
  38. }
  39. getTableData()
  40. const pageChange = () => {
  41. getTableData()
  42. }
  43. // ============== 表格部分结束 ===============
  44. // ============== crud部分开始 ===============
  45. const handleCreate = () => {
  46. curPage.value = 1
  47. getTableData()
  48. }
  49. const handleUpdate = () => {
  50. query.value = {}
  51. }
  52. const handleDelete = () => {
  53. ElMessageBox.confirm('您确定要删除该项吗', '提示', {
  54. type: 'warning'
  55. }).then(() => {})
  56. }
  57. const handlePatchDelete = () => {}
  58. // ============== crud部分结束 ===============
  59. </script>
  60. <template>
  61. <div class="flex flex-col" style="height: calc(100vh - 100px)">
  62. <el-card class="mb-4" shadow="never">
  63. <el-form :inline="true">
  64. <slot name="queryBar" :query="query"></slot>
  65. <el-form-item>
  66. <el-button type="primary" icon="search" @click="handleQuery">查询</el-button>
  67. <el-button icon="i-ep-refresh" @click="handleReset">重置</el-button>
  68. </el-form-item>
  69. </el-form>
  70. </el-card>
  71. <el-card class="h-full flex-grow-1" :body-style="{ height: '100%' }" shadow="never">
  72. <div class="flex flex-col h-full">
  73. <div class="flex justify-between mb-20px">
  74. <div>
  75. <el-button type="primary" @click="handleCreate">新建</el-button>
  76. <el-button type="danger" @click="handlePatchDelete">删除</el-button>
  77. </div>
  78. </div>
  79. <el-table class="flex-grow-1 h-full" :data="tableData">
  80. <slot name="table"></slot>
  81. <el-table-column fixed="right" label="操作" width="120">
  82. <template #default>
  83. <el-button link type="primary" size="small" @click="handleUpdate">编辑</el-button>
  84. <el-button link type="danger" size="small" @click="handleDelete">删除</el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <div class="flex justify-end shrink-0">
  89. <el-pagination
  90. background
  91. layout="prev, pager, next"
  92. :page-size="pageSize"
  93. :total="total"
  94. @current-change="pageChange"
  95. class="mt-4"
  96. />
  97. </div>
  98. </div>
  99. </el-card>
  100. </div>
  101. </template>
  102. <style scoped>
  103. :deep(.el-table th.el-table__cell) {
  104. background-color: #f5f7fa;
  105. color: rgb(31, 34, 37);
  106. }
  107. </style>