123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <template>
- <view :class="fixed?'zp-swiper-container zp-swiper-container-fixed':'zp-swiper-container'" :style="[finalSwiperStyle]">
-
- <view v-if="cssSafeAreaInsetBottom===-1" class="zp-safe-area-inset-bottom"></view>
-
- <slot v-if="$slots.top" name="top" />
- <view class="zp-swiper-super">
- <view v-if="$slots.left" :class="{'zp-swiper-left':true,'zp-absoulte':isOldWebView}">
- <slot name="left" />
- </view>
- <view :class="{'zp-swiper':true,'zp-absoulte':isOldWebView}" :style="[swiperContentStyle]">
- <slot />
- </view>
- <view v-if="$slots.right" :class="{'zp-swiper-right':true,'zp-absoulte zp-right':isOldWebView}">
- <slot name="right" />
- </view>
- </view>
- <slot v-if="$slots.bottom" name="bottom" />
- </view>
- </template>
- <script>
- export default {
- name: "z-paging-swiper",
- data() {
- return {
- systemInfo: null,
- cssSafeAreaInsetBottom: -1,
- swiperContentStyle: {}
- };
- },
- props: {
-
- fixed: {
- type: Boolean,
- default: true
- },
-
- safeAreaInsetBottom: {
- type: Boolean,
- default: false
- },
-
- swiperStyle: {
- type: Object,
- default: function() {
- return {};
- },
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.systemInfo = uni.getSystemInfoSync();
- })
-
- this._getCssSafeAreaInsetBottom();
-
- this._updateLeftAndRightWidth();
- this.swiperContentStyle = {'flex': '1'};
-
- this.swiperContentStyle = {width: '100%',height: '100%'};
-
- },
- computed: {
- finalSwiperStyle() {
- let swiperStyle = this.swiperStyle;
- if (!this.systemInfo) return swiperStyle;
- let windowTop = this.systemInfo.windowTop;
-
-
-
- const pageHeadNode = document.getElementsByTagName("uni-page-head");
- if (!pageHeadNode.length) windowTop = 0;
-
- const windowBottom = this.systemInfo.windowBottom;
- if (this.fixed) {
- if (windowTop && !swiperStyle.top) {
- swiperStyle.top = windowTop + 'px';
- }
- if (!swiperStyle.bottom) {
- let bottom = windowBottom ? windowBottom : 0;
- if (this.safeAreaInsetBottom) {
- bottom += this.safeAreaBottom;
- }
- if(bottom > 0){
- swiperStyle.bottom = bottom + 'px';
- }
- }
- }
- return swiperStyle;
- },
- safeAreaBottom() {
- if(!this.systemInfo){
- return 0;
- }
- let safeAreaBottom = 0;
-
- safeAreaBottom = this.systemInfo.safeAreaInsets.bottom || 0;
-
-
- safeAreaBottom = this.cssSafeAreaInsetBottom === -1 ? 0 : this.cssSafeAreaInsetBottom;
-
- return safeAreaBottom;
- },
- isOldWebView() {
-
- try {
- const systemInfos = uni.getSystemInfoSync().system.split(' ');
- const deviceType = systemInfos[0];
- const version = parseInt(systemInfos[1].slice(0,1));
- if ((deviceType === 'iOS' && version <= 10) || (deviceType === 'Android' && version <= 6)) {
- return true;
- }
- } catch(e){
- return false;
- }
-
- return false;
- }
- },
- methods: {
-
- _getCssSafeAreaInsetBottom(){
- const query = uni.createSelectorQuery().in(this);
- query.select('.zp-safe-area-inset-bottom').boundingClientRect(res => {
- if (res) {
- this.cssSafeAreaInsetBottom = res.height;
- }
- }).exec();
- },
-
- _updateLeftAndRightWidth(){
- if (!this.isOldWebView) return;
- this.$nextTick(() => {
- let delayTime = 0;
-
- delayTime = 10;
-
- setTimeout(() => {
- const query = uni.createSelectorQuery().in(this);
- query.select('.zp-swiper-left').boundingClientRect(res => {
- this.$set(this.swiperContentStyle,'left',res ? res[0].width + 'px' : '0px');
- }).exec();
- query.select('.zp-swiper-right').boundingClientRect(res => {
- this.$set(this.swiperContentStyle,'right',res ? res[0].width + 'px' : '0px');
- }).exec();
- }, delayTime)
- })
- }
- }
- }
- </script>
- <style scoped>
- .zp-swiper-container {
-
- display: flex;
-
- flex-direction: column;
- flex: 1;
- }
- .zp-swiper-container-fixed {
- position: fixed;
-
- height: auto;
- width: auto;
-
- top: 0;
- left: 0;
- bottom: 0;
- right: 0;
- }
-
- .zp-safe-area-inset-bottom {
- position: absolute;
-
- height: env(safe-area-inset-bottom);
-
- }
- .zp-swiper-super {
- flex: 1;
- position: relative;
-
- display: flex;
-
- flex-direction: row;
- }
-
- .zp-swiper-left,.zp-swiper-right{
-
- height: 100%;
-
- }
- .zp-swiper {
- flex: 1;
-
- height: 100%;
- width: 100%;
-
- }
-
- .zp-absoulte {
-
- position: absolute;
- top: 0;
- width: auto;
-
- }
-
- .zp-right{
- right: 0;
- }
-
- .zp-swiper-item {
- height: 100%;
- }
- </style>
|