z-paging-swiper.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. })
  59. // #ifndef APP-PLUS
  60. this._getCssSafeAreaInsetBottom();
  61. // #endif
  62. this.updateLeftAndRightWidth();
  63. this.swiperContentStyle = { 'flex': '1' };
  64. // #ifndef APP-NVUE
  65. this.swiperContentStyle = { width: '100%',height: '100%' };
  66. // #endif
  67. },
  68. computed: {
  69. finalSwiperStyle() {
  70. const swiperStyle = this.swiperStyle;
  71. if (!this.systemInfo) return swiperStyle;
  72. const windowTop = this.windowTop;
  73. const windowBottom = this.systemInfo.windowBottom;
  74. if (this.fixed) {
  75. if (windowTop && !swiperStyle.top) {
  76. swiperStyle.top = windowTop + 'px';
  77. }
  78. if (!swiperStyle.bottom) {
  79. let bottom = windowBottom || 0;
  80. bottom += this.safeAreaInsetBottom ? this.safeAreaBottom : 0;
  81. if (bottom > 0) {
  82. swiperStyle.bottom = bottom + 'px';
  83. }
  84. }
  85. }
  86. return swiperStyle;
  87. }
  88. },
  89. methods: {
  90. //更新slot="left"和slot="right"宽度,当slot="left"或slot="right"宽度动态改变时调用
  91. updateLeftAndRightWidth() {
  92. if (!this.isOldWebView) return;
  93. this.$nextTick(() => this._updateLeftAndRightWidth(this.swiperContentStyle, 'zp-swiper'));
  94. }
  95. }
  96. }
  97. </script>
  98. <style scoped>
  99. .zp-swiper-container {
  100. /* #ifndef APP-NVUE */
  101. display: flex;
  102. /* #endif */
  103. flex-direction: column;
  104. flex: 1;
  105. }
  106. .zp-swiper-container-fixed {
  107. position: fixed;
  108. /* #ifndef APP-NVUE */
  109. height: auto;
  110. width: auto;
  111. /* #endif */
  112. top: 0;
  113. left: 0;
  114. bottom: 0;
  115. right: 0;
  116. }
  117. .zp-safe-area-inset-bottom {
  118. position: absolute;
  119. /* #ifndef APP-PLUS */
  120. height: env(safe-area-inset-bottom);
  121. /* #endif */
  122. }
  123. .zp-swiper-super {
  124. flex: 1;
  125. position: relative;
  126. /* #ifndef APP-NVUE */
  127. display: flex;
  128. /* #endif */
  129. flex-direction: row;
  130. }
  131. .zp-swiper-left,.zp-swiper-right{
  132. /* #ifndef APP-NVUE */
  133. height: 100%;
  134. /* #endif */
  135. }
  136. .zp-swiper {
  137. flex: 1;
  138. /* #ifndef APP-NVUE */
  139. height: 100%;
  140. width: 100%;
  141. /* #endif */
  142. }
  143. .zp-absoulte {
  144. /* #ifndef APP-NVUE */
  145. position: absolute;
  146. top: 0;
  147. width: auto;
  148. /* #endif */
  149. }
  150. .zp-right{
  151. right: 0;
  152. }
  153. .zp-swiper-item {
  154. height: 100%;
  155. }
  156. </style>