index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const { IoTVsp, IoTVspEvent, modeType } = requirePlugin('IoTVsp')
  2. import {
  3. userCreate,
  4. isvPid,
  5. orgOutId,
  6. componentOutId } from '/utils/api/zfb_ioTVsp'
  7. let throttle = false
  8. const iotVspInit = function(callback = null) {
  9. // 跳转到开通结果时监听上报结果数据
  10. IoTVsp.addEventListener(IoTVspEvent.query, (data) => {
  11. // 当跳转至开通结果页,data中能获取到上报到信息,不需要点击完成拿到信息
  12. // console.log('IoTVspEvent.query-->', data)
  13. })
  14. // 开通结果页点击完成返回事件
  15. IoTVsp.addEventListener(IoTVspEvent.back, (data) => {
  16. //若配置不跳转至默认开通成功页,则开通成功后执行此回调
  17. // console.log('IoTVspEvent.back-->', data)
  18. // my.alert({content: 'IoTVspEvent.back-->' + JSON.stringify(data)})
  19. if(callback != null && throttle) {
  20. throttle = false
  21. callback(data)
  22. }
  23. })
  24. // 错误事件监听
  25. IoTVsp.addEventListener(IoTVspEvent.result, (data) => {})
  26. }
  27. const _startComponent = function(uniqueId) {
  28. if(!uniqueId) {
  29. return
  30. }
  31. throttle = true
  32. IoTVsp.start({
  33. mode: modeType.faceverify,
  34. config: {
  35. uniqueId,
  36. isvPid: isvPid,
  37. orgOutId: orgOutId,
  38. componentOutId: componentOutId
  39. }
  40. })
  41. }
  42. const iotVspUniqueId = function(idNumber, username, phone, avatar, uniqueId = null) {
  43. return new Promise((resolve, reject) => {
  44. if(!idNumber && !username && !phone) {
  45. reject()
  46. return
  47. }
  48. if(uniqueId) {
  49. _startComponent(uniqueId)
  50. resolve(false)
  51. return
  52. }
  53. userCreate({
  54. certType: 'IDENTITY_CARD',
  55. certNo: idNumber,
  56. certName: username,
  57. phone: phone,
  58. avatar
  59. }).then((res) => {
  60. if(res.data && !res.data.uniqueId) {
  61. // uniqueId为空,表示已入库
  62. resolve(true)
  63. } else {
  64. _startComponent(res.data.uniqueId)
  65. resolve(false)
  66. }
  67. }).catch((error) => {
  68. reject(error)
  69. })
  70. })
  71. }
  72. module.exports = {
  73. iotVspUniqueId,
  74. iotVspInit
  75. }