xtable.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div>
  3. <div class="flex flex-center flex-justify-between border-bottom">
  4. <div v-for="header in headers" :key="header.id" class="mt-20 full-width">
  5. <div
  6. v-if="header.label === '操作' && showMenu"
  7. class="padding-top padding-bottom"
  8. style="width: 280px"
  9. >
  10. {{ header.label }}{{ showMenu }}
  11. </div>
  12. <div
  13. v-else
  14. class="menu flex flex-center"
  15. :style="header.width ? `width:` + header.width + `px` : ''"
  16. >
  17. {{ header.label }}
  18. </div>
  19. </div>
  20. </div>
  21. <div class="full-width">
  22. <div v-if="data.length !== 0">
  23. <div
  24. v-for="row in data"
  25. :key="row.id"
  26. class="flex flex-center row pointer"
  27. >
  28. <div
  29. v-for="(prop, index) in headers"
  30. :key="prop.id"
  31. class="flex-child-average flex"
  32. >
  33. <div
  34. v-if="prop.label === '操作' && showMenu"
  35. class="nowrap menu flex flex-center light-blue-bg"
  36. style="width: 280px"
  37. >
  38. <el-button type="primary" size="small" text>查看</el-button>
  39. <el-button type="primary" size="small" text>归档</el-button>
  40. <el-button type="primary" size="small" text>重命名</el-button>
  41. <move />
  42. </div>
  43. <div
  44. v-else
  45. class="row full-width"
  46. :style="`min-width:` + prop.width + `px`"
  47. >
  48. <div class="cell flex flex-center full-width">
  49. <row1
  50. :row="row"
  51. :column="prop"
  52. :index="index"
  53. @click="rowClick(row)"
  54. ></row1>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <div v-else class="mt-20">
  61. <el-empty v-if="loading === false" description="暂无数据"></el-empty>
  62. <el-skeleton v-else :rows="20" animated />
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import row1 from '@/views/resource/component/row1.vue'
  69. import move from '@/views/resource/component/move.vue'
  70. export default {
  71. components: {
  72. row1,
  73. move
  74. },
  75. props: {
  76. data: {
  77. type: Array,
  78. default: null
  79. },
  80. option: {
  81. type: Object,
  82. default: null
  83. },
  84. loading: {
  85. type: Boolean,
  86. default: false
  87. }
  88. },
  89. watch: {
  90. option: {
  91. handler(val) {
  92. this.headers.length = 0
  93. const menu = {
  94. label: '操作'
  95. }
  96. console.log(this.option.showMenu)
  97. this.showMenu = this.option.showMenu
  98. this.headers = val.column
  99. if (this.headers.findIndex(e => e.label === '操作') === -1) {
  100. this.headers.push(menu)
  101. }
  102. },
  103. immediate: true
  104. }
  105. },
  106. data() {
  107. return {
  108. showMenu: true,
  109. headers: []
  110. }
  111. },
  112. methods: {
  113. rowClick(row) {
  114. this.$emit('row-click', row)
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .row {
  121. min-height: 40px;
  122. }
  123. .row:hover {
  124. min-height: 40px;
  125. background-color: #f7f9fc;
  126. }
  127. .cell {
  128. min-height: 45px;
  129. }
  130. .menu {
  131. display: flex;
  132. flex: 1;
  133. height: 45px;
  134. border-bottom: #f7f8fa solid 1px;
  135. }
  136. </style>