Camera

相机组件。一个页面仅支持一个camera组件。

子组件

不支持

属性

名称

类型

默认值

必填

描述

id

string

-

组件的唯一标识。

style

string

-

组件的样式声明。

class

string

-

组件的样式类,用于引用样式表。

ref

string

-

用来指定指向子元素或子组件的引用信息,该引用将注册到父组件的$refs 属性对象上。

data

string

-

给当前组件设置data属性,进行相应的数据存储和读取。

样式

名称

类型

默认值

必填

描述

width

<length> | <percentage>

-

设置组件自身的宽度。

缺省时使用元素自身内容需要的宽度。

height

<length> | <percentage>

-

设置组件自身的高度。

缺省时使用元素自身内容需要的高度。

事件

通用

方法

名称

参数

描述

takePhoto

CameraTakePhotoOptions

执行拍照

startRecord

-

开始录像

closeRecord

CameraRecordOptions

结束录像

CameraTakePhotoOptions

quality

string

图片质量(L3)

success

Function

接口调用成功,返回uri

fail

Function

接口调用失败

complete

Function

接口调用结束

CameraRecordOptions

success

Function

接口调用成功,返回uri

fail

Function

接口调用失败

complete

Function

接口调用结束

示例

<div  style=" flex-direction: column; align-content: center;" >
    <div style="height: {{heights}};width: {{widths}} ;">
        <camera id="cameraId"  style="height: 100%;width: 100%;"> </camera>
    </div>
    <text > src: {{src}}   photoUri: {{photoUri}}  </text>
    <div style="height: 200; align-items: center;" >
        <image style="  border-radius: 150;  width: 200; height: 200; margin-left: 10; margin-right: 30;
                object-fit: fill; background-color: black;" src="{{photoUri}}" ></image>
        <button style=" border-radius: 150; height: 200; width: 200; margin-right: 30;"
                onclick="takePhoto" value="takePhoto"></button>
    </div>
    <div style="flex-direction: row;height: 200;">
        <button value="录像" onclick="startRecord" style="width: 50%;height: 200;"></button>
        <button value="结束录像" onclick="closeRecord" style="width: 50%;height: 200;"></button>
    </div>
</div>
//.js
import router from '@system.router';
export default {
    data: {
        photoUri: "",
        val: "",
        arr:[],
        size: -1,
        quality:'',
        src:'',
        heights: 600,
        widths:600,
    },
    onInit() {
    },
	startRecord() {
        this.$element('cameraId').startRecorder();
    },
    closeRecord() {
        this.$element('cameraId').closeRecorder(
            {
                success: (res) => {
                    this.src = res.uri;
                },
                fail: (res) => {
                    this.val = "fail   " + res.errormsg + " " + res.errorcode;
                },
                complete : (res) => {
                    this.val += " :complete";
                },
            }
        );
    },
	takePhoto() {
        this.$element('cameraId').takePhoto(
            {
                quality: -1,
                success: (res) => {
                    this.photoUri = res.uri;
                },
                fail: (res) => {
                    this.val = "fail   " + res.errormsg + " " + res.errorcode;
                },
                complete : (res) => {
                    this.val += " :complete";
                },
            }
        );
	},

}