1.0.2 • Published 1 month ago

@tanzhenxing/zx-popconfirm v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

zx-popconfirm 气泡确认框组件

基于 uni-app 开发的气泡确认框组件,可在移动端和小程序中使用。

安装方式

npm install @tanzhenxing/zx-popconfirm

引入组件

pages.json 中注册组件:

{
  "easycom": {
    "autoscan": true,
    "custom": {
      "^zx-popconfirm": "@tanzhenxing/zx-popconfirm/zx-popconfirm"
    }
  }
}

基本使用

<template>
  <zx-popconfirm title="确定要删除吗?">
    <template #reference>
      <button>删除</button>
    </template>
  </zx-popconfirm>
</template>

API

Props 属性

属性名类型默认值说明
titleString''标题文本
confirmButtonTextString'确认'确认按钮文本
cancelButtonTextString'取消'取消按钮文本
confirmButtonTypeString'primary'确认按钮类型,可选值:'default', 'primary', 'success', 'warning', 'danger', 'info', 'text'
cancelButtonTypeString'default'取消按钮类型,可选值:'default', 'primary', 'success', 'warning', 'danger', 'info', 'text'
iconString'help-filled'图标类型,可选值:'help-filled', 'info-filled', 'warning-filled', 'error-filled'
iconColorString'#f90'图标颜色
hideIconBooleanfalse是否隐藏图标
hideAfterNumber200关闭延迟时间(毫秒)
widthString/Number150气泡宽度
placementString'top'气泡展示位置,可选值:'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end'

Events 事件

事件名说明回调参数
confirm点击确认按钮时触发-
cancel点击取消按钮时触发-

Slots 插槽

插槽名说明
reference触发气泡显示的元素
actions自定义操作按钮,提供 confirm 和 cancel 函数

示例

基础用法

<zx-popconfirm title="确定要删除这条记录吗?">
  <template #reference>
    <button>删除</button>
  </template>
</zx-popconfirm>

自定义按钮文字

<zx-popconfirm 
  title="确定要执行此操作吗?" 
  confirm-button-text="是的" 
  cancel-button-text="取消操作"
  @confirm="handleConfirm"
  @cancel="handleCancel"
>
  <template #reference>
    <button>执行操作</button>
  </template>
</zx-popconfirm>

自定义图标和颜色

<zx-popconfirm 
  title="此操作不可逆,是否继续?" 
  icon="error-filled" 
  icon-color="#F56C6C"
>
  <template #reference>
    <button>危险操作</button>
  </template>
</zx-popconfirm>

自定义按钮类型

<zx-popconfirm 
  title="确认操作?" 
  confirm-button-type="success" 
  cancel-button-type="info"
>
  <template #reference>
    <button>自定义按钮类型</button>
  </template>
</zx-popconfirm>

自定义操作插槽

<zx-popconfirm title="确认删除所选项目?">
  <template #reference>
    <button>批量删除</button>
  </template>
  <template #actions="{ confirm, cancel }">
    <button @click="cancel">我再想想</button>
    <button @click="confirm">确定删除</button>
  </template>
</zx-popconfirm>

注意事项

  1. 组件需要 uni-app 环境,确保项目是基于 uni-app 框架开发的
  2. 组件使用了 Vue 3 的 Composition API (setup),不支持 Vue 2
  3. 在某些小程序平台可能有兼容性问题,请根据实际情况调整样式
1.0.2

1 month ago

1.0.1

2 months ago