home-head.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <!-- 首页标题栏,轮播图整合插件 -->
  3. <view class="banner-swiper-wrap u-m-b-10">
  4. <!-- 标题栏 -->
  5. <view class="u-navbar u-navbar-fixed" :style="[navbarStyle]">
  6. <view class="u-status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
  7. <view class="u-navbar-inner" :style="[navbarInnerStyle]">
  8. <view class="u-back-wrap">
  9. <view class="u-icon-wrap u-back-text u-line-1" :style="[navTitleStyle]">中宏商城</view>
  10. </view>
  11. <view hover-class="hover-search" class="search-box u-flex u-row-center u-col-center u-m-r-30" @tap="$Router.push('/pages/public/search')">
  12. <view class="u-iconfont uicon-search" style="color: #fff"></view>
  13. </view>
  14. </view>
  15. </view>
  16. <!-- 轮播组件 -->
  17. <swiper class="screen-swiper square-dot" @change="onChange" style="height: 520rpx" :indicator-dots="true" :circular="true" :autoplay="true" interval="5000" duration="500">
  18. <swiper-item v-for="(item, index) in list" :key="index" @tap="onSwiper(index)"><image :src="item.image" mode="aspectFill"></image></swiper-item>
  19. </swiper>
  20. </view>
  21. </template>
  22. <script>
  23. // 获取系统状态栏的高度
  24. let systemInfo = uni.getSystemInfoSync();
  25. let menuButtonInfo = {};
  26. // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
  27. menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  28. // #endif
  29. /**
  30. * home-head-轮播卡片,主要为了处理数据
  31. * @property {Array} list 轮播图数据,
  32. * @property {String} mode 指示器模式
  33. * @property {String} navTitle 项目名称
  34. */
  35. export default {
  36. components: {},
  37. data() {
  38. return {
  39. navBgImage: '',
  40. changeNavBackground: false,
  41. swiperCur: 0,
  42. statusBarHeight: systemInfo.statusBarHeight
  43. };
  44. },
  45. props: {
  46. isScorll: {
  47. type: Boolean,
  48. default: false
  49. },
  50. // 轮播图的数据,格式如:[{image: 'xxxx', title: 'xxxx'},{image: 'yyyy', title: 'yyyy'}],其中title字段可选
  51. list: {
  52. type: Array,
  53. default() {
  54. return [];
  55. }
  56. },
  57. navTitle: {
  58. type: String,
  59. default: '中宏商城'
  60. },
  61. navTitleStyle: {
  62. type: Object,
  63. default: () => {
  64. return {
  65. color: '#fff',
  66. fontSize: '38rpx'
  67. };
  68. }
  69. }
  70. },
  71. watch: {
  72. isScorll(newValue, oldValue) {
  73. this.changeNavBackground = newValue;
  74. this.navBgImage = this.list[this.swiperCur].image;
  75. }
  76. },
  77. computed: {
  78. // 导航栏内部盒子的样式
  79. navbarInnerStyle() {
  80. let style = {};
  81. style.height = this.navbarHeight + 'px';
  82. // #ifdef MP
  83. let rightButtonWidth = systemInfo.windowWidth - menuButtonInfo.left;
  84. style.marginRight = rightButtonWidth + 'px';
  85. // #endif
  86. return style;
  87. },
  88. // 整个导航栏的样式
  89. navbarStyle() {
  90. let style = {};
  91. style.zIndex = this.$u.zIndex.navbar;
  92. style.background = this.changeNavBackground ? `url(${this.navBgImage}) no-repeat top / 100% auto` : 'none';
  93. Object.assign(style, this.background);
  94. return style;
  95. },
  96. navbarHeight() {
  97. // #ifdef APP-PLUS || H5
  98. return 44;
  99. // #endif
  100. // #ifdef MP
  101. return systemInfo.platform == 'ios' ? 44 : 48;
  102. // #endif
  103. }
  104. },
  105. created() {
  106. this.navBgImage = this.list[0].image;
  107. },
  108. methods: {
  109. onSwiper(e) {
  110. this.$tools.routerTo(this.list[e].path);
  111. },
  112. onChange(e) {
  113. this.swiperCur = e.detail.current;
  114. }
  115. }
  116. };
  117. </script>
  118. <style lang="scss" scoped>
  119. @mixin vue-flex($direction: row) {
  120. /* #ifndef APP-NVUE */
  121. display: flex;
  122. flex-direction: $direction;
  123. /* #endif */
  124. }
  125. // 轮播
  126. .banner-swiper-wrap {
  127. height: 520rpx;
  128. position: relative;
  129. z-index: 100;
  130. .search-box {
  131. width: 66rpx;
  132. height: 66rpx;
  133. background: rgba(#000, 0.18);
  134. border-radius: 100%;
  135. }
  136. .hover-search {
  137. background: rgba(#fff, 0.18);
  138. }
  139. }
  140. .u-navbar {
  141. width: 100%;
  142. }
  143. .u-navbar-fixed {
  144. position: fixed;
  145. left: 0;
  146. right: 0;
  147. top: 0;
  148. z-index: 991;
  149. }
  150. .u-status-bar {
  151. width: 100%;
  152. }
  153. .u-navbar-inner {
  154. @include vue-flex;
  155. justify-content: space-between;
  156. position: relative;
  157. align-items: center;
  158. }
  159. .u-back-wrap {
  160. @include vue-flex;
  161. align-items: center;
  162. flex: 1;
  163. flex-grow: 0;
  164. padding: 14rpx 14rpx 14rpx 24rpx;
  165. }
  166. </style>