z-paging-swiper.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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="[swiperStyle]">
  8. <slot v-if="$slots.top" name="top"></slot>
  9. <view class="zp-swiper-super">
  10. <view class="zp-swiper">
  11. <slot/></slot>
  12. </view>
  13. </view>
  14. <slot v-if="$slots.bottom" name="bottom"></slot>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: "z-paging-swiper",
  20. data() {
  21. return {
  22. systemInfo: null
  23. };
  24. },
  25. props: {
  26. //是否使用fixed布局,默认为是
  27. fixed: {
  28. type: Boolean,
  29. default: true
  30. },
  31. //是否开启底部安全区域适配
  32. safeAreaInsetBottom: {
  33. type: Boolean,
  34. default: false
  35. }
  36. },
  37. mounted() {
  38. this.$nextTick(() => {
  39. this.systemInfo = uni.getSystemInfoSync();
  40. })
  41. },
  42. computed: {
  43. swiperStyle() {
  44. if (!this.systemInfo) {
  45. return {};
  46. }
  47. let swiperStyle = {};
  48. const windowTop = this.systemInfo.windowTop;
  49. const windowBottom = this.systemInfo.windowBottom;
  50. if (this.fixed) {
  51. if (windowTop && windowTop !== undefined) {
  52. swiperStyle.top = windowTop + 'px';
  53. }
  54. let bottom = 0;
  55. if (windowBottom && windowBottom !== undefined) {
  56. bottom = windowBottom;
  57. }
  58. if (this.safeAreaInsetBottom) {
  59. bottom += this.safeAreaBottom;
  60. }
  61. swiperStyle.bottom = bottom + 'px';
  62. }
  63. return swiperStyle;
  64. },
  65. safeAreaBottom() {
  66. if (!this.systemInfo) {
  67. return 0;
  68. }
  69. let safeAreaBottom = 0;
  70. // #ifdef MP-WEIXIN
  71. safeAreaBottom = this.systemInfo.screenHeight - this.systemInfo.safeArea.bottom;
  72. // #endif
  73. // #ifdef APP-PLUS || H5
  74. safeAreaBottom = this.systemInfo.safeAreaInsets.bottom || 0;
  75. // #endif
  76. return Math.abs(safeAreaBottom);
  77. }
  78. }
  79. }
  80. </script>
  81. <style scoped>
  82. .zp-swiper-container {
  83. /* #ifndef APP-NVUE */
  84. display: flex;
  85. /* #endif */
  86. flex-direction: column;
  87. flex: 1;
  88. }
  89. .zp-swiper-container-fixed {
  90. position: fixed;
  91. /* #ifndef APP-NVUE */
  92. height: auto;
  93. width: auto;
  94. /* #endif */
  95. top: 0;
  96. left: 0;
  97. bottom: 0;
  98. right: 0;
  99. }
  100. .zp-swiper-super {
  101. flex: 1;
  102. position: relative;
  103. }
  104. .zp-swiper {
  105. /* #ifndef APP-NVUE */
  106. height: 100%;
  107. width: 100%;
  108. position: absolute;
  109. top: 0;
  110. left: 0;
  111. /* #endif */
  112. /* #ifdef APP-NVUE */
  113. flex: 1;
  114. /* #endif */
  115. }
  116. .zp-swiper-item {
  117. height: 100%;
  118. }
  119. </style>