test.nvue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view>
  3. <view class="show-view">
  4. <Ba-CameraView ref="cameraView" class="camera-view" :load="loadData">
  5. </Ba-CameraView>
  6. </view>
  7. <button @click="takePhoto" :sizeLimit="100">拍照</button>
  8. <button @click="startRecord" :sizeLimit="100">开始录制</button>
  9. <button @click="stopRecord" :sizeLimit="100">停止录制</button>
  10. <button @click="changeCamera" :sizeLimit="100">切换摄像头</button>
  11. <button @click="setPrese" :sizeLimit="100">设置清晰度</button>
  12. </view>
  13. </template>
  14. <script>
  15. const toast = uni.requireNativePlugin('Ba-Toast')
  16. export default {
  17. data() {
  18. return {
  19. obj: {
  20. src: null,
  21. text: null,
  22. vSrc: null
  23. },
  24. loadData: { //配置
  25. isToast: true,
  26. isShowVibrate:false,
  27. },
  28. msgList: []
  29. }
  30. },
  31. onReady() {
  32. this.setListener(); //设置监听
  33. },
  34. methods: {
  35. takePhoto() {
  36. this.$refs.cameraView.takePicture((res) => {
  37. this.showToast(res.msg)
  38. });
  39. },
  40. //开始录制
  41. startRecord() {
  42. },
  43. //停止录制
  44. stopRecord() {
  45. },
  46. //切换摄像头
  47. changeCamera() {
  48. // const _this = this
  49. // this.$refs.CameraPreviewPlus.changeCamera({}, res => {
  50. // _this.obj.text = JSON.stringify(res)
  51. // })
  52. },
  53. //设置清晰度
  54. setPrese() {
  55. const _this = this
  56. // 1 AVCaptureSessionPresetHigh
  57. // 2 AVCaptureSessionPresetMedium
  58. // 3 AVCaptureSessionPresetLow
  59. // 4 AVCaptureSessionPreset640x480
  60. // 5 AVCaptureSessionPreset1280x720
  61. // 6 AVCaptureSessionPreset1920x1080
  62. // 7 AVCaptureSessionPreset3840x2160
  63. // 0 AVCaptureSessionPresetPhoto
  64. },
  65. setListener() {
  66. this.$refs.cameraView.setListener((res) => {
  67. if (res.action == "error") {
  68. this.showToast(res.msg)
  69. }
  70. });
  71. },
  72. showToast(msg) {
  73. toast.showToast({
  74. title: msg
  75. });
  76. }
  77. }
  78. }
  79. </script>
  80. <style>
  81. .show-view {
  82. flex-direction: row;
  83. }
  84. .camera-view {
  85. width: 750rpx;
  86. height: 640rpx;
  87. background-color: #333333;
  88. }
  89. .r-flex {
  90. margin-top: 40rpx;
  91. margin-bottom: 40rpx;
  92. flex-wrap: wrap;
  93. flex-direction: row;
  94. }
  95. .color-view {
  96. height: 200rpx;
  97. width: 200rpx;
  98. border-width: 1rpx;
  99. border-style: solid;
  100. border-color: #333333;
  101. }
  102. </style>