vue3-confirm组件封装

<template>
  <transition name="confirm-fade">
    <div class="b-confirm" v-show="$props.visible">
      <!-- 头部标题 -->
      <div class="b-confirm-header">
        <slot name="header">
          <b-icon
            name="setting"
            :style="{ fontSize: '60px', color: 'red' }"
          ></b-icon>
        </slot>
        <b-icon name="close" class="b-close-icon" @click="close"></b-icon>
      </div>
      <!-- 内容区域 -->
      <div class="b-confirm-content">
        <slot>
          <div>删除后无法恢复,</div>
          <div>确定删除?</div>
        </slot>
      </div>
      <!-- 底部按钮 -->
      <div class="b-confirm-footer">
        <div class="b-confirm-btn">
          <b-button type="default" @click="close">取消</b-button>
          <b-button type="primary" @click="ok">确认</b-button>
        </div>
      </div>
    </div>
  </transition>
  <!-- 遮罩层 -->
  <div class="mask" v-show="$props.visible" @click="close"></div>
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import BButton from '@/components/button/src/button.vue'
import BIcon from '@/components/icon/src/icon.vue'

export default defineComponent({
  name: 'BConfirm',
  components: { BButton, BIcon },
  props: {
    visible: {
      type: Boolean as PropType<boolean>,
      default: false
    }
  },
  emits: ['cancel', 'update:visible', 'submit'],
  setup(props, { emit }) {
    // 取消

    const close = () => {
      emit('cancel')
      emit('update:visible', false)
    }
    // 确认
    const ok = () => {
      emit('submit')
      emit('update:visible', false)
    }

    return {
      close,
      ok
    }
  }
})
</script>

<style scoped lang="less">
@import "../style/confirm.less";
</style>

css部分:

// 遮罩层
.mask {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 998;
  width: 100%;
  height: 100%;
  background-color: rgb(0 0 0 / 30%);
}

.b-confirm {
  position: fixed;
  top: 45%;
  left: 50%;
  z-index: 999;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 460px;
  height: 304px;
  background-color: #fff;
  border-radius: 8px;
  transition: 0.5s;
  transform: translate(-50%, -50%);

  .b-confirm-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;

    .b-close-icon {
      position: absolute;
      top: 21px;
      right: 20px;
      width: 22px !important;
      height: 22px !important;
      cursor: pointer;
    }
  }

  // 内容
  .b-confirm-content {
    position: absolute;
    top: 128px;
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0 94px;
    font-size: 20px;
    font-weight: 700;
    line-height: 28px;
    color: #242934;
  }

  // 底部按钮
  .b-confirm-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 60px;
    padding-bottom: 48px;
    border: none;

    .b-confirm-btn {
      display: flex;
      justify-content: center;

      button {
        margin-left: 12px;
      }
    }
  }
}

// 模态框展示隐藏的动画
.confirm-fade-enter-active {
  transition: all 0.3s ease-out;
}

.confirm-fade-leave-active {
  transition: all 0.3s cubic-bezier(1, 0.5, 0.8, 1);
}

.confirm-fade-enter-from,
.confirm-fade-leave-to {
  opacity: 0;
  transform: translate(-50%, -50%) scale3d(0, 0, 0);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值