common.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="common">
  3. <div class="operation-container">
  4. <span class="title">练习列表</span>
  5. <slot name="operation"></slot>
  6. </div>
  7. <div class="menu">
  8. <div :class="['menu-item', isPublic ? 'active' : '']" @click="$router.push('/')">公共题库</div>
  9. <div :class="['menu-item', isPublic ? '' : 'active']" @click="$router.push('personal_question')">个人题库</div>
  10. </div>
  11. <div class="search">
  12. <slot name="search"></slot>
  13. </div>
  14. <el-table :data="data">
  15. <slot></slot>
  16. </el-table>
  17. <el-pagination
  18. background
  19. :current-page="cur_page"
  20. :page-sizes="[10, 20, 30, 40, 50]"
  21. :page-size="page_capacity"
  22. layout="total, prev, pager, next, sizes, jumper"
  23. :total="total"
  24. @prev-click="changePage"
  25. @next-click="changePage"
  26. @current-change="changePage"
  27. @size-change="changePageSize"
  28. />
  29. </div>
  30. </template>
  31. <script>
  32. export default {
  33. name: 'HomeCommon',
  34. props: {
  35. pageSize: {
  36. type: Number,
  37. default: 10
  38. },
  39. total: {
  40. type: Number,
  41. default: 0
  42. },
  43. data: {
  44. type: Array,
  45. default: () => []
  46. }
  47. },
  48. data() {
  49. return {
  50. cur_page: 1,
  51. page_capacity: this.pageSize
  52. };
  53. },
  54. computed: {
  55. isPublic() {
  56. return this.$route.path === '/home';
  57. }
  58. },
  59. created() {
  60. this.getList();
  61. },
  62. methods: {
  63. changePage(number) {
  64. this.cur_page = number;
  65. this.getList();
  66. },
  67. changePageSize(size) {
  68. this.page_capacity = size;
  69. this.getList();
  70. },
  71. getList() {
  72. this.$emit('getList', { cur_page: this.cur_page, page_capacity: this.page_capacity });
  73. }
  74. }
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .common {
  79. display: flex;
  80. flex-direction: column;
  81. row-gap: 16px;
  82. height: calc(100% - 16px);
  83. padding: 24px;
  84. margin: 0 24px 16px;
  85. background: #fff;
  86. border-radius: 4px;
  87. .operation-container {
  88. display: flex;
  89. align-items: center;
  90. justify-content: space-between;
  91. height: 32px;
  92. .title {
  93. font-size: 20px;
  94. font-weight: bold;
  95. }
  96. }
  97. .menu {
  98. display: flex;
  99. &-item {
  100. padding: 5px 16px;
  101. font-size: 14px;
  102. color: #4e5969;
  103. cursor: pointer;
  104. &.active {
  105. font-weight: bold;
  106. color: $main-color;
  107. background-color: $fill-color;
  108. border-radius: 18px;
  109. }
  110. }
  111. }
  112. .search {
  113. display: grid;
  114. grid-template: 30px 32px / repeat(auto-fill, 210px);
  115. grid-auto-flow: column;
  116. column-gap: 24px;
  117. &-name {
  118. font-size: 14px;
  119. color: #4e5969;
  120. }
  121. }
  122. }
  123. </style>