更新记录
1.0.0(2026-07-04)
下载此版本
第一版,鸿蒙原生弹框
平台兼容性
uni-app(3.7.13)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| - |
√ |
× |
× |
- |
- |
× |
× |
5 |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| × |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
uni-app x(3.7.13)
| Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
| - |
- |
- |
- |
√ |
- |
其他
| 多语言 |
暗黑模式 |
宽屏模式 |
蒸汽模式 |
| × |
× |
× |
√ |
harmony-popup
HarmonyOS 原生弹框插件,基于 uni-app x UTS 开发。提供 Toast 提示、模态对话框(Alert / Confirm / Prompt)、操作菜单、自定义弹出层,支持 5 个方向弹出、动画效果和 Slot 自定义内容。
平台支持
| 平台 |
支持 |
| APP-HarmonyOS |
✓ |
| APP-Android |
✗ |
| APP-iOS |
✗ |
| Web |
✗ |
| 小程序 |
✗ |
安装
将 harmony-popup 目录放入项目的 uni_modules/ 目录下即可。
快速上手
引入组件
使用 showModal({ editable: true }) 或 showPopup() 前,必须在页面中引入 <harmony-popup /> 组件:
<template>
<view>
<!-- 页面内容 -->
<!-- 函数模式(必须引入,用于 editable 和 showPopup) -->
<harmony-popup />
</view>
</template>
<script>
import { showToast, showModal, showActionSheet, showPopup, closePopup } from '@/uni_modules/harmony-popup'
import HarmonyPopup from '@/uni_modules/harmony-popup/components/harmony-popup/harmony-popup.uvue'
export default {
components: { HarmonyPopup }
}
</script>
基本用法
// Toast 提示
showToast({ message: '操作成功' })
// Alert 提示框
showModal({
title: '提示',
content: '操作完成',
showCancel: false
})
// Confirm 确认框
showModal({
title: '确认',
content: '确定要删除吗?',
success(res) {
if (res.confirm) { /* 点击了确定 */ }
if (res.cancel) { /* 点击了取消 */ }
}
})
// Prompt 输入框(需要 <harmony-popup /> 组件)
showModal({
title: '请输入',
editable: true,
placeholderText: '请输入姓名',
success(res) {
console.log('输入内容:', res.content)
}
})
// ActionSheet 操作菜单
showActionSheet({
itemList: ['拍照', '相册', '文件'],
success(res) {
console.log('选中下标:', res.tapIndex)
}
})
// 自定义 Popup(需要 <harmony-popup /> 组件)
showPopup({
position: 'bottom',
title: '选择操作',
content: '请选择一个操作',
buttons: [
{ text: '取消', type: 'default' },
{ text: '确定', type: 'primary' }
],
showClose: true,
onButtonClick(index) { console.log('点击按钮:', index) },
onClose() { console.log('关闭') }
})
// 关闭自定义 Popup
closePopup()
API 文档
showToast(options)
显示 Toast 提示(使用原生 promptAction,无需组件)。
| 参数 |
类型 |
必填 |
默认值 |
说明 |
| message |
string |
✓ |
- |
提示内容 |
| duration |
'short' | 'long' |
|
'short' |
显示时长,short≈1500ms,long≈3500ms |
| bottom |
number |
|
80 |
Toast 底部距离(px) |
| success |
(res: PopupResult) => void |
|
- |
成功回调 |
| fail |
(err: UniError) => void |
|
- |
失败回调 |
| complete |
(res: PopupResult \| UniError) => void |
|
- |
完成回调 |
showModal(options)
显示模态对话框。非 editable 模式使用原生 promptAction;editable 模式需要 <harmony-popup /> 组件。
| 参数 |
类型 |
必填 |
默认值 |
说明 |
| title |
string |
|
'' |
对话框标题 |
| content |
string |
* |
'' |
对话框内容(editable 为 true 时可选) |
| showCancel |
boolean |
|
true |
是否显示取消按钮 |
| cancelText |
string |
|
'取消' |
取消按钮文字 |
| confirmText |
string |
|
'确定' |
确定按钮文字 |
| editable |
boolean |
|
false |
是否显示输入框(Prompt 模式) |
| placeholderText |
string |
|
'' |
输入框占位文字 |
| success |
(res: ShowModalResult) => void |
|
- |
成功回调 |
| fail |
(err: UniError) => void |
|
- |
失败回调 |
| complete |
(res: ShowModalResult \| UniError) => void |
|
- |
完成回调 |
success 回调参数 ShowModalResult:
| 字段 |
类型 |
说明 |
| confirm |
boolean |
是否点击了确定 |
| cancel |
boolean |
是否点击了取消 |
| content |
string |
editable 模式下的输入框内容,否则为空字符串 |
| errMsg |
string |
结果信息 |
showActionSheet(options)
显示操作菜单(使用原生 promptAction,无需组件)。
| 参数 |
类型 |
必填 |
默认值 |
说明 |
| title |
string |
|
'' |
菜单标题 |
| itemList |
string[] |
✓ |
- |
菜单项文字数组,最多 6 个 |
| cancelText |
string |
|
'取消' |
取消按钮文字 |
| success |
(res: ShowActionSheetResult) => void |
|
- |
成功回调 |
| fail |
(err: UniError) => void |
|
- |
失败回调 |
| complete |
(res: ShowActionSheetResult \| UniError) => void |
|
- |
完成回调 |
success 回调参数 ShowActionSheetResult:
| 字段 |
类型 |
说明 |
| tapIndex |
number |
选中项下标(从 0 开始),取消时为 -1 |
| errMsg |
string |
结果信息 |
showPopup(options)
显示自定义弹出层。需要页面中引入 <harmony-popup /> 组件。
| 参数 |
类型 |
必填 |
默认值 |
说明 |
| position |
PopupPosition |
|
'center' |
弹出位置,见下方说明 |
| title |
string |
|
'' |
标题文字 |
| content |
string |
|
'' |
内容文字 |
| buttons |
PopupButton[] |
|
[] |
底部按钮数组,最多 3 个 |
| showClose |
boolean |
|
false |
是否显示关闭按钮(右上角) |
| cornerRadius |
number |
|
16 |
圆角大小(rpx) |
| backgroundColor |
string |
|
'#FFFFFF' |
弹窗背景颜色 |
| autoCancel |
boolean |
|
true |
点击遮罩是否关闭弹窗 |
| animation |
boolean |
|
true |
是否启用动画 |
| duration |
number |
|
300 |
动画时长(ms) |
| onClose |
() => void |
|
- |
弹窗关闭回调 |
| onButtonClick |
(index: number) => void |
|
- |
按钮点击回调,参数为按钮下标 |
| success |
(res: PopupResult) => void |
|
- |
成功回调 |
| fail |
(err: UniError) => void |
|
- |
失败回调 |
| complete |
(res: PopupResult \| UniError) => void |
|
- |
完成回调 |
PopupPosition 类型: 'center' | 'top' | 'bottom' | 'left' | 'right'
PopupButton 类型:
| 字段 |
类型 |
必填 |
默认值 |
说明 |
| text |
string |
✓ |
- |
按钮文字 |
| type |
'primary' | 'default' |
|
'default' |
按钮样式类型 |
| color |
string |
|
'#666666' |
按钮文字颜色 |
closePopup()
关闭当前显示的自定义弹出层(无参数,无返回值)。
动画效果
默认启用动画,可通过 animation: false 关闭。
| 位置 |
动画效果 |
| center |
缩放 + 渐隐(scale 0.85 → 1 + fade) |
| top |
从顶部向下滑入 |
| bottom |
从底部向上滑入 |
| left |
从左侧向右滑入 |
| right |
从右侧向左滑入 |
动画时长通过 duration 参数控制,默认 300ms。
Slot 模式
除函数 API 外,还可以使用 Slot 模式自定义弹窗内容,直接在弹窗中嵌入 Vue 组件。
使用方式
<template>
<view>
<view class="btn" @click="popupVisible = true">
<text>打开 Slot 弹窗</text>
</view>
<harmony-popup
:visible="popupVisible"
position="center"
:show-close="true"
:animation="true"
:duration="300"
:auto-cancel="true"
corner-radius="16"
background-color="#FFFFFF"
@close="handleClose"
@update:visible="val => popupVisible = val"
>
<!-- 自定义标题 -->
<view slot="title">
<text style="font-size: 36rpx; font-weight: bold; color: #e74c3c;">自定义标题</text>
</view>
<!-- 自定义内容(默认 slot) -->
<view style="padding: 20rpx 0;">
<text style="font-size: 28rpx; color: #666;">自定义内容区域</text>
<input
style="height: 80rpx; background-color: #f5f5f5; border-radius: 12rpx; padding: 0 20rpx;"
placeholder="请输入"
v-model="inputValue"
/>
</view>
<!-- 自定义底部 -->
<view slot="footer" style="flex-direction: row; justify-content: center;">
<view class="btn-cancel" @click="popupVisible = false">
<text>取消</text>
</view>
<view class="btn-confirm" @click="handleConfirm">
<text>确定</text>
</view>
</view>
</harmony-popup>
</view>
</template>
<script>
import HarmonyPopup from '@/uni_modules/harmony-popup/components/harmony-popup/harmony-popup.uvue'
export default {
components: { HarmonyPopup },
data() {
return {
popupVisible: false,
inputValue: ''
}
},
methods: {
handleClose() { console.log('关闭') },
handleConfirm() {
console.log('输入:', this.inputValue)
this.popupVisible = false
}
}
}
</script>
Props
| Prop |
类型 |
默认值 |
说明 |
| visible |
boolean |
false |
控制弹窗显隐 |
| position |
string |
'center' |
弹出位置 |
| showClose |
boolean |
false |
是否显示关闭按钮 |
| autoCancel |
boolean |
true |
点击遮罩是否关闭弹窗 |
| animation |
boolean |
true |
是否启用动画 |
| duration |
number |
300 |
动画时长(ms) |
| cornerRadius |
number |
16 |
圆角大小(rpx) |
| backgroundColor |
string |
'#FFFFFF' |
弹窗背景颜色 |
Events
| 事件 |
参数 |
说明 |
update:visible |
boolean |
弹窗显隐状态变化(用于 v-model:visible) |
close |
- |
弹窗关闭时触发 |
Slots
| Slot |
说明 |
| default |
弹窗内容区域(可嵌入任意组件) |
| title |
标题区域(使用 slot="title") |
| footer |
底部区域(使用 slot="footer") |
方法(通过 ref 调用)
| 方法 |
说明 |
show() |
显示弹窗 |
hide() |
隐藏弹窗 |
注意事项
showToast()、showModal({ editable: false })、showActionSheet() 使用 HarmonyOS 原生 API,不需要引入组件。
showModal({ editable: true }) 和 showPopup() 必须在页面中引入 <harmony-popup /> 组件,否则会返回错误。
- 左/右侧弹窗宽度为 500rpx,上/下侧弹窗宽度为全屏(750rpx),居中弹窗宽度为 600rpx。
- Slot 模式和函数模式可以在同一页面共存,使用不同的
<harmony-popup /> 实例。
- 本插件仅支持 HarmonyOS 平台,其他平台调用会返回错误。
- 弹窗内容区最大高度为 85vh,超出部分可滚动。