Page({ data: { videoSrc: '', src: '', mode: 'normal', zoom: 1, devicePosition: 'back', flash: 'auto', flashArr: ['auto', 'on', 'off', 'torch'], frameSize: 'medium', frameSizeArr: ['small', 'medium', 'large'], }, onLoad() { this.ctx = xhs.createCameraContext(); }, takePhoto() { this.ctx.takePhoto({ quality: 'high', success: (res) => { console.log("%c Line:21 takePhoto 🌮 takePhoto res", "color:#3f7cff", res); this.setData({ src: res.tempImagePath }); } }); }, startRecord() { this.ctx.startRecord({ success: (res) => { console.log('startRecord'); } }); }, changeFlash(e) { this.setData({ flash: this.data.flashArr[e.detail.value] }); }, changeFrameSize(e) { this.setData({ frameSize: this.data.frameSizeArr[e.detail.value] }); }, changeMode() { this.setData({ mode: this.data.mode === 'normal' ? 'scanCode' : 'normal' }); }, changeDevicePosition() { this.setData({ devicePosition: this.data.devicePosition === 'back' ? 'front' : 'back' }); }, stopRecord() { this.ctx.stopRecord({ success: (res) => { this.setData({ src: res.tempThumbPath, videoSrc: res.tempVideoPath }); } }); }, setZoom() { this.ctx.setZoom({ zoom: 2, success(res) { console.log('setZoom 成功', res); this.setData({ zoom: res.zoom }); }, fail(error) { console.log('setZoom 失败', error); } }); }, error(e) { xhs.showToast({ title: 'binderror', content: JSON.stringify(e) }); console.log('相机组件触发了 binderror', e.detail); }, stop(e) { xhs.showToast({ title: 'bindstop', content: JSON.stringify(e) }); console.log('相机组件触发了 bindstop', e.detail); }, initdone(e) { xhs.showToast({ title: 'initdone', content: JSON.stringify(e) }); console.log('相机组件触发了 bindinitdone', e.detail); }, scancode(e) { xhs.showToast({ title: 'scancode', content: JSON.stringify(e) }); console.log('相机组件触发了 bindscancode', e.detail); } });