top.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div id="top">
  3. <van-row>
  4. <van-col span="24" class="main">
  5. <van-col span="24" class="common type_1" v-if="topType == '1'">
  6. <van-search v-model="searchName" placeholder="请输入信息标题" @search="search" />
  7. </van-col>
  8. <van-col span="24" class="common type_2" v-else-if="topType == '2'">
  9. <van-nav-bar :title="this.$route.meta.title">
  10. <template #left>
  11. <van-col span="24" v-if="leftArrow" @click="back" class="leftArrow">
  12. <van-icon name="arrow-left" />
  13. <span>返回</span>
  14. </van-col>
  15. </template>
  16. <template #right>
  17. <van-col span="24" v-if="rightArrow" @click="add"><van-icon name="plus"/></van-col>
  18. </template>
  19. </van-nav-bar>
  20. </van-col>
  21. <van-col span="24" class="common type_3" v-else-if="topType == '3'">
  22. <van-col span="4" class="left" @click.native="back">
  23. <van-icon name="arrow-left" />
  24. <span>返回</span>
  25. </van-col>
  26. <van-col span="20" class="right">
  27. <van-search v-model="searchName" placeholder="请输入信息标题" @search="search" />
  28. </van-col>
  29. </van-col>
  30. <van-col span="24" class="common type_4" v-else-if="topType == '4'">
  31. <slot name="top"></slot>
  32. </van-col>
  33. </van-col>
  34. </van-row>
  35. </div>
  36. </template>
  37. <script>
  38. import { mapState, createNamespacedHelpers } from 'vuex';
  39. export default {
  40. name: 'top',
  41. props: {
  42. topType: { typ: String },
  43. leftArrow: { typ: Boolean },
  44. rightArrow: { typ: Boolean },
  45. },
  46. components: {},
  47. data: function() {
  48. return {
  49. searchName: '',
  50. };
  51. },
  52. created() {},
  53. methods: {
  54. // 搜索
  55. search() {
  56. this.$emit('search', { searchName: this.searchName });
  57. },
  58. // 返回
  59. back() {
  60. this.$emit('back');
  61. },
  62. // 添加
  63. add() {
  64. this.$emit('add');
  65. },
  66. },
  67. computed: {
  68. ...mapState(['user']),
  69. },
  70. metaInfo() {
  71. return { title: this.$route.meta.title };
  72. },
  73. watch: {
  74. test: {
  75. deep: true,
  76. immediate: true,
  77. handler(val) {},
  78. },
  79. },
  80. };
  81. </script>
  82. <style lang="less" scoped>
  83. .main {
  84. .common {
  85. height: 45px;
  86. overflow: hidden;
  87. border-bottom: 1px solid #f1f1f1;
  88. }
  89. .type_1 {
  90. padding: 5px;
  91. /deep/.van-search {
  92. padding: 0;
  93. }
  94. }
  95. .type_2 {
  96. .leftArrow {
  97. span {
  98. color: #409eff;
  99. position: relative;
  100. top: 0;
  101. }
  102. }
  103. }
  104. .type_3 {
  105. padding: 5px;
  106. /deep/.van-search {
  107. padding: 0;
  108. }
  109. .left {
  110. color: #409eff;
  111. font-size: 15px;
  112. text-align: center;
  113. padding: 8px 0;
  114. span {
  115. position: relative;
  116. top: -2px;
  117. }
  118. }
  119. }
  120. }
  121. </style>