ocr-finish-behavior.js 953 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import mapDisplayToOcr from '../../utils/mapDisplayToOcr';
  2. import { RESULT_ENUM } from '../../constant/result';
  3. module.exports = Behavior({
  4. data: {
  5. modifiable: false,
  6. },
  7. attached() {
  8. const { resultPageConfig } = wx.clientInfo;
  9. if (resultPageConfig) {
  10. const { modifiable } = resultPageConfig;
  11. this.setData({
  12. modifiable: !!modifiable,
  13. });
  14. }
  15. },
  16. methods: {
  17. onFinished() {
  18. /**
  19. * 拼装最后返回给客户的结果result
  20. */
  21. const { originResult } = this.data;
  22. const category = wx.clientInfo.ocrType;
  23. const result = mapDisplayToOcr(this.data.ocrResponse);
  24. const { optionalResultKey } = RESULT_ENUM[category];
  25. if (optionalResultKey) {
  26. optionalResultKey.forEach((item) => {
  27. result[item] = originResult[item];
  28. });
  29. }
  30. result.RequestId = originResult.RequestId;
  31. wx.clientInfo.onFinish(result);
  32. },
  33. },
  34. });