123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <template>
- <view class="custom-dialog" v-if="visible">
- <view class="dialog-mask" @click="closeDialog"></view>
- <view class="dialog-content" :class="{'dialog-show': visible}" :animation="animationData" :style="{ width: contentWidth, background: backgroundColor }">
- <view class="dialog-header" v-if="title && title.length > 0">
- <text class="dialog-title">{{title}}</text>
- </view>
- <view class="dialog-close" @click="closeDialog" v-if="!closeImg">×</view>
- <image v-if="closeImg" class="dialog-close-img" :src="closeImg" @click="closeDialog" mode="aspectFit" :style="{ top: closeImgTop && closeImgTop.length > 0 ? closeImgTop : '20rpx' }"></image>
- <view class="dialog-body">
- <slot></slot>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'CustomDialog',
- props: {
- visible: {
- type: Boolean,
- default: false
- },
- title: {
- type: String,
- default: '提示'
- },
- contentWidth: {
- type: String,
- default: '600rpx'
- },
- backgroundColor: {
- type: String,
- default: '#fff'
- },
- closeImg: {
- type: String,
- default: ''
- },
- closeImgTop: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- animationData: {}
- }
- },
- watch: {
- visible(val) {
- if (val) {
- this.playShowAnimation()
- } else {
- this.playHideAnimation()
- }
- }
- },
- methods: {
- playShowAnimation() {
- const animation = uni.createAnimation({
- duration: 300,
- timingFunction: 'ease'
- })
-
- animation.scale(0.8).opacity(0).step({ duration: 0 })
- animation.scale(1.1).opacity(1).step({ duration: 150 })
- animation.scale(0.95).step({ duration: 75 })
- animation.scale(1).step({ duration: 75 })
-
- this.animationData = animation.export()
- },
- playHideAnimation() {
- const animation = uni.createAnimation({
- duration: 200,
- timingFunction: 'ease'
- })
-
- animation.scale(0.95).opacity(0.8).step({ duration: 100 })
- animation.scale(0.8).opacity(0).step({ duration: 100 })
-
- this.animationData = animation.export()
- },
- closeDialog() {
- this.$emit('update:visible', false)
- this.$emit('close')
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .custom-dialog {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 900;
- display: flex;
- align-items: center;
- justify-content: center;
-
- .dialog-mask {
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: rgba(0, 0, 0, 0.6);
- }
-
- .dialog-content {
- position: relative;
- border-radius: 16rpx;
- overflow: hidden;
- opacity: 0;
- transform: scale(0.8);
-
- &.dialog-show {
- opacity: 1;
- transform: scale(1);
- }
- }
-
- .dialog-header {
- position: relative;
- padding: 30rpx;
- text-align: center;
- border-bottom: 1rpx solid #eee;
-
- .dialog-title {
- font-size: 32rpx;
- font-weight: 500;
- color: #333;
- }
- }
-
- .dialog-close {
- position: absolute;
- right: 20rpx;
- top: 20rpx;
- width: 60rpx;
- height: 60rpx;
- line-height: 60rpx;
- text-align: center;
- font-size: 40rpx;
- color: #999;
- cursor: pointer;
- z-index: 1;
-
- &:active {
- opacity: 0.7;
- }
- }
- .dialog-close-img {
- position: absolute;
- right: 20rpx;
- width: 60rpx;
- height: 60rpx;
- z-index: 1;
- cursor: pointer;
-
- &:active {
- opacity: 0.7;
- }
- }
-
- .dialog-body {
- padding: 0rpx;
- }
- }
- </style>
|