securityCheckTable.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div
  3. class="security-check-table-wrapper"
  4. :style="{ height: tableWrapperHeight }"
  5. >
  6. <a-table
  7. :data-source="tableData"
  8. :columns="columns"
  9. :row-key="rowKey"
  10. :row-selection="
  11. withSelection
  12. ? { selectedRowKeys: selectedRowKeys, onChange: onSelectChange }
  13. : null
  14. "
  15. :rowClassName="rowClassName"
  16. bordered
  17. :pagination = "pagination"
  18. @change="handleTableChange"
  19. :loading="loading"
  20. >
  21. <template
  22. v-if="withOperateColumn"
  23. slot="operation"
  24. slot-scope="text, record"
  25. >
  26. <div class="column-operate">
  27. <span class="cell-operate-edit" @click="editRow(record)">修改</span>
  28. <span class="cell-operate-delete" @click="deleteRow(record)"
  29. >删除</span
  30. >
  31. </div>
  32. </template>
  33. </a-table>
  34. </div>
  35. </template>
  36. <script>
  37. export default {
  38. name: "SecurityCheckTable",
  39. props: {
  40. height: {
  41. type: [Number, String],
  42. default: "50vh",
  43. },
  44. tableCols: {
  45. type: Array,
  46. default: () => [],
  47. },
  48. tableData: {
  49. type: Array,
  50. default: () => [],
  51. },
  52. rowKey: {
  53. type: String,
  54. default: "key",
  55. },
  56. withSelection: {
  57. type: Boolean,
  58. default: false,
  59. },
  60. loading: {
  61. type: Boolean,
  62. default: false,
  63. },
  64. showSummary: {
  65. type: Boolean,
  66. default: false,
  67. },
  68. pagination:{
  69. type:Object,
  70. default: null,
  71. }
  72. },
  73. data() {
  74. return {
  75. selectedRowKeys: [],
  76. };
  77. },
  78. computed: {
  79. columns() {
  80. return this.tableCols.map((col) => {
  81. if (col.clickHandler) {
  82. col.customCell = () => {
  83. return {
  84. class: "cell-click",
  85. on: {
  86. click: col.clickHandler,
  87. },
  88. };
  89. };
  90. }
  91. if (col.children) {
  92. col.children.forEach((res) => {
  93. if (res.clickHandler) {
  94. res.customCell = () => {
  95. return {
  96. class: "cell-click",
  97. on: {
  98. click: res.clickHandler,
  99. },
  100. };
  101. };
  102. }
  103. });
  104. }
  105. return col;
  106. });
  107. },
  108. tableWrapperHeight() {
  109. return typeof this.height === "number" ? this.height + "px" : this.height;
  110. },
  111. withOperateColumn() {
  112. return this.columns.find((col) => col.dataIndex === "operation");
  113. },
  114. },
  115. methods: {
  116. onSelectChange(selectedRowKeys, selectedRows) {
  117. // console.log(selectedRowKeys)
  118. this.selectedRowKeys = selectedRowKeys;
  119. },
  120. rowClassName(index) {
  121. if (index.index % 2 == 0) {
  122. return "warning-row";
  123. } else {
  124. return "warning-rows";
  125. }
  126. },
  127. editRow(row) {
  128. console.log("edit");
  129. },
  130. deleteRow(row) {
  131. console.log("delete");
  132. },
  133. clickHandler(index) {
  134. console.log(index);
  135. },
  136. handleTableChange(pagination, filters, sorter){
  137. this.$emit("handleTableChange",pagination)
  138. }
  139. },
  140. };
  141. </script>
  142. <style lang="scss" scoped>
  143. .security-check-table-wrapper {
  144. width: 100%;
  145. ::v-deep .ant-table {
  146. width: 100%;
  147. .ant-table-thead {
  148. th {
  149. padding: 18px 12px;
  150. }
  151. .ant-table-column-title {
  152. font-size: 14px;
  153. font-family: Helvetica, "Microsoft YaHei";
  154. color: #101116;
  155. font-weight: bold;
  156. }
  157. }
  158. .ant-table-tbody {
  159. .warning-row {
  160. background-color: #f3f5f8;
  161. padding: 9px 16px;
  162. }
  163. .warning-rows {
  164. background-color: #fff;
  165. padding: 9px 16px;
  166. }
  167. td {
  168. font-size: 14px;
  169. font-family: Helvetica, "Microsoft YaHei";
  170. color: #101116;
  171. &.cell-click {
  172. color: #2d67e3;
  173. cursor: pointer;
  174. }
  175. }
  176. .column-operate {
  177. span {
  178. cursor: pointer;
  179. &:not(:last-child) {
  180. margin-right: 25px;
  181. }
  182. &.cell-operate-edit {
  183. color: #2d67e3;
  184. }
  185. &.cell-operate-delete {
  186. color: #ea4545;
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. </style>