简介(下载地址)
Ba-CallerID 是一款来电显示悬浮窗插件插件。
- 支持显示、隐藏
- 支持锁屏来电显示
- 支持自定义位置显示(上、中、下)
- 支持拖动(这版不支持,需要的话可以加)
- 支持申请、判断悬浮窗权限
截图展示
使用方法
在 script
中引入组件
const callerID = uni.requireNativePlugin('Ba-CallerID')
在 script
中调用(示例参考,可根据自己业务和调用方法自行修改)
methods: {
showFW(gravity) { //显示
callerID.show({
gravity: gravity, //显示位置:0中间 1上 2下
name: "三杯五岳",
content: "生活的梦,永远不止如此!",
call: "接听电话",
uncall: "拒绝电话",
empty: "无记录",
avatar: "https://test.jpg",
totalHint: "详情记录(6)",
tel: "010-0100-7530",
list: [{
iconText: "张",
title1: "张三",
title2: "河北某宝公司",
date: "2023-4-19",
time: "22:10:21",
iconColor: "#A71F21",
title1Color: "#6B646B",
title2Color: "#333333",
}, {
iconText: "李",
title1: "李四",
title2: "深圳某东有限公司",
date: "2023-4-19",
time: "22:10:21",
iconColor: "#00A71F",
title1Color: "#00646B",
title2Color: "#003333",
}]
},
(res) => {
console.log(res);
uni.showToast({
title: res.msg,
icon: "none",
duration: 3000
})
});
},
hideFW() { //隐藏
callerID.hide(
(res) => {
console.log(res);
uni.showToast({
title: res.msg,
icon: "none",
duration: 3000
})
});
},
permissionFW() { //申请悬浮窗权限
callerID.permission(
(res) => {
console.log(res);
uni.showToast({
title: res.msg,
icon: "none",
duration: 3000
})
});
},
goPermissionFW() { //跳转到悬浮窗权限页面
callerID.goPermission(
(res) => {
console.log(res);
uni.showToast({
title: res.msg,
icon: "none",
duration: 3000
})
});
},
isPermissionFW() { //是否申请悬浮窗权限
callerID.isPermission(
(res) => {
console.log(res);
let msg = res.msg;
if (res.data) {
msg = "isPermission:" + res.data.isPermission;
}
uni.showToast({
title: msg,
icon: "none",
duration: 3000
})
});
},
}
点击事件监听
在应用生命周期app.vue的onLaunch事件中设置监听:
onLaunch: function() {
var globalEvent = uni.requireNativePlugin('globalEvent');
globalEvent.addEventListener('baCallerIdEvent', function(e) {
console.log('baCallerIdEvent:' + JSON.stringify(e));
//处理点击事件
});
},
onShow: function() {
},
onHide: function() {
}
点击事件参数
属性名 | 说明 |
action | 事件类型,如:onClick |
tag | 事件名称:接听电话call,挂断电话uncall |
示例:
{"tag":"uncall","action":"onClick"}
api 列表
方法名 | 说明 |
show | 显示 |
hide | 隐藏 |
permission | 申请悬浮窗权限 |
goPermission | 跳转到悬浮窗权限页面 |
isPermission | 是否申请悬浮窗权限 |