基于ElementUI二次封装弹窗组件

效果:

基于elementui弹窗的二次封装

一、自定义内容类型弹窗

<!-- 
  title:对话框的标题
  confirmLoading:当前是否处于提交中
  titleCenter:对话框标题居中方式
  footerCenter:底部按钮的对其方式
  visible:是否显示弹窗
  width:设置对话框的宽度
  beforeClose:允许您指定在对话框关闭之前将调用的函数
  closeOnClickModal:确定单击对话框外部(在模态叠加层上)是否会关闭对话框
  center:控制对话框是否在屏幕中央
  customClass:允许您为对话框指定自定义类。此类可用于将自定义样式应用于对话框
  showFooter:确定是否显示带有“取消”和“确认”按钮的默认页脚
 -->
<template>
  <el-dialog
    :visible.sync="dialogVisible"
    :width="width"
    :before-close="handleBeforeClose"
    :close-on-click-modal="closeOnClickModal"
    :center="center"
    :custom-class="customClass"
    :show-close="false"
  >
    <div
      slot="title"
      :style="{'textAlign': titleCenter,'font-size':'16px','font-weight':'bold'}"
    >
      <span>{{title}}</span>
    </div>
    <slot></slot>
    <div slot="footer" v-if="showFooter" :style="{'text-align': footerCenter}" class="dialog-footer">
      <el-button class="cancel-btn" @click="handleCancel" size="small">取消</el-button>
      <el-button class="primary-btn" type="primary"  :loading="confirmLoading" @click="handleConfirm" size="small"
        >{{ confirmLoading ? "提交中" : "确  定" }}</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
export default {
  name:"hsk-dialog",
  props: {
    title: { //对话框的标题
      type: String,
      default: "",
    },
    confirmLoading:{  //当前是否处于提交中
      type: Boolean,
      default: false,
    },
    titleCenter:{  //对话框标题居中方式
      type: String,
      default: "center",
    },
    footerCenter:{ //底部按钮的对其方式
      type: String,
      default: "center",
    },
    visible: { //是否显示弹窗
      type: Boolean,
      default: false,
    },
    width: { //设置对话框的宽度
      type: String,
      default: "400px",
    },
    beforeClose: { //允许您指定在对话框关闭之前将调用的函数
      type: Function,
      default: null,
    },
    closeOnClickModal: { //确定单击对话框外部(在模态叠加层上)是否会关闭对话框
      type: Boolean,
      default: true,
    },
    center: { //控制对话框是否在屏幕中央 ( true) 或不在屏幕中央 ( false)。
      type: Boolean,
      default: true,
    },
    customClass: {  //允许您为对话框指定自定义类。此类可用于将自定义样式应用于对话框
      type: String,
      default: "",
    },
    showFooter: { //确定是否显示带有“取消”和“确认”按钮的默认页脚
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      dialogVisible: this.visible,
    };
  },
  watch: {
    visible(newValue) {
      this.dialogVisible = newValue;
    },
    dialogVisible(newValue) {
      this.$emit("update:visible", newValue);
    },
  },
  methods: {
    handleBeforeClose(done) {
      if (this.beforeClose) {
        this.beforeClose(done);
      } else {
        done();
      }
    },
    handleCancel() {
      // this.$emit('update:visible', false);
      this.dialogVisible = false;
      this.$emit("cancel");
    },
    handleConfirm() {
      if (!this.confirmLoading) {
        // this.dialogVisible = false;
        this.$emit("confirm");
      }
      
    },
  },
};
</script>

<style scoped>
/* Add your custom styles here */
 /deep/.el-dialog__body{
  padding: 30px 55px !important;
}
.dialog-footer {
  text-align: right;
  margin-top: 10px;
}
.el-openDialog__header {
  margin-bottom: 10px;
}
.el-dialog__footer{
  margin-bottom: 31px;
}
.cancel-btn{
  width: 80px;
  height: 36px;
  background: #FFFFFF;
  border-radius: 2px 2px 2px 2px;
  opacity: 1;
  box-sizing: border-box;
  border: 1px solid #707070;
}
.primary-btn{
  margin-left:20px;
  width: 80px;
  height: 36px;
  background: #0759C4;
  box-sizing: border-box;
  border-radius: 2px 2px 2px 2px;
}
</style>

父组件使用

