完成签约之后直接添加人员,录入下发凭证
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.

107 lines
3.0 KiB

  1. const STATE_WAIT_FINGER_DOWN = 1;
  2. const STATE_WAIT_FINGER_LEAVE = 2;
  3. const STATE_FINGER_DOWN = 3;
  4. const STATE_FINGER_LEAVE = 4;
  5. const STATE_EXTRACT_TEMPLATE = 5;
  6. const STATE_DOWNLOAD_TEMPLATE = 6;
  7. const STATE_EXTRACT_TEMPLATE_FAIL = 100;
  8. const STATE_EXTRACT_TEMPLATE_DIRTY = 101;
  9. const STATE_EXTRACT_TEMPLATE_POINTS_FEW = 102;
  10. const STATE_EXTRACT_TEMPLATE_MERGE_FAIL = 103;
  11. const ErrorReceiveDataErr = 1;
  12. const ErrorEnrollTimeout = 2;
  13. const ErrorDeviceNotFound = 3;
  14. const ErrorEmptyFail = 4;
  15. var mafp = {
  16. isConnected: false,
  17. ws: null,
  18. enrollCount: 6,
  19. enrollTimeout: 30 * 1000,
  20. callback: null,
  21. isWorking: false,
  22. init(conf) {
  23. if (conf && conf.enrollCount) {
  24. this.enrollCount = conf.enrollCount;
  25. }
  26. if (conf && conf.enrollTimeout) {
  27. this.enrollTimeout = conf.enrollTimeout;
  28. }
  29. return new Promise((resolve,reject) => {
  30. var that = this;
  31. if (this.isConnected) {
  32. resolve();
  33. return;
  34. }
  35. var timeout = setTimeout(() => {
  36. if (!that.isConnected) {
  37. reject("Connection timeout");
  38. }
  39. }, 2000)
  40. var port = 9897;
  41. var address = 'ws://localhost:' + port + '/';
  42. that.ws = new WebSocket(address);
  43. that.ws.addEventListener('open', function() {
  44. that.isConnected = true;
  45. if (timeout) {
  46. clearTimeout(timeout);
  47. timeout = 0;
  48. }
  49. resolve()
  50. });
  51. that.ws.addEventListener('close', function() {
  52. console.log('Connection lost');
  53. that.isConnected = false;
  54. reject("Connection lost");
  55. });
  56. that.ws.addEventListener('message', function(e) {
  57. let resp = JSON.parse(e.data);
  58. if (that.callback) {
  59. that.callback(resp);
  60. if(resp.err || resp.data) {
  61. that.isWorking = false;
  62. that.callback = null;
  63. }
  64. }
  65. });
  66. });
  67. },
  68. _sendMessage(msg) {
  69. this.ws.send(JSON.stringify(msg));
  70. },
  71. startEnroll(callback=((status, data)=>{})) {
  72. this.callback = callback;
  73. this.isWorking = true;
  74. this.init().then(() => {
  75. this._sendMessage({
  76. cmd: "enrollStart",
  77. config: {
  78. enrollCount: this.enrollCount,
  79. enrollTimeout: this.enrollTimeout
  80. }
  81. });
  82. }).catch(err => {
  83. this.callback = null;
  84. this.isWorking = false;
  85. callback({
  86. err: err,
  87. state: 0,
  88. step:0
  89. })
  90. })
  91. },
  92. cancelEnroll() {
  93. this.callback = null;
  94. this.isWorking = false;
  95. this._sendMessage({
  96. cmd: "enrollCancel"
  97. });
  98. }
  99. };