import monitor from '/utils/alipayLogger';
App(monitor.hookApp({

  globalData: {
    version: "1.0.1.20200311",
    TEST_URL: "https://cashier.test.miyahub.net/",
    RELEASE_URL: "https://cashier.miyahub.com/",
    LOG_URL: "https://log.test.miyahub.net/log",
    appId: "2021001107617164",
    frontScreenAppId: "2021001107603212",
    userName:""
  },

  onLaunch(options) {
    monitor.init({
      pid: "qzhr85jigetfamuqniwz4q==",
      options: options,
      sample: 1,
      autoReportApi: true,
      autoReportPage: true,
      // Http请求返回数据中状态码字段名称
      code: ["success"],
      // Http返回数据中的error message字段名称
      msg: ["errorMsg"]
    });


    // 第一次打开
    // options.query == {number:1}
    console.info('App onLaunch');
  },
  onShow(options) {
     
    // 从后台被 scheme 重新打开
    // options.query == {number:1}
  },

  //错误上报
  onError(err) {
    try {
      var commonRequest = {
        appId: this.globalData.appId,
        account: this.globalData.userName,
        version: this.globalData.version,
        extra_data: err
      };
      my.request({
        url: this.globalData.LOG_URL,
        method: 'POST',
        dataType: 'json',
        timeout: 30000,
        data: commonRequest,
        success: (res) => {
          console.log("upload log success");
        },
        fail: (res) => {
          console.log("upload log fail");
        }
      });

    } catch (e) {
      console.log("upload log exp",e);
    }
  }

    
}));