<template>
  <div>
    <el-button type="text" @click="openDialog">弹出窗口</el-button>
    <!-- <el-button @click="openDialog">打开对话框</el-button> -->
    <hsk-dialog
      :visible.sync="dialogVisible"
      title="自定义对话框"
      :width="width"
      :before-close="beforeCloseHandler"
      :close-on-click-modal="false"
      :center="false"
      :showFooter="true"
      custom-class="custom-dialog"
      :show-footer="false"
      @confirm="handleConfirm"
      @cancel="handleCancel"
      :confirm-loading="confirmLoading"
    >
      自定义内容及表单
    </hsk-dialog>
  </div>
</template>

<script>
export default {
  components: {
    // hskDialog
  },
  data() {
    return {
      confirmLoading: false,
      dialogVisible: false,
      width: "400px",
    };
  },
  methods: {
    openDialog() {
      this.dialogVisible = true;
    },
    beforeCloseHandler(done) {
      this.$message.info("点击了“X”操作");
      done();
    },
    handleConfirm() {
      // this.$message.success('点击了确定按钮');
      this.confirmLoading = true;
      this.$message.success("点击了确定按钮");
      setTimeout(() => {
        this.confirmLoading = false;
      }, 1000);
    },
    handleCancel() {
      this.$message.info("点击了取消按钮");
    }
  },
};
</script>
<style>
.a {
  text-align: left;
  margin-top: 0;
}
.codebox{
  line-height: 24px;
}
</style>

二、删除提示类型弹窗封装

/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
import {MessageBox} from "element-ui"
import "./styles/pop-up.css"
export function hskMsgbox (h, title,value,iconClass='',iconColor='') {
  const newDatas = [];
  const confirmText = Array.isArray(value) ? [...value] : [value];
  if(value.length===1){
    newDatas.push(h('i', { class: iconClass,style:'color:'+iconColor+';float: left;margin-right:5px;font-size:24px;'}),h('div', { style: 'padding-left:-6px;text-align: left;font-size: 14px;font-weight:bold;' }, confirmText[0]));
  }else{
    for (const i in confirmText) {
        if(i==='0'){
          newDatas.push(h('div', { class: iconClass,style:'color:'+iconColor+';float: left;margin-right:5px;font-size:24px;'}),h('div', { style: 'padding-left:-6px;text-align: left;font-size: 14px;font-weight:bold;' }, confirmText[i]));
        }else{
          newDatas.push(h('div', { style: 'padding-left:-6px;text-align: left;font-size: 12px' }, confirmText[i] ));
        }
    }
  }
  
   const promiseconfirm = new Promise((resolve, reject) => {
    MessageBox.confirm('Tip', {
      title: title,
      message:h('p', {style:"text-align: left;"}, [
        newDatas
      ]), 
      showCancelButton: true,
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      center: true
    }).then(() => {
      resolve(true)
    }).catch(() => {
      resolve(false)
    })
  })
  return promiseconfirm
}

删除提示类型弹窗样式文件

.el-message-box__title {
  text-align: center;
  font-size: 16px;
  font-weight: bold;
}
.el-message-box__header{
  padding-bottom: 6px !important;
  padding-top: 23px !important;
}
.el-message-box--center{
  padding-bottom:25px !important;
}

父组件使用

<template>
  <div>
    <el-button type="text" @click="deleteClick">删除样式一</el-button>
    <br />
    <el-button type="text" @click="deleteClick2">删除样式二</el-button>
    <br />
    <el-button type="text" @click="deleteClick3">删除样式三</el-button>
    <br />
    <el-button type="text" @click="deleteClick4">删除样式四</el-button>
  </div>
</template>

