更新记录
1.0.1(2026-03-13)
- 增加鸿蒙支持
- 增加开启/关闭闪光灯接口
1.0.0(2026-03-11)
自定义相机进行拍照录像,自定义UI,点击聚焦,双指拉近摄像头
平台兼容性
uni-app(3.7.0)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| √ |
√ |
- |
- |
√ |
√ |
5.0 |
√ |
√ |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(3.7.0)
| Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
| - |
- |
5.0 |
√ |
- |
- |
其他
自定义相机进行拍照录像,自定义UI
功能
- 自定义相机拍照
- 自定义相机录像
- 点击聚焦
- 双指收缩进行拉近/放到焦距
- 支持自定义UI
集成步骤
- 拷贝demo里的AndroidManifest.xml、Info.plist、harmony-configs文件到项目根目录
- 本页面右上角可以点击"使用HBuilderX导入示例项目"下载demo,导入demo的时候选vue3,插件支持vue2和vue3
- 如需定制或增加功能请点击插件标题下方的"进入交流群"私聊作者
组件
<!-- #ifdef APP-HARMONY -->
<embed :style="'width:'+width+'px;height:'+height+'px;'" tag="camera" :options="options"
@onevent="onEvent"></embed>
<!-- #endif -->
<!-- #ifndef APP-HARMONY -->
<wrs-uts-camera :style="'width:'+width+'px;height:'+height+'px;'" @onEvent="onEvent"
:params="params"></wrs-uts-camera>
<!-- #endif -->
- 使用了本组件的页面需要用nvue
- 组件通过修改params参数来实现业务,通过onEvent事件来回调数据
- 打开相机
let businessArray = []
businessArray.push({
business: "startCamera", //设置业务参数
params: {
isFrontCamera: true // 是否使用前摄像头
}
})
let params = {}
params.businessArray = businessArray
let paramsStr = JSON.stringify(params)
return {
imageSrc: null,
videoSrc: null,
params: paramsStr,
options: {
params: paramsStr
},
height: height,
width: width,
hadScanCode: false,
index: 0,
code: null,
msg: null,
}
let imageName = getUserName()
let filePath = plus.io.convertLocalFileSystemURL("_download/" + imageName + ".jpg");
let newParams = {}
newParams.businessArray = [{
business: "takePhoto",
params: {
needBase64: false, // 是否返回图片的base64
filePath: filePath // 图片保存的本地绝对地址
}
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
params: newParamsStr
}
- 开始录像
录像结果在onEvent里回调,录像过程请不要切换摄像头
let imageName = getUserName()
let filePath = plus.io.convertLocalFileSystemURL("_download/" + imageName + ".mp4");
let newParams = {}
newParams.businessArray = [{
business: "startRecord",
params: {
filePath: filePath
}
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
params: newParamsStr
}
let newParams = {}
newParams.businessArray = [{
business: "stopRecord"
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
params: newParamsStr
}
let newParams = {}
newParams.businessArray = [{
business: "pauseRecord"
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
params: newParamsStr
}
let newParams = {}
newParams.businessArray = [{
business: "resumeRecord"
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
params: newParamsStr
}
let newParams = {}
newParams.businessArray = [{
business: "switchCamera"
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
params: newParamsStr
}
let newParams = {}
newParams.businessArray = [{
business: "setTorch",
params: {
isOn: true
}
}]
let newParamsStr = this.formatNewParams(newParams)
// android、ios
this.params = newParamsStr
// 鸿蒙
this.options = {
params: newParamsStr
}
onEvent(event) {
console.log("onEvent:" + JSON.stringify(event))
let detail = event.detail
let opt = detail.opt
if (opt) {
switch (opt) {
// 拍照回调
case "takePhoto":
let flag = detail.flag
if (flag) {
let base64 = detail.base64
let filePath = detail.filePath
if (base64) {
if (!base64.startsWith(
"data:image/jpg;base64,"
)) { // android、harmony图片转base64前缀没有data:image/jpg;base64,
base64 = "data:image/jpg;base64," + base64
}
this.imageSrc = base64
}
if (filePath) {
this.imageSrc = "file://" + filePath
}
} else {
console.log("拍照失败:" + JSON.stringify(detail))
this.showToast("拍照失败:" + JSON.stringify(detail))
}
break;
// 录像回调
case "recordFile": {
let flag = detail.flag
if (flag) {
let filePath = detail.filePath
if (filePath) {
this.videoSrc = "file://" + filePath
}
} else {
console.log("录像失败:" + JSON.stringify(detail))
this.showToast("录像失败:" + JSON.stringify(detail))
}
}
default:
break;
}
}
}