z-paging-swiper.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. export default {
  29. name: "z-paging-swiper",
  30. mixins: [commonLayoutModule],
  31. data() {
  32. return {
  33. swiperContentStyle: {}
  34. };
  35. },
  36. props: {
  37. // 是否使用fixed布局,默认为是
  38. fixed: {
  39. type: Boolean,
  40. default: true
  41. },
  42. // 是否开启底部安全区域适配
  43. safeAreaInsetBottom: {
  44. type: Boolean,
  45. default: false
  46. },
  47. // z-paging-swiper样式
  48. swiperStyle: {
  49. type: Object,
  50. default: function() {
  51. return {};
  52. },
  53. }
  54. },
  55. mounted() {
  56. this.$nextTick(() => {
  57. this.systemInfo = uni.getSystemInfoSync();
  58. setTimeout(this.updateFixedLayout, 100)
  59. })
  60. // #ifndef APP-PLUS
  61. this._getCssSafeAreaInsetBottom();
  62. // #endif
  63. this.updateLeftAndRightWidth();
  64. this.swiperContentStyle = { 'flex': '1' };
  65. // #ifndef APP-NVUE
  66. this.swiperContentStyle = { width: '100%',height: '100%' };
  67. // #endif
  68. },
  69. computed: {
  70. finalSwiperStyle() {
  71. const swiperStyle = { ...this.swiperStyle };
  72. if (!this.systemInfo) return swiperStyle;
  73. const windowTop = this.windowTop;
  74. const windowBottom = this.systemInfo.windowBottom;
  75. if (this.fixed) {
  76. if (windowTop && !swiperStyle.top) {
  77. swiperStyle.top = windowTop + 'px';
  78. }
  79. if (!swiperStyle.bottom) {
  80. let bottom = windowBottom || 0;
  81. bottom += this.safeAreaInsetBottom ? this.safeAreaBottom : 0;
  82. if (bottom > 0) {
  83. swiperStyle.bottom = bottom + 'px';
  84. }
  85. }
  86. }
  87. return swiperStyle;
  88. }
  89. },
  90. methods: {
  91. // 更新slot="left"和slot="right"宽度,当slot="left"或slot="right"宽度动态改变时调用
  92. updateLeftAndRightWidth() {
  93. if (!this.isOldWebView) return;
  94. this.$nextTick(() => this._updateLeftAndRightWidth(this.swiperContentStyle, 'zp-swiper'));
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. .zp-swiper-container {
  101. /* #ifndef APP-NVUE */
  102. display: flex;
  103. /* #endif */
  104. flex-direction: column;
  105. flex: 1;
  106. }
  107. .zp-swiper-container-fixed {
  108. position: fixed;
  109. /* #ifndef APP-NVUE */
  110. height: auto;
  111. width: auto;
  112. /* #endif */
  113. top: 0;
  114. left: 0;
  115. bottom: 0;
  116. right: 0;
  117. }
  118. .zp-safe-area-inset-bottom {
  119. position: absolute;
  120. /* #ifndef APP-PLUS */
  121. height: env(safe-area-inset-bottom);
  122. /* #endif */
  123. }
  124. .zp-swiper-super {
  125. flex: 1;
  126. overflow: hidden;
  127. position: relative;
  128. /* #ifndef APP-NVUE */
  129. display: flex;
  130. /* #endif */
  131. flex-direction: row;
  132. }
  133. .zp-swiper-left,.zp-swiper-right{
  134. /* #ifndef APP-NVUE */
  135. height: 100%;
  136. /* #endif */
  137. }
  138. .zp-swiper {
  139. flex: 1;
  140. /* #ifndef APP-NVUE */
  141. height: 100%;
  142. width: 100%;
  143. /* #endif */
  144. }
  145. .zp-absoulte {
  146. /* #ifndef APP-NVUE */
  147. position: absolute;
  148. top: 0;
  149. width: auto;
  150. /* #endif */
  151. }
  152. .zp-swiper-item {
  153. height: 100%;
  154. }
  155. </style>