Table.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <el-table
  3. :data="tableData"
  4. border
  5. class="table"
  6. @selection-change="handleSelectionChange"
  7. style="width: 100%">
  8. <el-table-column
  9. type="selection"
  10. fixed
  11. width="55">
  12. </el-table-column>
  13. <el-table-column
  14. prop="title"
  15. label="标题"
  16. width="360">
  17. </el-table-column>
  18. <el-table-column
  19. prop="intro"
  20. label="描述"
  21. width="360">
  22. </el-table-column>
  23. <el-table-column
  24. prop="newsClassifyName"
  25. label="新闻分类"
  26. width="200">
  27. </el-table-column>
  28. <el-table-column
  29. prop="pic"
  30. label="图片"
  31. width="300">
  32. <template slot-scope="scope">
  33. <el-image
  34. style="width: 200px;height: 200px"
  35. :src="scope.row.pic"
  36. :lazy="true"
  37. :preview-src-list="scope.row.pic ? [scope.row.pic]: []"
  38. fit="contain"></el-image>
  39. </template>
  40. </el-table-column>
  41. <el-table-column
  42. prop="startTime"
  43. label="发布时间"
  44. :show-overflow-tooltip="true"
  45. width="200">
  46. </el-table-column>
  47. <el-table-column
  48. prop="visits"
  49. label="访问次数"
  50. :show-overflow-tooltip="true"
  51. width="200">
  52. </el-table-column>
  53. <el-table-column
  54. label="操作"
  55. fixed="right"
  56. >
  57. <template slot-scope="scope">
  58. <el-button type="text" @click="handleEditor(scope.row)">编辑</el-button>
  59. <el-button type="text" v-if="false" @click="handleDelete(scope.row)">删除</el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. </template>
  64. <script>
  65. export default {
  66. name: 'Table',
  67. inject: {
  68. tableServiceData: {
  69. type: Object,
  70. default: () => {
  71. },
  72. },
  73. paginationServiceData: {
  74. type: Object,
  75. default: () => {
  76. },
  77. },
  78. },
  79. computed: {
  80. tableData() {
  81. return this.tableServiceData.myData;
  82. },
  83. },
  84. methods: {
  85. handleSelectionChange(data) {
  86. const arr = [];
  87. data.forEach(item => {
  88. arr.push(item.iiId)
  89. })
  90. this.$emit('select-change', arr);
  91. },
  92. handleEditor(data) {
  93. this.$emit('editor', data);
  94. },
  95. handleDelete(data) {
  96. this.$emit('delete', data);
  97. },
  98. },
  99. };
  100. </script>
  101. <style lang="scss" scoped>
  102. .table {
  103. ::v-deep .is-leaf {
  104. .cell {
  105. text-align: center;
  106. }
  107. }
  108. ::v-deep .el-table-column--selection {
  109. .cell {
  110. text-align: center;
  111. }
  112. }
  113. }
  114. </style>