list-layout.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div id="list-layout">
  3. <el-container direction="vertical" style="width:100%;height:100%;background: #f0f2f5;">
  4. <el-header class="toZero" v-if="needSearch">
  5. <el-row :gutter="1" type="flex" justify="center" class="search_row">
  6. <el-col :span="20">
  7. <el-input v-model="searchVal" size="medium" :placeholder="searchPlaceHolder" prefix-icon="el-icon-search" @input="toSearch('sync')"></el-input>
  8. </el-col>
  9. <el-col :span="3" :offset="1" class="btn_col">
  10. <span class="search_btn" @click="toSearch('search')">搜索</span>
  11. </el-col>
  12. </el-row>
  13. </el-header>
  14. <el-header v-else style="height:2.5rem">
  15. <el-row class="title">
  16. <el-col :span="24" style="text-align:center;">{{ title }}</el-col>
  17. </el-row>
  18. </el-header>
  19. <el-main class="toZero">
  20. <listContent v-on="$listeners" :hasMore="hasMore" v-if="needInfinteLoading">
  21. <template v-slot:list>
  22. <slot name="content"></slot>
  23. </template>
  24. </listContent>
  25. <slot name="content" v-else></slot>
  26. </el-main>
  27. </el-container>
  28. </div>
  29. </template>
  30. <script>
  31. import listContent from '@/components/list-components/list.vue';
  32. import { mapActions, mapState } from 'vuex';
  33. export default {
  34. name: 'list-layout',
  35. props: {
  36. needSearch: { type: Boolean, default: true },
  37. searchPlaceHolder: { type: String },
  38. needInfinteLoading: { type: Boolean, default: true },
  39. hasMore: { type: Boolean },
  40. searchName: { type: String },
  41. title: null,
  42. },
  43. components: {
  44. listContent,
  45. },
  46. data: () => ({
  47. searchVal: '',
  48. }),
  49. created() {},
  50. computed: {},
  51. methods: {
  52. toSearch(type) {
  53. let data;
  54. if (this.searchName) {
  55. data = {};
  56. data[`${this.searchName}`] = this.searchVal;
  57. } else {
  58. data = this.searchVal;
  59. }
  60. this.$emit('searchBar', { type: type, value: data });
  61. },
  62. },
  63. };
  64. </script>
  65. <style lang="less" scoped>
  66. .toZero {
  67. margin: 0;
  68. padding: 0;
  69. }
  70. .search_row {
  71. padding: 0.55rem;
  72. &:last-child {
  73. margin-bottom: 0;
  74. }
  75. }
  76. .title {
  77. padding: 0.3rem;
  78. }
  79. .search_btn {
  80. background: #f0f2f5;
  81. color: #333333;
  82. border: 0;
  83. font-size: 16px;
  84. font-weight: 500;
  85. }
  86. .btn_col {
  87. padding-top: 0.5rem;
  88. }
  89. </style>