mapOcrToDisplay.js 1006 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { RESULT_ENUM, FIELD_ENUM } from '../constant/result';
  2. function mapOcrToDisplay(ocrResult) {
  3. const { ocrType } = wx.clientInfo;
  4. const displayResult = {};
  5. const { resultType, resultKey } = RESULT_ENUM[ocrType];
  6. const meta = FIELD_ENUM[ocrType];
  7. const fieldResult = ocrResult[resultKey];
  8. switch (resultType) {
  9. case 1:
  10. Object.keys(ocrResult).forEach((item) => {
  11. if (meta[item] && ocrResult[item]) {
  12. displayResult[item] = {
  13. title: meta[item].title,
  14. value: ocrResult[item],
  15. type: meta[item].type ? meta[item].type : (ocrResult[item].length > 12 ? 'textarea' : 'input')
  16. };
  17. }
  18. });
  19. break;
  20. case 2:
  21. fieldResult.forEach((field) => {
  22. displayResult[field.Name] = {
  23. title: field.Name,
  24. value: field.Value,
  25. type: field.Value.length > 12 ? 'textarea' : 'input',
  26. };
  27. });
  28. break;
  29. }
  30. return displayResult;
  31. }
  32. module.exports = mapOcrToDisplay;