index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div>
  3. <el-alert
  4. effect="dark"
  5. :closable="false"
  6. title="基于 Element 的 Table 组件进行二次封装,实现数据驱动,支持所有 Table 参数 -- 固定列和表头"
  7. type="info"
  8. style="margin-bottom: 20px;"
  9. />
  10. <com-table
  11. v-loading="loading"
  12. :columns="columns"
  13. :data="tableData"
  14. border
  15. height="250"
  16. style="width: 820px;"
  17. >
  18. <template #action="scope">
  19. <el-button type="text" size="small" @click="handleClick(scope.row)">查看</el-button>
  20. <el-button type="text" size="small">编辑</el-button>
  21. </template>
  22. </com-table>
  23. </div>
  24. </template>
  25. <script lang="ts">
  26. import { defineComponent, ref } from 'vue'
  27. import ComTable from '_c/Table/index.vue'
  28. const columns = [
  29. {
  30. key: 'date',
  31. label: '日期',
  32. fixed: true,
  33. width: '150'
  34. },
  35. {
  36. key: 'name',
  37. label: '姓名',
  38. width: '120'
  39. },
  40. {
  41. key: 'province',
  42. label: '省份',
  43. width: '120'
  44. },
  45. {
  46. key: 'city',
  47. label: '市区',
  48. width: '120'
  49. },
  50. {
  51. key: 'address',
  52. label: '地址',
  53. width: '300'
  54. },
  55. {
  56. key: 'zip',
  57. label: '邮编',
  58. width: '120'
  59. },
  60. {
  61. key: 'action',
  62. label: '操作',
  63. width: '100',
  64. fixed: 'right',
  65. slots: {
  66. default: 'action'
  67. }
  68. }
  69. ]
  70. const tableData = [
  71. {
  72. date: '2016-05-02',
  73. name: '王小虎',
  74. province: '上海',
  75. city: '普陀区',
  76. address: '上海市普陀区金沙江路 1518 弄',
  77. zip: 200333
  78. },
  79. {
  80. date: '2016-05-04',
  81. name: '王小虎',
  82. province: '上海',
  83. city: '普陀区',
  84. address: '上海市普陀区金沙江路 1517 弄',
  85. zip: 200333
  86. },
  87. {
  88. date: '2016-05-01',
  89. name: '王小虎',
  90. province: '上海',
  91. city: '普陀区',
  92. address: '上海市普陀区金沙江路 1519 弄',
  93. zip: 200333
  94. },
  95. {
  96. date: '2016-05-03',
  97. name: '王小虎',
  98. province: '上海',
  99. city: '普陀区',
  100. address: '上海市普陀区金沙江路 1516 弄',
  101. zip: 200333
  102. },
  103. {
  104. date: '2016-05-02',
  105. name: '王小虎',
  106. province: '上海',
  107. city: '普陀区',
  108. address: '上海市普陀区金沙江路 1518 弄',
  109. zip: 200333
  110. },
  111. {
  112. date: '2016-05-04',
  113. name: '王小虎',
  114. province: '上海',
  115. city: '普陀区',
  116. address: '上海市普陀区金沙江路 1517 弄',
  117. zip: 200333
  118. },
  119. {
  120. date: '2016-05-01',
  121. name: '王小虎',
  122. province: '上海',
  123. city: '普陀区',
  124. address: '上海市普陀区金沙江路 1519 弄',
  125. zip: 200333
  126. },
  127. {
  128. date: '2016-05-03',
  129. name: '王小虎',
  130. province: '上海',
  131. city: '普陀区',
  132. address: '上海市普陀区金沙江路 1516 弄',
  133. zip: 200333
  134. }
  135. ]
  136. export default defineComponent({
  137. // name: 'FixedColumnHeader',
  138. components: {
  139. ComTable
  140. },
  141. setup() {
  142. const loading = ref<boolean>(true)
  143. setTimeout(() => {
  144. loading.value = false
  145. }, 1000)
  146. function handleClick(row: any) {
  147. console.log(row)
  148. }
  149. return {
  150. columns,
  151. tableData,
  152. loading,
  153. handleClick
  154. }
  155. }
  156. })
  157. </script>
  158. <style>
  159. </style>