index.vue 2.89 KB
<template>
  <uni-popup
    ref="tips"
    :type="position"
    :is-mask-click="false"
    :animation="false"
  >
    <view
      class="tips-wrapper"
      :style="{ width: popupW + 'rpx', minHeight: popupH + 'rpx' }"
    >
      <view class="tips-content">
        <view class="tips-title"
          >{{ title }}
          <view class="icon-close" @click="close">×</view>
        </view>
        <view class="tips-text" v-if="content">{{ content }}</view>
        <slot></slot>
      </view>
      <view class="tips-footer" v-if="isFooter">
        <view class="tips-btn close" @click="cancel()">{{
          cancelBtnText
        }}</view>
        <view class="tips-btn preview" @click="confirm()">{{
          confirmBtnText
        }}</view>
      </view>
    </view>
  </uni-popup>
</template>
<script>
export default {
  name: "MessageBox",
  data() {
    return {};
  },
  props: {
    isAutoClose: {
      type: Boolean,
      default: true,
    },
    position: {
      type: String,
      default: "center",
    },
    popupW: {
      type: Number,
    },
    popupH: {
      type: Number,
      default: 372,
    },
    isFooter: {
      type: Boolean,
      default: true,
    },
    title: {
      type: String,
      default: "提示",
    },
    content: {
      type: String,
      default: "",
    },
    confirmBtnText: {
      type: String,
      default: "确定",
    },
    cancelBtnText: {
      type: String,
      default: "取消",
    },
  },
  methods: {
    close() {
      this.$refs.tips.close();
      this.$emit("close");
    },
    open() {
      this.$refs.tips.open();
    },
    cancel() {
      this.$refs.tips.close();
      this.$emit("cancel");
    },
    confirm() {
      if (this.isAutoClose) this.$refs.tips.close();
      this.$emit("confirm");
    },
  },
};
</script>
<style scoped lang="scss">
.tips-wrapper {
  background: #ffffff;
  border-radius: 20rpx;
  height: 100%;
  .tips-content {
    padding: 48rpx;
    box-sizing: border-box;
    border-bottom: 1px solid #e8e8e8;
    height: calc(100% - 100rpx);
    .tips-title {
      position: relative;
      width: 100%;
      font-weight: 500;
      font-size: 32rpx;
      color: #292d33;
      text-align: center;
      .icon-close {
        position: absolute;
        right: 0;
        top: -30rpx;
        width: 160rpx;
        font-size: 50rpx;
        text-align: right;
        padding-right: 20rpx;
        line-height: 96rpx;
      }
    }
  }
  .tips-text {
    font-size: 30rpx;
    color: #5a5e66;
    letter-spacing: 1rpx;
    text-align: center;
    line-height: 40rpx;
    margin-top: 48rpx;
  }
  .tips-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100rpx;

    .close {
      color: #6c6c70;
    }
    .preview {
      color: #2c66f7;
    }
  }
  .tips-btn {
    width: 50%;
    text-align: center;
    font-size: 32rpx;
    text-align: center;
    line-height: 44rpx;
  }
}
</style>