ModalTable.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="table_template">
  3. <table class="table">
  4. <thead>
  5. <tr :style="tableHeadStyle">
  6. <td v-for="(item, index) in tableHeader" :key="index" :style="tableHeadStyle">{{ item }}</td>
  7. </tr>
  8. </thead>
  9. <tbody>
  10. <tr v-for="(obj, index) in tableData" :key="index" :class="{ table_gray: !discolor && index%2 === 0 }">
  11. <td :style="trStyle" v-if="flag">{{ index + 1 }}</td>
  12. <td v-for="(item, index) in obj" :key="index" :style="trStyle">
  13. {{ item }}
  14. </td>
  15. <td :style="trStyle">
  16. <img src="../../../../img/add.png" @click="changeIcon(index)" :style="operationStyle" v-if="imgFlag[index]">
  17. <img src="../../../../img/delete.png" @click="changeIcon(index)" :style="operationStyle" v-else>
  18. </td>
  19. </tr>
  20. </tbody>
  21. </table>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. props: {
  27. // 表数据
  28. tableData: {
  29. type: Array,
  30. default: () => {
  31. return []
  32. }
  33. },
  34. // 表头
  35. tableHeader: {
  36. type: Array,
  37. default: () => {
  38. return []
  39. }
  40. },
  41. // 表头样式
  42. tableHeadStyle: {
  43. type: Object,
  44. default: () => {
  45. return {
  46. background: '#848484',
  47. height: '50px',
  48. color: '#fff'
  49. }
  50. }
  51. },
  52. // 操作样式
  53. operationStyle: {
  54. type: Object,
  55. default: () => {
  56. return {
  57. color: '#0000ff'
  58. }
  59. }
  60. },
  61. // imgFlag
  62. imgFlag: {
  63. type: Array,
  64. default: () => {
  65. let arr = new Array(20).fill(20);
  66. return arr
  67. }
  68. },
  69. // 表格除去表头的样式
  70. trStyle: {
  71. type: Object,
  72. default: () => {
  73. return {
  74. width: '200px',
  75. height: '50px'
  76. }
  77. }
  78. },
  79. // 是否隔行变色
  80. discolor: {
  81. type: Boolean,
  82. default: true
  83. },
  84. // 每页表格共有多少数据
  85. pageSize: {
  86. type: Number,
  87. default: 20
  88. },
  89. flag: {
  90. type: Boolean,
  91. default: true
  92. },
  93. },
  94. methods: {
  95. changeIcon: function(index) {
  96. console.log(index);
  97. this.$emit('change_icon', index);
  98. }
  99. },
  100. mounted() {
  101. },
  102. data() {
  103. return {
  104. }
  105. }
  106. };
  107. </script>
  108. <style scoped lang="less">
  109. .table_template{
  110. text-align: center;
  111. .table{
  112. background-color: #fff;
  113. border-collapse:collapse;
  114. border:none;
  115. width: 100%;
  116. td{
  117. border: 1px solid #ccc;
  118. }
  119. span{
  120. &:hover{
  121. cursor: pointer;
  122. }
  123. }
  124. }
  125. }
  126. .table_gray{
  127. background: #f5f5f5;
  128. }
  129. </style>