<script>
import { hskMsgbox } from "@/package/commonUtils.js";
export default {
  components: {
  },
  data() {
    return {
    };
  },
  methods: {
    //删除
    async deleteClick() {
      // confirmANewline
      const h = this.$createElement;
      // let abc = 11
      let confirmText1 = [
        `是否删除数据字典?`,
        // `删除后,数据无法找回,请谨慎操作。`,
      ];
      let a = await hskMsgbox(
        h,
        "删除数据字典",
        confirmText1
      );
      console.log("a", a);
    },
    //删除样式二
    async deleteClick2() {
      // confirmANewline
      const h = this.$createElement;
      // let abc = 11
      let confirmText1 = [
        `是否删除数据字典?`,
        `删除后,数据无法找回,请谨慎操作。`,
      ];
      let a = await hskMsgbox(
        h,
        "删除数据字典",
        confirmText1
      );
      console.log("a", a);
    },
    async deleteClick3() {
      // confirmANewline
      const h = this.$createElement;
      // let abc = 11
      let confirmText1 = [
        `是否删除数据字典?`,
      ];
      let a = await hskMsgbox(
        h,
        "删除数据字典",
        confirmText1,
        "el-icon-warning",
        "red"
      );
      console.log("a", a);
    },
    async deleteClick4() {
      // confirmANewline
      const h = this.$createElement;
      // let abc = 11
      let confirmText1 = [
        `是否删除数据字典?`,
        `删除后,数据无法找回,请谨慎操作。`,
      ];
      let a = await this.hskMsgbox(
        h,
        "删除角色",
        confirmText1,
        "el-icon-warning",
        "#E6A23C"
      );
      console.log("a", a);
    },
  },
};
</script>
<style>
</style>

提示弹窗取消和确认返回的是true和false

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/279728.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

重定向和转发的区别

重定向 1、定义 用户通过浏览器发送一个请求&#xff0c;Tomcat服务器接收这个请求&#xff0c;会给浏览器发送一个状态码302&#xff0c;并设置一个重定向的路径&#xff0c;浏览器如果接收到了这个302的状态码以后&#xff0c;就会去自动加载服务器设置的路径 一个页面跳转…

【测试开发与AIchat】它的思维跟大多数人还是一样的,都解决不了实际问题,可能是它也没有积累类似的经验[chatGPT]

分享一个人工智能{AI}解决问题的工具GPT(点我赶紧注册)&#xff0c;它是有GPT-4模型的。 它可以做很多事情&#xff0c;譬如问&#xff1a;开发平台功能 但是它仍然没有解决题主的问题。 源码如下&#xff1a; #....with smtplib.SMTP() as smtp:smtp.connect(smtp_server…

【两两交换链表中的节点】

Problem: 24. 两两交换链表中的节点 文章目录 思路解题方法Code 思路 把第一步的模拟过程的步骤记录下来 一共分为三个步骤 解题方法 创建虚拟头节点 循环什么时候结束&#xff0c;需要考虑问题 Q&#xff1a; 奇数链表结束条件&#xff1f;偶数链表结束条件&#xff1f;为什么…

一语道破爬虫,来揭开爬虫面纱

目录 一、爬虫&#xff08;网络蜘蛛(Spider)&#xff09; 1.1、是什么&#xff1a; 1.2、学习的原因 1.3、用在地方&#xff1a; 1.4、是否合法&#xff1a; 1.5、后果 案例&#xff1a; 二、应用领域 三、Robots协议 四、抓包 4.1、浏览器抓包 4.2、抓包工具 常见…

【数据结构复习之路】查找(严蔚敏版)万字详解

专栏&#xff1a;数据结构复习之路 复习完上面四章【线性表】【栈和队列】【串】【数组和广义表】【树和二叉树】【图】&#xff0c;我们接着复习 查找&#xff0c;这篇文章我写的非常详细且通俗易懂&#xff0c;看完保证会带给你不一样的收获。如果对你有帮助&#xff0c;看在…

深入学习Python与Vscode环境的安装与配置

上进小菜猪&#xff0c;沈工大软件工程专业&#xff0c;爱好敲代码&#xff0c;持续输出干货。 随着Python的广泛应用&#xff0c;使用一款高效的集成开发环境&#xff08;IDE&#xff09;变得尤为重要。而在众多IDE中&#xff0c;Visual Studio Code&#xff08;简称Vscode&a…

几种取时间的方法(附代码)

1.上古版 最原始的取时间的方法大概就是timelocaltime了&#xff0c;见代码&#xff1a; #include <stdio.h>#include <time.h>// gcc -o time_1 time_1.cint main(){time_t tm_now;time(&tm_now);// 或者写成 tm_now time(NULL);//1.直接打印&#xff1a;197…

【C++】开源:libev事件循环库配置使用

&#x1f60f;★,:.☆(&#xffe3;▽&#xffe3;)/$:.★ &#x1f60f; 这篇文章主要介绍libev事件循环库配置使用。 无专精则不能成&#xff0c;无涉猎则不能通。——梁启超 欢迎来到我的博客&#xff0c;一起学习&#xff0c;共同进步。 喜欢的朋友可以关注一下&#xff0c…

