You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

banner.vue 2.9 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <view
  3. v-if="type === 'default'"
  4. :class="[hexColor ? '' : 'bg-' + color, fixed ? 'banner-fixed' : '', className]"
  5. :style="rootStyle"
  6. class="cu-bar cu-banner"
  7. >
  8. <view @click="clickLeft" class="action"><slot name="left"></slot></view>
  9. <view @click="clickCenter" class="content">
  10. <slot></slot>
  11. {{ title }}
  12. </view>
  13. <view @click="clickRight" class="action"><slot name="right"></slot></view>
  14. </view>
  15. <view
  16. v-else-if="type === 'search'"
  17. :class="[hexColor ? '' : 'bg-' + color, fixed ? 'banner-fixed' : '', className]"
  18. :style="rootStyle"
  19. class="cu-bar search cu-banner"
  20. >
  21. <slot name="left"></slot>
  22. <view class="search-form" :class="[fill ? 'radius' : 'round']" :style="inputStyle">
  23. <slot name="searchInput">
  24. <text class="cuIcon-search"></text>
  25. <input
  26. @input="searchTextChange"
  27. @focus="$emit('inputFocus', $event)"
  28. :placeholder-style="placeholderStyle"
  29. :adjust-position="false"
  30. :placeholder="placeholder"
  31. :value="value"
  32. :focus="focus"
  33. confirm-type="search"
  34. type="text"
  35. ref="bannerInput"
  36. />
  37. </slot>
  38. </view>
  39. <view v-if="!noSearchButton" class="action">
  40. <slot name="searchButton">
  41. <template v-if="fill">
  42. <view @click="searchClick">搜索</view>
  43. </template>
  44. <button v-else @click="searchClick" class="cu-btn bg-green shadow-blur round">搜索</button>
  45. </slot>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. name: 'l-banner',
  52. props: {
  53. type: { default: 'default' },
  54. color: { default: 'white' },
  55. hexColor: {},
  56. inputStyle: {},
  57. fill: {},
  58. title: {},
  59. value: {},
  60. placeholder: { default: '搜索图片、文章、视频' },
  61. noSearchButton: {},
  62. placeholderStyle: {},
  63. fixed: {},
  64. noshadow: {},
  65. focus: {}
  66. },
  67. methods: {
  68. searchTextChange(e) {
  69. this.$emit('input', e.detail.value)
  70. this.$emit('change', e.detail.value)
  71. },
  72. clickLeft(e) {
  73. this.$emit('clickLeft', e)
  74. },
  75. clickRight(e) {
  76. this.$emit('clickRight', e)
  77. },
  78. clickCenter(e) {
  79. this.$emit('clickCenter', e)
  80. },
  81. searchClick(F) {
  82. this.$emit('searchClick')
  83. },
  84. inputFocus() {
  85. this.$refs.bannerInput.focus()
  86. }
  87. },
  88. computed: {
  89. rootStyle() {
  90. return this.type === 'default'
  91. ? this.getStyle({
  92. backgroundColor: this.hexColor,
  93. boxShadow: this.noshadow ? null : '0 1rpx 6rpx rgba(0, 0, 0, 0.1)'
  94. })
  95. : this.getStyle({
  96. backgroundColor: this.hexColor,
  97. boxShadow: this.noshadow ? null : '0 1rpx 6rpx rgba(0, 0, 0, 0.1)'
  98. })
  99. }
  100. }
  101. }
  102. </script>
  103. <style scoped>
  104. .banner-fixed {
  105. position: fixed;
  106. width: 100%;
  107. top: var(--window-top);
  108. z-index: 1024;
  109. }
  110. </style>