list-layout.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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-main class="toZero">
  15. <listContent v-on="$listeners" :hasMore="hasMore" v-if="needInfinteLoading">
  16. <template v-slot:list>
  17. <slot name="content"></slot>
  18. </template>
  19. </listContent>
  20. <slot name="content" v-else></slot>
  21. </el-main>
  22. </el-container>
  23. </div>
  24. </template>
  25. <script>
  26. import listContent from '@/components/list-components/list.vue';
  27. import { mapActions, mapState } from 'vuex';
  28. export default {
  29. name: 'list-layout',
  30. props: {
  31. needSearch: { type: Boolean, default: true },
  32. searchPlaceHolder: { type: String },
  33. needInfinteLoading: { type: Boolean, default: true },
  34. hasMore: { type: Boolean },
  35. searchName: { type: String },
  36. },
  37. components: {
  38. listContent,
  39. },
  40. data: () => ({
  41. searchVal: '',
  42. }),
  43. created() {},
  44. computed: {},
  45. methods: {
  46. toSearch(type) {
  47. let data;
  48. if (this.searchName) {
  49. data = {};
  50. data[`${this.searchName}`] = this.searchVal;
  51. } else {
  52. data = this.searchVal;
  53. }
  54. console.log(type, data);
  55. this.$emit('searchBar', { type: type, value: data });
  56. },
  57. },
  58. };
  59. </script>
  60. <style lang="less" scoped>
  61. .toZero {
  62. margin: 0;
  63. padding: 0;
  64. }
  65. .search_row {
  66. padding: 0.55rem;
  67. &:last-child {
  68. margin-bottom: 0;
  69. }
  70. }
  71. .search_btn {
  72. background: #f0f2f5;
  73. color: #333333;
  74. border: 0;
  75. font-size: 16px;
  76. font-weight: 500;
  77. }
  78. .btn_col {
  79. padding-top: 0.5rem;
  80. }
  81. </style>