康巴易测肤/伤疤uniapp小程序类
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.1KB

  1. const STATE = {
  2. ING:'ing',
  3. SUCCESS:'success',
  4. FAIL:'fail'
  5. }
  6. class Action {
  7. constructor(second=10,fun,limit,initTip) {
  8. this.second = second
  9. this.endTime = Infinity
  10. this.frames = []
  11. this.tip = initTip
  12. this.initTip = initTip
  13. this.state = STATE.ING
  14. this.fun = fun
  15. this.limit = limit
  16. }
  17. end(){
  18. if(this.fun){
  19. this.fun(this.state)
  20. }
  21. }
  22. check(faceData){
  23. if(this.endTime === Infinity){
  24. this.endTime = new Date().getTime() + (this.second*1000)
  25. }
  26. if(this.state !== STATE.ING ){
  27. return
  28. }
  29. if(new Date().getTime()>this.endTime){
  30. this.state = STATE.FAIL
  31. this.end()
  32. return
  33. }
  34. if(this.frames.length>=this.limit){
  35. this.state = STATE.SUCCESS
  36. this.end()
  37. return
  38. }
  39. this.takeFrameAfter(faceData)?.takeFrame(faceData)
  40. }
  41. takeFrame(faceData){
  42. }
  43. takeFrameAfter(faceData){
  44. let face = faceData.faceInfo[0]
  45. this.tip = this.initTip
  46. if(faceData.x == -1 || faceData.y == -1) {
  47. this.tip = '检测不到人脸'
  48. return null
  49. }
  50. if(faceData.faceInfo.length > 1) {
  51. this.tip = '请保证只有一人做核验'
  52. return null
  53. }
  54. return this
  55. }
  56. }
  57. export default Action