z-paging-swiper.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <!-- z-paging -->
  2. <!-- github地址:https://github.com/SmileZXLee/uni-z-paging -->
  3. <!-- dcloud地址:https://ext.dcloud.net.cn/plugin?id=3935 -->
  4. <!-- 反馈QQ群:790460711 -->
  5. <!-- 滑动切换选项卡swiper容器,此组件支持easycom规范,可以在项目中直接引用 -->
  6. <template>
  7. <view :class="fixed?'zp-swiper-container zp-swiper-container-fixed':'zp-swiper-container'" :style="[finalSwiperStyle]">
  8. <!-- #ifndef APP-PLUS -->
  9. <view v-if="cssSafeAreaInsetBottom===-1" class="zp-safe-area-inset-bottom"></view>
  10. <!-- #endif -->
  11. <slot v-if="zSlots.top" name="top" />
  12. <view class="zp-swiper-super">
  13. <view v-if="zSlots.left" :class="{'zp-swiper-left':true,'zp-absoulte':isOldWebView}">
  14. <slot name="left" />
  15. </view>
  16. <view :class="{'zp-swiper':true,'zp-absoulte':isOldWebView}" :style="[swiperContentStyle]">
  17. <slot />
  18. </view>
  19. <view v-if="zSlots.right" :class="{'zp-swiper-right':true,'zp-absoulte zp-right':isOldWebView}">
  20. <slot name="right" />
  21. </view>
  22. </view>
  23. <slot v-if="zSlots.bottom" name="bottom" />
  24. </view>
  25. </template>
  26. <script>
  27. import commonLayoutModule from '../z-paging/js/modules/common-layout'
  28. /**
  29. * z-paging-swiper 组件
  30. * @description 在 swiper 中使用 z-paging 时(左右滑动切换列表),在根节点使用 z-paging-swiper,其相当于一个 view 容器,默认铺满全屏,可免计算高度直接插入 swiper 的视图容器。
  31. * @tutorial https://z-paging.zxlee.cn/api/sub-components/main.html#z-paging-swiper配置
  32. * @property {Boolean} fixed 是否使用 fixed 布局,默认为 true
  33. * @property {Boolean} safeAreaInsetBottom 是否开启底部安全区域适配,默认为 false
  34. * @property {Object} swiperStyle z-paging-swiper 样式,默认为 {}
  35. * @example <z-paging-swiper :safeAreaInsetBottom="true"></z-paging-swiper>
  36. */
  37. export default {
  38. name: "z-paging-swiper",
  39. mixins: [commonLayoutModule],
  40. data() {
  41. return {
  42. swiperContentStyle: {}
  43. };
  44. },
  45. props: {
  46. // 是否使用fixed布局,默认为是
  47. fixed: {
  48. type: Boolean,
  49. default: true
  50. },
  51. // 是否开启底部安全区域适配
  52. safeAreaInsetBottom: {
  53. type: Boolean,
  54. default: false
  55. },
  56. // z-paging-swiper样式
  57. swiperStyle: {
  58. type: Object,
  59. default: function() {
  60. return {};
  61. },
  62. }
  63. },
  64. mounted() {
  65. this.$nextTick(() => {
  66. this.systemInfo = this._getSystemInfoSync();
  67. setTimeout(this.updateFixedLayout, 100)
  68. })
  69. // #ifndef APP-PLUS
  70. this._getCssSafeAreaInsetBottom();
  71. // #endif
  72. this.updateLeftAndRightWidth();
  73. this.swiperContentStyle = { 'flex': '1' };
  74. // #ifndef APP-NVUE
  75. this.swiperContentStyle = { width: '100%',height: '100%' };
  76. // #endif
  77. },
  78. computed: {
  79. finalSwiperStyle() {
  80. const swiperStyle = { ...this.swiperStyle };
  81. if (!this.systemInfo) return swiperStyle;
  82. const windowTop = this.windowTop;
  83. const windowBottom = this.systemInfo.windowBottom;
  84. if (this.fixed) {
  85. if (windowTop && !swiperStyle.top) {
  86. swiperStyle.top = windowTop + 'px';
  87. }
  88. if (!swiperStyle.bottom) {
  89. let bottom = windowBottom || 0;
  90. bottom += this.safeAreaInsetBottom ? this.safeAreaBottom : 0;
  91. if (bottom > 0) {
  92. swiperStyle.bottom = bottom + 'px';
  93. }
  94. }
  95. }
  96. return swiperStyle;
  97. }
  98. },
  99. methods: {
  100. // 更新slot="left"和slot="right"宽度,当slot="left"或slot="right"宽度动态改变时调用
  101. updateLeftAndRightWidth() {
  102. if (!this.isOldWebView) return;
  103. this.$nextTick(() => this._updateLeftAndRightWidth(this.swiperContentStyle, 'zp-swiper'));
  104. }
  105. }
  106. }
  107. </script>
  108. <style scoped>
  109. .zp-swiper-container {
  110. /* #ifndef APP-NVUE */
  111. display: flex;
  112. /* #endif */
  113. flex-direction: column;
  114. flex: 1;
  115. }
  116. .zp-swiper-container-fixed {
  117. position: fixed;
  118. /* #ifndef APP-NVUE */
  119. height: auto;
  120. width: auto;
  121. /* #endif */
  122. top: 0;
  123. left: 0;
  124. bottom: 0;
  125. right: 0;
  126. }
  127. .zp-safe-area-inset-bottom {
  128. position: absolute;
  129. /* #ifndef APP-PLUS */
  130. height: env(safe-area-inset-bottom);
  131. /* #endif */
  132. }
  133. .zp-swiper-super {
  134. flex: 1;
  135. overflow: hidden;
  136. position: relative;
  137. /* #ifndef APP-NVUE */
  138. display: flex;
  139. /* #endif */
  140. flex-direction: row;
  141. }
  142. .zp-swiper-left,.zp-swiper-right{
  143. /* #ifndef APP-NVUE */
  144. height: 100%;
  145. /* #endif */
  146. }
  147. .zp-swiper {
  148. flex: 1;
  149. /* #ifndef APP-NVUE */
  150. height: 100%;
  151. width: 100%;
  152. /* #endif */
  153. }
  154. .zp-absoulte {
  155. /* #ifndef APP-NVUE */
  156. position: absolute;
  157. top: 0;
  158. width: auto;
  159. /* #endif */
  160. }
  161. .zp-swiper-item {
  162. height: 100%;
  163. }
  164. </style>