代码回滚(git reset)后push失败的解决方法

问题描述 代码本地回滚之后&#xff08;即 git reset 到之前的某个历史节点&#xff09;&#xff0c;push上去失败&#xff0c;并报出以下错误信息 ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to gitgithub.com:PisecesPeng/useg…

Strateg策略模式(组件协作)

策略模式&#xff08;组件协作&#xff09; 链接&#xff1a;策略模式实例代码 注解 目的 正常情况下&#xff0c;一个类/对象中会包含其所有可能会使用的内外方法&#xff0c;但是一般情况下&#xff0c;这些常使用的类都是由不同的父类继承、组合得来的&#xff0c;来实现…

精品Nodejs实现的校园疫情防控管理系统的设计与实现健康打卡

《[含文档PPT源码等]精品Nodejs实现的校园疫情防控管理系统的设计与实现[包运行成功]》该项目含有源码、文档、PPT、配套开发软件、软件安装教程、项目发布教程、包运行成功&#xff01; 软件开发环境及开发工具&#xff1a; 操作系统&#xff1a;Windows 10、Windows 7、Win…

【nodejs】Express概念与使用介绍

Express Express是基于Node.js平台&#xff0c;从内置模块http封装出来的第三方模块&#xff0c;可以更方便的开发Web服务器。 中文官网&#xff1a; http://www.expressjs.com.cn/ 一、基本使用 // 导入express const express require(express) // 创建web服务器 const a…

三、KMDF开发之 windbg基于网线的双机调试

目录 一 、搭建调试环境 目标机需要进入bios里面把security boot 设置为disable 1.1 网线链接 1.2 IP设置 1.2.1 关闭IPV6 1.2.2关闭防火墙 1.2.3目标机IP设置 1.2.4主机ip设置 二、设备组态 2.1 打开configure device 2.2 新增device 2.3 配置device 2.4 配置deb…

C++ Primer Plus----第十二章--类和动态内存分布

本章内容包括&#xff1a;对类成员使用动态内存分配&#xff1b;隐式和显式复制构造函数&#xff1b;隐式和显式重载赋值运算符&#xff1b;在构造函数中使用new所必须完成的工作&#xff1b;使用静态类成员&#xff1b;将定位new运算符用于对象&#xff1b;使用指向对象的指针…

IDEA中允许开启多个客户端

这个时候不要在客户端里创建socket对象时指定端口号了&#xff0c;否则会报错BindException

69内网安全-域横向CobaltStrikeSPNRDP

这节课主要讲spn和rdp协议&#xff0c; 案例一域横向移动RDP传递-Mimikatz rdp是什么&#xff0c;rdp是一个远程的链接协议&#xff0c;在linux上面就是ssh协议&#xff0c; 我们在前期信息收集的时候&#xff0c;得到一些hash值和明文密码可以进行一些相关协议的链接的&am…

python+django校园篮球论坛交流系统v5re9

本课题使用Python语言进行开发。基于web,代码层面的操作主要在PyCharm中进行&#xff0c;将系统所使用到的表以及数据存储到MySQL数据库中 技术栈 系统权限按管理员和用户这两类涉及用户划分。 (a) 管理员&#xff1b;管理员使用本系统涉到的功能主要有&#xff1a;首页、个人中…

Java Spring

目录 一、spring简介 1.1、什么是Spring 1.2 IOC 1.3、DI 二.创建Spring项目 2.1 创建一个普通的maven项目 2.2 引入maven依赖 三、Spring的创建和使用 3.1 创建Bean 3.2 将Bean放入到容器中 3.3 获取Bean对象 3.4、创建 Spring 上下文 3.5 获取指定的 Bean …

win部署stable-diffusion

win部署stable-diffusion 1.环境2.模型3.使用4.效果 1.环境 首先下载stable-diffusion-webui&#xff0c;这个包了一层ui&#xff0c;特别好用。 git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git然后搭建conda环境。 这里的pytorch&#xff0c;自己去…

挑战Python100题(8)

100+ Python challenging programming exercises 8 Question 71 Please write a program which accepts basic mathematic expression from console and print the evaluation result. 请编写一个从控制台接受基本数学表达式的程序,并打印评估结果。 Example: If the follo…
最新文章