SweetAlert2 - 漂亮可定制的 JavaScript 弹窗

https://sweetalert2.github.io/
https://github.com/sweetalert2/sweetalert2

安装:

bash 复制代码
npm install sweetalert2

封装:

javascript 复制代码
import Swal from 'sweetalert2/dist/sweetalert2.js'
import 'sweetalert2/src/sweetalert2.scss'

/**
 * 
 * @param {string} icon  - icon类型 success error warning info question
 * @param {string} title - 标题
 * @param {string} text  - 内容
 * 
 * @param {boolean} showConfirmButton  - 是否开启确认按钮
 * @param {boolean} showCancelButton   - 是否开启取消按钮
 * @param {boolean} showDenyButton     - 是否开启拒绝按钮
 * @param {string} confirmButtonText   - 确认按钮文本
 * @param {string} cancelButtonText    - 取消按钮文本
 * @param {string} denyButtonText      - 拒绝按钮文本
 * @param {string} confirmButtonColor  - 确认按钮颜色
 * @param {string} cancelButtonColor   - 取消按钮颜色
 * @param {string} denyButtonColor     - 拒绝按钮颜色
 * 
 * @param {string} imageUrl     - 
 * @param {string} imageHeight  - 
 * @param {string} imageAlt     - 
 * 
 * @param {number} timer        - 持续时间
 * @param {boolean} draggable   - 是否拖拽
 * @param {boolean} heightAuto  - 是否开启自动高度
 * 
 * @return {Object}
 */
export async function handleSwal({
  icon,
  title = '',
  text = '',
  // 
  showConfirmButton = true,
  showCancelButton = true,
  showDenyButton = false,
  confirmButtonText = "确认",
  cancelButtonText = `取消`,
  denyButtonText = `拒绝`,
  confirmButtonColor,
  cancelButtonColor,
  denyButtonColor,
  // 
  imageUrl,
  imageHeight,
  imageAlt,
  // 
  // footer
  //
  timer,
  draggable = false,
  heightAuto = false
} = {}) {
  const res = await Swal.fire({
    icon: icon || 'question',
    title,
    text,
    // 按钮
    showConfirmButton,
    showCancelButton,
    showDenyButton,
    confirmButtonText,
    cancelButtonText,
    denyButtonText,
    confirmButtonColor,
    cancelButtonColor,
    denyButtonColor,
    // 图片内容
    imageUrl,
    imageHeight,
    imageAlt,
    // 底部内容
    // footer,
    // 配置
    timer, // 持续时间
    draggable, // 是否拖动
    heightAuto // 是否自动高度
  })
  return res
}
相关推荐
Data_Journal41 分钟前
什么是 CAPTCHA,它是如何工作的?
java·大数据·服务器·前端·数据库
计算机魔术师1 小时前
我看了这个更新,把原来的检索方案推翻了
前端
zhanghaha13141 小时前
HTML系列教程:3_HTML 基础标签 — 标题、段落、超链接、图像
前端·html
李高钢1 小时前
C# WPF Prism 进阶(二):区域(Region)与模块化(Module)
java·前端·数据库
xyphf_和派孔明1 小时前
Vite 与 Webpack 对比及常见面试题
前端·webpack·vite
明月_清风2 小时前
Pi Agent 深度解析:开源极简终端 AI 编码代理的终极指南
前端·后端·ai编程
fatcoder2 小时前
玩转Nginx 03 — location 匹配规则:让不同的路径各回各家
前端·后端·nginx
HjhIron2 小时前
前端面试高频考点 —— TS 高级类型 & CSS 三列布局
前端
李剑一2 小时前
《牛来》火了?我用ThreeJs实现了一个简易版的,代码全送给你,文章最后附演示效果
前端
世界哪有真情3 小时前
AI 写代码两年多,我发现自己越来越"看不进去"了
前端·后端·ai编程