封装dialog 确认弹窗

在项目中经常出现需要确认弹框的地方 由于样式都是根据ui确认 不方便基于组件更改 于是自己写了一套

import Vue from 'vue'
import Deletelog from "@/components/deletelog.vue"; 

const JSDeletelog = Vue.extend(Deletelog)

/** JS 调用删除对话提示框 */
export function useDeleteLog(message, confirmCallBack, propsData = {}) {

  function destroy() {
    instance.$destroy()
    instance.$el.remove();
  }

  const instance = new JSDeletelog({
    propsData: {
      isVisible: true,
      content: message,
      ...propsData
    },
    mounted() {
      this.$once('queryDelete', () => {
        confirmCallBack?.()
        destroy()
      })
      this.$once('cancelDelte', () => {
        destroy()
      })
    }
  })

  instance.$mount()

  document.body.appendChild(instance.$el)
}

下面是vue页面

<template>
  <FullScreenDialog
    width="560px"
    height="200px"
    :visible.sync="isVisible"
    class="deleteVisible"
    style="margin-top: 20vh"
    append-to-body
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <div class="dialogContent">
      <div class="df">
        <img src="../assets/img/delete.png" alt="" />
        <div class="right">
          <div style="font-size: 20px; color: #3a3b40; margin-top: 27px">
            {{ content }}
          </div>
        </div>
      </div>
      <div class="df" style="margin-top: 30px">
        <div
          class="saveBtn"
          style="margin-left: 300px"
          v-loading="loading"
          element-loading-spinner="el-icon-loading"
          @click="queryDelete()"
        >
          {{ confirmButtonText }}
        </div>
        <div class="cancelBtn" style="margin-left: 8px" @click="cancelDelte()">
          {{ cancelButtonText }}
        </div>
      </div>
    </div>
  </FullScreenDialog>
</template>

<script>
export default {
  name: "deletelog",
  props: {
    isVisible: {
      type: Boolean,
      default: false,
    },
    content: {
      type: String,
      default: "数据",
    },
    loading: {
      type: Boolean,
      default: false,
    },
    confirmButtonText: {
      type: String,
      default: "确定",
    },
    cancelButtonText: {
      type: String,
      default: "取消",
    },
  },
  data() {
    return {};
  },
  methods: {
    queryDelete() {
      this.$emit("queryDelete");
    },
    cancelDelte() {
      this.$emit("cancelDelte");
    },
  },
};
</script>

<style scoped lang="scss">
.deleteVisible ::v-deep .el-dialog__headerbtn > i {
  display: none;
}
.dialogContent {
  padding: 30px;
  img {
    margin-right: 30px;
    object-fit: contain;
  }
  .right {
    padding-top: 10px;

    div {
      margin-bottom: 15px;
      line-height: 24px;
    }
  }
}
</style>

下面是在项目中使用

const func = () => {
}
const message = '确定删除该列吗?'
useDeleteLog(message, func);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值