123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <template>
- <view v-if="isShow" class="container">
- <wyb-transition :contentStyle="maskRoot" :isContentShow="isPopupShow" :typeList="['fade']" :duration="duration">
- <view :style="maskRoot" @tap="close" />
- </wyb-transition>
- <wyb-transition :contentStyle="root" :isContentShow="isPopupShow" :zoomLessenMulti="zoomLessenMulti" :typeList="popupAnim" mode="ease-out" :duration="duration">
- <view v-if="showCloseIcon" class="iconfont icon-close close" :style="closeRoot" @tap="hide" />
- <slot></slot>
- </wyb-transition>
- </view>
- </template>
- <script>
- import wybTransition from '../wyb-transition/wyb-transition.vue'
- export default {
- components: {
- wybTransition
- },
- data() {
- return {
- w: uni.getSystemInfoSync().screenWidth,
- h: uni.getSystemInfoSync().screenHeight,
- root: '',
- maskRoot: '',
- closeRoot: '',
- isShow: false,
- isPopupShow: false,
- popupAnim: ['slide-up']
- }
- },
- props: {
- type: {
- type: String,
- default: 'bottom'
- },
- mode: {
- type: String,
- default: 'size-auto'
- },
- height: {
- type: [String, Number],
- default: 400
- },
- width: {
- type: [String, Number],
- default: 500
- },
- radius: {
- type: [String, Number],
- default: 0
- },
- zIndex: {
- type: [String, Number],
- default: 10076
- },
- maskClickClose: {
- type: Boolean,
- default: true
- },
- maskAlpha: {
- type: Number,
- default: 0.5
- },
- duration: {
- type: Number,
- default: 400
- },
- showCloseIcon: {
- type: Boolean,
- default: false
- },
- centerAnim: {
- type: String,
- default: 'zoom-lessen'
- },
- closeIconPos: {
- type: String,
- default: 'top-right'
- },
- bgColor: {
- type: String,
- default: '#ffffff'
- },
- zoomLessenMulti: {
- type: Number,
- default: 1.15
- }
- },
- methods: {
- processStyle() {
- let style = 'z-index: ' + this.zIndex + '; '
- style += 'background-color: ' + this.bgColor + '; position: fixed; '
- switch (this.type) {
- case 'bottom':
- if (this.mode === 'size-fixed') {
- style += 'height: ' + this.height + 'rpx; '
- } else if (this.mode === 'size-auto') {
- style += 'min-height: ' + this.height + 'rpx; '
- style += 'height: auto; '
- }
- style += 'bottom: 0; left: 0; right: 0; '
- style += 'border-top-left-radius: ' + this.radius + 'px; '
- style += 'border-top-right-radius: ' + this.radius + 'px; '
- style += 'width: 100%; '
- this.popupAnim = ['slide-up']
- break
- case 'top':
- if (this.mode === 'size-fixed') {
- style += 'height: ' + this.height + 'rpx; '
- } else if (this.mode === 'size-auto') {
- style += 'min-height: ' + this.height + 'rpx; '
- style += 'height: auto; '
- }
- style += 'top: 0; left: 0; right: 0; '
- style += 'border-bottom-left-radius: ' + this.radius + 'px; '
- style += 'border-bottom-right-radius: ' + this.radius + 'px; '
- style += 'width: 100%; '
- this.popupAnim = ['slide-down']
- break
- case 'left':
- if (this.mode === 'size-fixed') {
- style += 'width: ' + this.width + 'rpx; '
- } else if (this.mode === 'size-auto') {
- style += 'min-width: ' + this.width + 'rpx; '
- style += 'width: auto; '
- }
- style += 'height: 100%; '
- style += 'top: 0; left: 0; bottom: 0; '
- style += 'border-top-right-radius: ' + this.radius + 'px; '
- style += 'border-bottom-right-radius: ' + this.radius + 'px; '
- this.popupAnim = ['slide-left']
- break
- case 'right':
- if (this.mode === 'size-fixed') {
- style += 'width: ' + this.width + 'rpx; '
- } else if (this.mode === 'size-auto') {
- style += 'min-width: ' + this.width + 'rpx; '
- style += 'width: auto; '
- }
- style += 'height: 100%; '
- style += 'top: 0; right: 0; bottom: 0; '
- style += 'border-top-left-radius: ' + this.radius + 'px; '
- style += 'border-bottom-left-radius: ' + this.radius + 'px; '
- this.popupAnim = ['slide-right']
- break
- case 'center':
- style += 'border-radius: ' + this.radius + 'px;'
- style += 'width: ' + this.width + 'rpx; '
- style += 'height: ' + this.height + 'rpx; '
- let statusBarHeight = uni.getSystemInfoSync().statusBarHeight
- // #ifdef H5
- style += 'left: ' + (this.w - this.rpxToPx(this.width)) / 2 + 'px; top: ' + (this.h - this.rpxToPx(this.height)) / 2 +
- 'px; '
- // #endif
- // #ifndef H5 || MP-WEIXIN
- style += 'left: ' + (this.w - this.rpxToPx(this.width)) / 2 + 'px; top: ' + (((this.h - this.rpxToPx(this.height)) / 2) -
- 45 - statusBarHeight) + 'px; '
- // #endif
- // #ifdef MP-WEIXIN
- let navBarHeight = wx.getMenuButtonBoundingClientRect().bottom
- style += 'left: ' + (this.w - this.rpxToPx(this.width)) / 2 + 'px; top: ' + (this.h - this.rpxToPx(this.height)) / 2 -
- statusBarHeight - navBarHeight + 'px; '
- // #endif
- if (this.centerAnim === 'zoom-lessen') {
- this.popupAnim = ['fade', 'zoom-lessen']
- } else if (this.centerAnim === 'zoom-largen') {
- this.popupAnim = ['fade', 'zoom-largen']
- } else if (this.centerAnim === 'fade') {
- this.popupAnim = ['fade']
- } else if (this.centerAnim === 'bounce') {
- this.popupAnim = ['bounce', 'fade']
- } else if (this.centerAnim === 'slide-up') {
- this.popupAnim = ['fade', 'slide-up']
- } else if (this.centerAnim === 'slide-down') {
- this.popupAnim = ['fade', 'slide-down']
- }
- break
- }
- return style
- },
- processMask() {
- let style = 'z-index: ' + (parseInt(this.zIndex) - 1) + '; '
- style += 'background-color: rgba(0, 0, 0, ' + this.maskAlpha +
- '); position: fixed; top: 0; left: 0; right: 0; bottom: 0;'
- style += 'width: ' + this.w + 'px; '
- style += 'height: ' + this.h + 'px; '
- return style
- },
- processClose() {
- let style = 'position: absolute; font-size: 40rpx; color: #808080;'
- switch (this.closeIconPos) {
- case 'top-right':
- style += 'top: 22rpx; right: 22rpx;'
- break
- case 'top-left':
- style += 'top: 22rpx; left: 22rpx;'
- break
- case 'bottom-left':
- style += 'bottom: 22rpx; left: 22rpx;'
- break
- case 'bottom-right':
- style += 'bottom: 22rpx; right: 22rpx;'
- break
- }
- return style
- },
- close() {
- this.maskClickClose && this.hide()
- },
- show() {
- this.root = this.processStyle()
- this.maskRoot = this.processMask()
- this.closeRoot = this.processClose()
- this.isShow = true
- setTimeout(function() {
- this.isPopupShow = true
- setTimeout(function() {
- this.$emit('show')
- }.bind(this), this.duration + 10)
- }.bind(this), 10)
- },
- hide() {
- this.isPopupShow = false
- setTimeout(function() {
- this.isShow = false
- this.$emit('hide')
- }.bind(this), this.duration + 10)
- },
- rpxToPx(rpx) {
- return rpx / 750 * this.w
- }
- }
- }
- </script>
- <style>
- @import "./iconfont.css";
- </style>
|