z-paging-swiper.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 APP-PLUS || H5 || MP-WEIXIN
  71. safeAreaBottom = this.systemInfo.safeAreaInsets.bottom || 0;
  72. // #endif
  73. return safeAreaBottom;
  74. }
  75. }
  76. }
  77. </script>
  78. <style scoped>
  79. .zp-swiper-container {
  80. /* #ifndef APP-NVUE */
  81. display: flex;
  82. /* #endif */
  83. flex-direction: column;
  84. flex: 1;
  85. }
  86. .zp-swiper-container-fixed {
  87. position: fixed;
  88. /* #ifndef APP-NVUE */
  89. height: auto;
  90. width: auto;
  91. /* #endif */
  92. top: 0;
  93. left: 0;
  94. bottom: 0;
  95. right: 0;
  96. }
  97. .zp-swiper-super {
  98. flex: 1;
  99. position: relative;
  100. }
  101. .zp-swiper {
  102. /* #ifndef APP-NVUE */
  103. height: 100%;
  104. width: 100%;
  105. position: absolute;
  106. top: 0;
  107. left: 0;
  108. /* #endif */
  109. /* #ifdef APP-NVUE */
  110. flex: 1;
  111. /* #endif */
  112. }
  113. .zp-swiper-item {
  114. height: 100%;
  115. }
  116. </style>