index.js 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import registerHooks from "../../../core/utils/registerHooks";
  2. import { globalExt } from "../../../core/utils/constants";
  3. import monitor from "../components/utils/alipayLogger";
  4. function wait(callback, time) {
  5. const { globalData } = getApp();
  6. if (time >= 5 || globalData.monitorPid) {
  7. callback(globalData);
  8. } else {
  9. setTimeout(() => {
  10. wait(callback, time + 1);
  11. }, 1000);
  12. }
  13. }
  14. registerHooks({
  15. async onAppLaunch(options) {
  16. wait(({ monitorPid }) => {
  17. try {
  18. monitor.init({
  19. pid: monitorPid || globalExt.pid,
  20. // eslint-disable-next-line no-undef
  21. options,
  22. sample: 1,
  23. autoReportApi: false,
  24. autoReportPage: true,
  25. // Http请求返回数据中状态码字段名称
  26. code: ["code"],
  27. // Http返回数据中的error message字段名称
  28. msg: ["msg"],
  29. miniVersion: globalExt.miniVersion || "0.0.56",
  30. });
  31. monitor.setCommonInfo({
  32. tag: this.globalData.appId,
  33. });
  34. } catch (error) {
  35. console.error(error);
  36. }
  37. }, 0);
  38. },
  39. });