123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <template>
- <view>
- <sjs src="../wxs/utils.sjs" module="utils" />
- <van-overlay :wx:if="overlay" :show="show" :z-index="zIndex" :custom-style="overlayStyle" :duration="duration" @click="onClickOverlay" />
- <view
- :wx:if="inited"
- :class="'custom-class ' + classes + ' ' + utils.bem('popup', [position, { round, safe: safeAreaInsetBottom, safeTop: safeAreaInsetTop }])"
- :style="
- 'z-index: ' +
- zIndex +
- '; -webkit-transition-duration:' +
- currentDuration +
- 'ms; transition-duration:' +
- currentDuration +
- 'ms; ' +
- (display ? '' : 'display: none;') +
- ';' +
- customStyle
- "
- @transitionend="onTransitionEnd"
- >
- <slot />
- <van-icon :wx:if="closeable" :name="closeIcon" :class="'van-popup__close-icon van-popup__close-icon--' + closeIconPosition" @tap.native="onClickCloseIcon" />
- </view>
- </view>
- </template>
- <script>
- import { VantComponent } from '../common/component';
- import { transition } from '../mixins/transition';
- export default {
- data() {
- return {
- show: '',
- duration: '',
- inited: '',
- classes: '',
- display: false,
- currentDuration: ''
- };
- },
- classes: ['enter-class', 'enter-active-class', 'enter-to-class', 'leave-class', 'leave-active-class', 'leave-to-class'],
- mixins: [transition(false)],
- props: {
- round: Boolean,
- closeable: Boolean,
- customStyle: String,
- overlayStyle: String,
- transition: {
- type: String
- },
- zIndex: {
- type: Number,
- default: 100
- },
- overlay: {
- type: Boolean,
- default: true
- },
- closeIcon: {
- type: String,
- default: 'cross'
- },
- closeIconPosition: {
- type: String,
- default: 'top-right'
- },
- closeOnClickOverlay: {
- type: Boolean,
- default: true
- },
- position: {
- type: String,
- default: 'center'
- },
- safeAreaInsetBottom: {
- type: Boolean,
- default: true
- },
- safeAreaInsetTop: {
- type: Boolean,
- default: false
- }
- },
- created() {
- this.observeClass();
- },
- methods: {
- onClickCloseIcon() {
- this.$emit('close');
- },
- onClickOverlay() {
- this.$emit('click-overlay');
- if (this.closeOnClickOverlay) {
- this.$emit('close');
- }
- },
- observeClass() {
- const { transition, position } = this;
- const updateData = {
- name: transition || position
- };
- if (transition === 'none') {
- updateData.duration = 0;
- }
- this.setData(updateData);
- },
- onTransitionEnd() {
- console.log('占位:函数 onTransitionEnd 未声明');
- }
- },
- watch: {
- transition: {
- handler: function () {
- const { transition, position } = this;
- const updateData = {
- name: transition || position
- };
- if (transition === 'none') {
- updateData.duration = 0;
- }
- this.setData(updateData);
- },
- immediate: true
- },
- position: {
- handler: function () {
- const { transition, position } = this;
- const updateData = {
- name: transition || position
- };
- if (transition === 'none') {
- updateData.duration = 0;
- }
- this.setData(updateData);
- },
- immediate: true
- }
- }
- };
- </script>
- <style>
- @import '../common/index.ttss';
- .van-popup {
- position: fixed;
- box-sizing: border-box;
- max-height: 100%;
- overflow-y: auto;
- transition-timing-function: ease;
- -webkit-animation: ease both;
- animation: ease both;
- -webkit-overflow-scrolling: touch;
- background-color: #fff;
- background-color: var(--popup-background-color, #fff);
- }
- .van-popup--center {
- top: 50%;
- left: 50%;
- -webkit-transform: translate3d(-50%, -50%, 0);
- transform: translate3d(-50%, -50%, 0);
- }
- .van-popup--center.van-popup--round {
- border-radius: 20px;
- border-radius: var(--popup-round-border-radius, 20px);
- }
- .van-popup--top {
- top: 0;
- left: 0;
- width: 100%;
- }
- .van-popup--top.van-popup--round {
- border-radius: 0 0 20px 20px;
- border-radius: 0 0 var(--popup-round-border-radius, 20px) var(--popup-round-border-radius, 20px);
- }
- .van-popup--right {
- top: 50%;
- right: 0;
- -webkit-transform: translate3d(0, -50%, 0);
- transform: translate3d(0, -50%, 0);
- }
- .van-popup--right.van-popup--round {
- border-radius: 20px 0 0 20px;
- border-radius: var(--popup-round-border-radius, 20px) 0 0 var(--popup-round-border-radius, 20px);
- }
- .van-popup--bottom {
- bottom: 0;
- left: 0;
- width: 100%;
- }
- .van-popup--bottom.van-popup--round {
- border-radius: 20px 20px 0 0;
- border-radius: var(--popup-round-border-radius, 20px) var(--popup-round-border-radius, 20px) 0 0;
- }
- .van-popup--left {
- top: 50%;
- left: 0;
- -webkit-transform: translate3d(0, -50%, 0);
- transform: translate3d(0, -50%, 0);
- }
- .van-popup--left.van-popup--round {
- border-radius: 0 20px 20px 0;
- border-radius: 0 var(--popup-round-border-radius, 20px) var(--popup-round-border-radius, 20px) 0;
- }
- .van-popup--bottom.van-popup--safe {
- padding-bottom: env(safe-area-inset-bottom);
- }
- .van-popup--safeTop {
- padding-top: env(safe-area-inset-top);
- }
- .van-popup__close-icon {
- position: absolute;
- z-index: 1;
- z-index: var(--popup-close-icon-z-index, 1);
- color: #969799;
- color: var(--popup-close-icon-color, #969799);
- font-size: 18px;
- font-size: var(--popup-close-icon-size, 18px);
- }
- .van-popup__close-icon--top-left {
- top: 16px;
- top: var(--popup-close-icon-margin, 16px);
- left: 16px;
- left: var(--popup-close-icon-margin, 16px);
- }
- .van-popup__close-icon--top-right {
- top: 16px;
- top: var(--popup-close-icon-margin, 16px);
- right: 16px;
- right: var(--popup-close-icon-margin, 16px);
- }
- .van-popup__close-icon--bottom-left {
- bottom: 16px;
- bottom: var(--popup-close-icon-margin, 16px);
- left: 16px;
- left: var(--popup-close-icon-margin, 16px);
- }
- .van-popup__close-icon--bottom-right {
- right: 16px;
- right: var(--popup-close-icon-margin, 16px);
- bottom: 16px;
- bottom: var(--popup-close-icon-margin, 16px);
- }
- .van-popup__close-icon:active {
- opacity: 0.6;
- }
- .van-scale-enter-active,
- .van-scale-leave-active {
- transition-property: opacity, -webkit-transform;
- transition-property: opacity, transform;
- transition-property: opacity, transform, -webkit-transform;
- }
- .van-scale-enter,
- .van-scale-leave-to {
- -webkit-transform: translate3d(-50%, -50%, 0) scale(0.7);
- transform: translate3d(-50%, -50%, 0) scale(0.7);
- opacity: 0;
- }
- .van-fade-enter-active,
- .van-fade-leave-active {
- transition-property: opacity;
- }
- .van-fade-enter,
- .van-fade-leave-to {
- opacity: 0;
- }
- .van-center-enter-active,
- .van-center-leave-active {
- transition-property: opacity;
- }
- .van-center-enter,
- .van-center-leave-to {
- opacity: 0;
- }
- .van-bottom-enter-active,
- .van-bottom-leave-active,
- .van-left-enter-active,
- .van-left-leave-active,
- .van-right-enter-active,
- .van-right-leave-active,
- .van-top-enter-active,
- .van-top-leave-active {
- transition-property: -webkit-transform;
- transition-property: transform;
- transition-property: transform, -webkit-transform;
- }
- .van-bottom-enter,
- .van-bottom-leave-to {
- -webkit-transform: translate3d(0, 100%, 0);
- transform: translate3d(0, 100%, 0);
- }
- .van-top-enter,
- .van-top-leave-to {
- -webkit-transform: translate3d(0, -100%, 0);
- transform: translate3d(0, -100%, 0);
- }
- .van-left-enter,
- .van-left-leave-to {
- -webkit-transform: translate3d(-100%, -50%, 0);
- transform: translate3d(-100%, -50%, 0);
- }
- .van-right-enter,
- .van-right-leave-to {
- -webkit-transform: translate3d(100%, -50%, 0);
- transform: translate3d(100%, -50%, 0);
- }
- </style>
|