securityCheckTable.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <div
  3. v-loading="loading"
  4. class="security-check-table-wrapper"
  5. :style="{ height: tableWrapperHeight }"
  6. >
  7. <a-table
  8. ref="table"
  9. :data-source="tableData"
  10. :columns="tableCols"
  11. bordered
  12. height="100%"
  13. :rowClassName="rowClassName"
  14. >
  15. <template v-if="withSelection">
  16. <a-table-column type="selection" width="35" />
  17. </template>
  18. <template v-for="col in cols">
  19. <NestTableColumn :key="col.prop" :col="col" />
  20. </template>
  21. <template v-if="withOperateColumn">
  22. <a-table-column label="操作" class-name="column-operate" :width="130">
  23. <template slot-scope="scope">
  24. <span class="cell-operate-edit" @click="editRow(scope.row)"
  25. >修改</span
  26. >
  27. <span class="cell-operate-delete" @click="deleteRow(scope.row)"
  28. >删除</span
  29. >
  30. </template>
  31. </a-table-column>
  32. </template>
  33. </a-table>
  34. </div>
  35. </template>
  36. <script>
  37. import NestTableColumn from "./nestTableColumn.vue";
  38. export default {
  39. name: "SecurityCheckTable",
  40. components: { NestTableColumn },
  41. props: {
  42. height: {
  43. type: [Number, String],
  44. default: "50vh",
  45. },
  46. tableCols: {
  47. type: Array,
  48. default: () => [],
  49. },
  50. tableData: {
  51. type: Array,
  52. default: () => [],
  53. },
  54. withSelection: {
  55. type: Boolean,
  56. default: false,
  57. },
  58. showSummary: {
  59. type: Boolean,
  60. default: false,
  61. },
  62. withOperateColumn: {
  63. type: Boolean,
  64. default: false,
  65. },
  66. },
  67. data() {
  68. return {
  69. loading: false,
  70. cols: [],
  71. data: [],
  72. };
  73. },
  74. computed: {
  75. tableWrapperHeight() {
  76. return typeof this.height === "number" ? this.height + "px" : this.height;
  77. },
  78. },
  79. watch: {
  80. tableCols: {
  81. handler(val) {
  82. this.cols = val;
  83. },
  84. deep: true,
  85. immediate: true,
  86. },
  87. tableData: {
  88. handler(val) {
  89. this.data = val;
  90. },
  91. deep: true,
  92. immediate: true,
  93. },
  94. },
  95. updated() {
  96. this.$refs["table"].doLayout();
  97. },
  98. methods: {
  99. rowClassName(index) {
  100. if (index.index % 2 == 0) {
  101. return "warning-row";
  102. } else {
  103. return "warning-rows";
  104. }
  105. },
  106. editRow(row) {
  107. console.log("edit");
  108. },
  109. deleteRow(row) {
  110. console.log("delete");
  111. },
  112. },
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. .security-check-table-wrapper {
  117. width: 100%;
  118. ::v-deep .warning-row {
  119. background-color: #f3f5f8;
  120. }
  121. ::v-deep .warning-rows {
  122. background-color: #fff;
  123. }
  124. ::v-deep .ant-table-column-title {
  125. font-size: 14px;
  126. font-family: Helvetica, "Microsoft YaHei";
  127. color: #101116;
  128. font-weight: bold;
  129. }
  130. ::v-deep .ant-table {
  131. width: 100%;
  132. .ant-table__cell {
  133. .cell {
  134. // padding: 0 19px;
  135. font-size: 14px;
  136. font-family: Helvetica, "Microsoft YaHei";
  137. color: #101116;
  138. }
  139. &.ant-table-column--selection .cell {
  140. padding: 0;
  141. text-align: center;
  142. }
  143. }
  144. .ant-table__header {
  145. .ant-table__cell {
  146. > .cell {
  147. font-weight: bold;
  148. }
  149. &:not(.is-leaf) > .cell {
  150. text-align: center;
  151. }
  152. }
  153. }
  154. .ant-table__body {
  155. .cell .cell-click {
  156. color: #2d67e3;
  157. cursor: pointer;
  158. }
  159. .column-operate .cell {
  160. span {
  161. cursor: pointer;
  162. &:not(:last-child) {
  163. margin-right: 25px;
  164. }
  165. &.cell-operate-edit {
  166. color: #2d67e3;
  167. }
  168. &.cell-operate-delete {
  169. color: #ea4545;
  170. }
  171. }
  172. }
  173. }
  174. }
  175. }
  176. </style>