123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <template>
- <view class="cm-drawer">
- <view class="mask" v-if="visible" :style="[offsetSize, { zIndex: zIndex - 1 }]" @click="$emit('close')"></view>
- <view class="drawer-content" :class="[position]" :style="[offsetSize, { zIndex: zIndex }]">
- <uni-transition :mode-class="modeClass" :show="visible">
- <view class="content">
- <!-- 关闭弹框按钮 -->
- <view class="iconfont icon-iconfontguanbi close" @click="$emit('close')"></view>
- <view class="title" v-if="title">{{ title }}</view>
- <!-- 自定义插槽 -->
- <view><slot></slot></view>
- </view>
- </uni-transition>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'cm-drawer',
- props: {
- title: {
- type: String,
- default: ''
- },
- visible: {
- type: Boolean,
- default: false
- },
- position: {
- type: String,
- default: 'center'
- },
- offset: {
- type: Number,
- default: 0
- },
- zIndex: {
- type: Number,
- default: 99999
- }
- },
- computed: {
- offsetSize() {
- if (this.position === 'center' || this.offset === 0) {
- return {}
- }
- return {
- [this.position]: this.offset + 'rpx'
- }
- },
- modeClass() {
- let name = 'fade'
- switch (this.position) {
- case 'center':
- name = 'fade'
- break
- case 'top':
- name = 'slide-top'
- break
- case 'right':
- name = 'slide-right'
- break
- case 'bottom':
- name = 'slide-bottom'
- break
- case 'left':
- name = 'slide-left'
- break
- default:
- name = 'fade'
- break
- }
- return name
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- $drawer-size: 100rpx;
- .mask {
- position: fixed;
- bottom: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background: rgba(0, 0, 0, 0.5);
- }
- .cm-drawer {
- .drawer-content {
- position: fixed;
- &.bottom {
- left: 0;
- bottom: 0;
- .content {
- border-radius: 16rpx 16rpx 0 0;
- }
- }
- &.top {
- top: 0;
- left: 0;
- .content {
- border-radius: 0 0 16rpx 16rpx;
- }
- }
- &.right {
- top: 0;
- right: 0;
- .content {
- border-radius: 16rpx 0 16rpx 0;
- }
- }
- &.left {
- top: 0;
- left: 0;
- .content {
- border-radius: 0 16rpx 16rpx 0;
- }
- }
- &.center {
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- .content {
- width: 702rpx;
- min-height: 600rpx;
- max-height: 800rpx;
- overflow-y: scroll;
- border-radius: 16rpx;
- }
- }
- .content {
- position: relative;
- width: 750rpx;
- min-height: 180rpx;
- background: #fff;
- box-sizing: border-box;
- padding: 24rpx;
- .close {
- position: absolute;
- top: 26rpx;
- right: 26rpx;
- font-size: 34rpx;
- color: #b2b2b2;
- width: 60rpx;
- height: 60rpx;
- text-align: center;
- line-height: 60rpx;
- }
- .title {
- width: 100%;
- word-break: break-all;
- overflow: hidden;
- line-height: 50rpx;
- height: 50rpx;
- text-overflow: ellipsis;
- text-align: center;
- font-size: 34rpx;
- color: #333333;
- }
- }
- }
- }
- </style>
|