index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import ROUTE_ENUM from './constant/route';
  2. import CATEGORY_ENUM from './constant/category';
  3. import { getTheme } from './constant/theme';
  4. export function start(params) {
  5. const {
  6. getAuthorization,
  7. secretId,
  8. secretKey,
  9. ocrType,
  10. ocrOption,
  11. cameraConfig,
  12. resultPage,
  13. resultPageConfig,
  14. theme,
  15. success,
  16. fail,
  17. } = params;
  18. if (!getAuthorization && (!secretId || !secretKey)) {
  19. wx.showToast({
  20. icon: 'none',
  21. duration: 3000,
  22. title: 'getAuthorization和(secretId,secretKey)不能都为空',
  23. });
  24. return false;
  25. }
  26. if (!ocrType) {
  27. wx.showToast({
  28. icon: 'none',
  29. duration: 3000,
  30. title: '参数ocrType不能为空',
  31. });
  32. return false;
  33. }
  34. if (!success) {
  35. wx.showToast({
  36. icon: 'none',
  37. duration: 3000,
  38. title: '请设置success函数',
  39. });
  40. return false;
  41. }
  42. wx.clientInfo = {
  43. getAuthorization,
  44. secretId,
  45. secretKey,
  46. ocrType,
  47. ocrOption,
  48. cameraConfig,
  49. resultPage: !!resultPage,
  50. resultPageConfig,
  51. theme: getTheme(theme),
  52. onFinish: success,
  53. fail,
  54. };
  55. wx.getSetting({
  56. success(res) {
  57. if (!res.authSetting['scope.camera']) {
  58. wx.authorize({
  59. scope: 'scope.camera',
  60. success() {
  61. wx.navigateTo({
  62. url:
  63. `/ocrsdk/pages/${ROUTE_ENUM[ocrType]}`,
  64. });
  65. },
  66. fail() {
  67. wx.showModal({
  68. title: '提示',
  69. content: '请打开摄像头权限',
  70. confirmText: '去设置',
  71. success(res) {
  72. if (res.confirm) {
  73. wx.openSetting();
  74. } else if (res.cancel) {
  75. return;
  76. }
  77. },
  78. });
  79. },
  80. });
  81. } else {
  82. wx.navigateTo({
  83. url:
  84. `/ocrsdk/pages/${ROUTE_ENUM[ocrType]}`,
  85. });
  86. }
  87. },
  88. });
  89. }
  90. export const OcrType = CATEGORY_ENUM;