face_camera.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <view>
  3. <view class="face-container">
  4. <camera device-position="front" flash="off" class="camera" @error="error" v-if="showCamera">
  5. <cover-image src="../static/face_camera/bg.png" class="bg"></cover-image>
  6. </camera>
  7. <view class="image-container" v-if="showImage">
  8. <image mode="widthFix" class="photo" :src="photoPath"></image>
  9. <view class="cover"></view>
  10. </view>
  11. </view>
  12. <view class="desc">
  13. <block v-if="mode == 'verificate'">
  14. <image src="../static/face_camera/tips.png" mode="widthFix" class="tips"></image>
  15. <text>请把面部放在圆圈内</text>
  16. <text>拍摄脸部来确认身份</text>
  17. </block>
  18. <block v-if="mode == 'create'">
  19. <image src="../static/face_camera/face.png" mode="widthFix" class="face"></image>
  20. <text>请把完整面部放在圆圈内</text>
  21. <text>拍摄脸部来保存身份识别数据</text>
  22. </block>
  23. </view>
  24. <button class="btn" @tap="confirmHandle">{{ mode == 'create' ? '录入面部信息' : '身份核实' }}</button>
  25. </view>
  26. </template>
  27. <script>
  28. let dayjs = require('dayjs');
  29. export default {
  30. data() {
  31. return {
  32. mode: 'verificate',
  33. photoPath: '',
  34. showCamera: true,
  35. showImage: false,
  36. audio: null
  37. };
  38. },
  39. methods: {
  40. confirmHandle:function(){
  41. let that=this
  42. that.audio.stop()
  43. let ctx=uni.createCameraContext()
  44. ctx.takePhoto({
  45. quality:"high",
  46. success:function(resp){
  47. that.photoPath=resp.tempImagePath
  48. that.showCamera=false
  49. that.showImage=true
  50. uni.getFileSystemManager().readFile({
  51. filePath:that.photoPath,
  52. encoding:"base64",
  53. success:function(resp){
  54. let base64='data:image:/png;base64,'+resp.data
  55. let url=null
  56. if(that.mode=="create"){
  57. //创建司机面部模型档案
  58. url = that.url.createDriverFaceModel;
  59. }
  60. else{
  61. //验证司机面部模型
  62. url = that.url.verificateDriverFace;
  63. }
  64. that.ajax(url,"POST",{photo:base64},function(resp){
  65. let result=resp.data.result
  66. if(that.mode=="create"){
  67. if(result!=null&&result.length>0){
  68. console.error(result);
  69. uni.showToast({
  70. icon: 'none',
  71. title: '面部录入失败,请重新录入'
  72. });
  73. setTimeout(function() {
  74. that.showCamera = true;
  75. that.showImage = false;
  76. }, 2000);
  77. }
  78. else{
  79. uni.showToast({
  80. title: '面部录入成功'
  81. });
  82. setTimeout(function() {
  83. uni.switchTab({
  84. url: '../../pages/workbench/workbench'
  85. });
  86. }, 2000);
  87. }
  88. }
  89. else{
  90. //TODO 判断人脸识别结果
  91. }
  92. })
  93. }
  94. })
  95. }
  96. })
  97. }
  98. },
  99. onLoad: function(options) {
  100. let that=this
  101. that.mode=options.mode
  102. let audio=uni.createInnerAudioContext();
  103. that.audio=audio
  104. audio.src="/static/voice/voice_5.mp3"
  105. audio.play()
  106. },
  107. onHide: function() {
  108. if(this.audio!=null){
  109. this.audio.stop()
  110. }
  111. }
  112. };
  113. </script>
  114. <style lang="less">
  115. @import url('face_camera.less');
  116. </style>