Table.vue 3.7 KB

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