Authored by huangyCode

Merge branches 'feature/error_page' and 'feature/grafana' of http://git.yoho.cn/…

…fe/yoho-luck into feature/error_page

# Conflicts:
#	libs/request.js
... ... @@ -6,7 +6,7 @@ import {API_HOST, MINI_APP_TYPE} from './libs/config';
import mta from './vendors/mta_analysis';
import {Event} from '/login/utils/index.js';
import {wxLogin} from '/login/utils/login/login';
import {appReport} from './libs/appReport.js';
import appReport from './libs/appReport';
import {isStringEmpty, getYHStorageSync} from './utils/util';
import regeneratorRuntime from '/login/libs/regenerator-runtime/index';
... ... @@ -144,11 +144,21 @@ App({
}
if (options && options.scene){
appReport('start', "LIFECYCLE", "RESUME", {
'activeWay': options.scene + ""
}, this)
appReport({
reportType: 'start',
pt: 'LIFECYCLE',
pn: 'RESUME',
param: {
'activeWay': options.scene + ''
}
}, this);
}else{
appReport('start', "LIFECYCLE", "RESUME", {}, this)
appReport({
reportType: 'start',
pt: 'LIFECYCLE',
pn: 'RESUME',
param: {}
}, this);
}
let scene = options ? options.scene : '';
... ... @@ -158,8 +168,13 @@ App({
//当应用程序进入后台状态时触发
onHide () {
let params = {};
yasReport(YB_ENTER_BACKGROUND,params);
appReport('start', "LIFECYCLE", "STOP", {},this)
yasReport(YB_ENTER_BACKGROUND, params);
appReport({
reportType: 'start',
pt: 'LIFECYCLE',
pn: 'STOP',
param: {}
}, this);
},
getUserInfo: function () {
... ... @@ -400,7 +415,6 @@ App({
},
getShareInfo: function () {
// console.log('getShareInfo');
let param = {
share_id: this.globalData.shareId,
}
... ... @@ -468,10 +482,14 @@ App({
} else {
net = '0';
}
// console.log("network:",net)
},
complete:function(res){
appReport('start', "LIFECYCLE", "START", {}, that)
appReport({
reportType: 'start',
pt: 'LIFECYCLE',
pn: 'START',
param: {}
}, that);
}
})
that.globalData.networkType = net;
... ...
'use strict'
import { APP_REPORT_HOST, APP_VERSION, APP_BUILD} from '../libs/config';
import { APP_REPORT } from '../libs/request';
import md5 from '../vendors/md5';
import Promise from '../vendors/es6-promise';
import { APP_REPORT_HOST, APP_VERSION, APP_BUILD } from '../libs/config';
let getDeviceInfo = function (app) {
let ak = 'yoholuck_mp';//
let ak = 'yoholuck_mp'; // 小程序标识
let systemInfo = app.globalData.systemInfo
let device = {}
... ... @@ -12,12 +11,12 @@ let getDeviceInfo = function (app) {
let union_type = app.getUnion_type();
device.ak = ak
device.udid = app.globalData.udid ? app.globalData.udid : '';
device.ch = union_type ? union_type: app.globalData.ch;
device.ch = union_type ? union_type : app.globalData.ch;
device.os = "weixinapp"
device.osv = systemInfo && systemInfo.version ? systemInfo.version:''
device.dm = systemInfo && systemInfo.model ? systemInfo.model.replace(' ', '_'):''
device.osv = systemInfo && systemInfo.version ? systemInfo.version : ''
device.dm = systemInfo && systemInfo.model ? systemInfo.model.replace(' ', '_') : ''
if (systemInfo.platform == 'ios'){
if (systemInfo.platform == 'ios') {
//针对ios设备,特殊处理dm,转为iphone_7这种格式
var start_num = device.dm.indexOf('<')
var end_num = device.dm.indexOf('>')
... ... @@ -30,61 +29,66 @@ let getDeviceInfo = function (app) {
}
}
}
return device;
}
let appReport = function(reportType, pt, pn, param,appObject) {
let app = appObject;
let appReport = function ({ reportType = 'hb', pt, pn, param = {} } = {}, _this) {
let app = _this || getApp();
let deviceInfo = getDeviceInfo(app)
if (!pt || !pn || !deviceInfo || !deviceInfo.dm) return;
if(!param)param = {};
if(!reportType)reportType='hb';
if (!reportType) reportType = 'hb';
let ts = new Date().getTime() + '000000';
let uid = app && app.globalData && app.globalData.userInfo && app.globalData.userInfo.uid ? md5(app.globalData.userInfo.uid) : '';
if(!uid){
if (!uid) {
uid = md5(app.getUid());
}
let event = {};
let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
let networkType = app && app.globalData && app.globalData.networkType ? app.globalData.networkType : '0';
let event = {}
event.ps = '0',
event.av = APP_VERSION,
event.ab = APP_BUILD,
event.ca = '0',
event.net = networkType,
event.sid = sid,
event.uid = uid,
event.ts = ts,
event.pt = pt,
event.pn = pn,
event.param = param
event.ps = '0';
event.av = APP_VERSION;
event.ab = APP_BUILD;
event.ca = '0';
event.net = networkType;
event.sid = sid;
event.uid = uid;
event.ts = ts;
event.pt = pt;
event.pn = pn;
event.param = param;
let events = [];
events.push(event)
//组装最终要上报的数据
let parameters = {};
parameters.type = reportType,
parameters.device = deviceInfo,
parameters.events = events,
APP_REPORT(APP_REPORT_HOST, parameters)
.then(function (data) {
// console.log(data)
})
.catch(function (error) {
parameters.type = reportType;
parameters.device = deviceInfo;
parameters.events = events;
let _appReport = function (url, params = {}) {
return new Promise(function (resolve, reject) {
let app = getApp();
let data = JSON.stringify(params)
let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
let header = {
'content-type': "application/json",
'x-yoho-sid': md5(sid),
}
wx.request({
url,
data,
header,
method: 'POST'
});
})
};
_appReport(APP_REPORT_HOST, parameters);
}
module.exports = {
appReport,
}
\ No newline at end of file
export default appReport;
\ No newline at end of file
... ...
// 线上环境
export const API_HOST = 'https://api.yoho.cn';
export const SERVICE_HOST = 'https://api.yoho.cn';
export const ACTIVITY_HOST = 'https://action.yoho.cn';
// export const API_HOST = 'https://api.yoho.cn';
// export const SERVICE_HOST = 'https://api.yoho.cn';
// export const ACTIVITY_HOST = 'https://action.yoho.cn';
// export const APP_REPORT_HOST = 'https://app.yoho.cn/collect/v3';
// export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile';
// 测试环境
// export const API_HOST = 'http://api-test3.dev.yohocorp.com';
// export const SERVICE_HOST = 'http://api-test3.dev.yohocorp.com';
export const API_HOST = 'http://api-test3.dev.yohocorp.com';
export const SERVICE_HOST = 'http://api-test3.dev.yohocorp.com';
// export const ACTIVITY_HOST = 'http://yoho-activity-platform.test3.ingress.dev.yohocorp.com';
// export const ACTIVITY_HOST = 'http://192.168.102.49:6006';
// export const API_HOST = 'http://dev-api.yohops.com:9999';
// export const SERVICE_HOST = 'http://dev-api.yohops.com:9999/';
// export const API_HOST = 'http://api-test1.yohops.com:9999';
// export const SERVICE_HOST = 'http://api-test1.yohops.com:9999/';
// export const API_HOST = 'http://api-test2.dev.yohocorp.com';
// export const SERVICE_HOST = 'http://api-test2.dev.yohocorp.com';
// export const APP_REPORT_HOST = 'http://app.yoho.cn/collect/v3';
// export const API_HOST = 'https://apigray.yoho.cn';
// export const SERVICE_HOST = 'https://apigray.yoho.cn';
export const APP_REPORT_HOST = 'https://app.yoho.cn/collect/v3';
export const ACTIVITY_HOST = 'http://192.168.102.49:6006';
export const APP_REPORT_HOST = 'http://app.yoho.cn/collect/v3';
export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile';
export const MINI_APP_TYPE = 29;
export const MINI_QR_TYPE = 16;
export const OS_VERSION = 'yohobuy:h5';
export const APP_VERSION = '2.9.0';
export const APP_BUILD = '1041';
... ...
... ... @@ -2,9 +2,9 @@ import Promise from '../vendors/es6-promise';
import objectAssign from '../vendors/object-assign';
import trimObject from '../utils/trimObject';
import queryString from '../vendors/query-string';
import md5 from '../vendors/md5';
import {API_HOST,APP_VERSION, CLIENT_TYPE, PRIVATE_KEY} from '../libs/config';
import { getYHStorageSync } from '../utils/util';
import {API_HOST,APP_VERSION, CLIENT_TYPE, PRIVATE_KEY} from '../libs/config';
import appReport from './appReport';
let crypto = require('./cryptojs/cryptojs.js').Crypto
let p1SecretKey = "yoho9646yoho9646"
... ... @@ -38,14 +38,12 @@ function getPrivateKey(){
method,
header: header,
success: function (res) {
// console.log("res:", res)
if (res && res.data && res.data.data && res.data.data.sk) {
app.globalData.p2SecretKey = res.data.data.sk;
wx.setStorage({
key: "p2SecretKey",
data: res.data.data.sk
});
resolve(app.globalData.p2SecretKey)
}
},
... ... @@ -54,7 +52,6 @@ function getPrivateKey(){
let message = err.message ? err.message : '';
let isPrivatekeyError = true
reject({ code, message, isPrivatekeyError});
// console.log("err:",err)
}
});
... ... @@ -127,6 +124,17 @@ function request(method = 'GET') {
errMsg = res.errMsg,
data = res.data;
if (statusCode !== 200) {
appReport({
pt: 'NETWORK',
pn: 'NETWORK_API_CODE_ERR',
param: {
url: url,
ec: statusCode
}
});
}
if (statusCode == 200) {
resolve(data);
} else {
... ... @@ -141,9 +149,20 @@ function request(method = 'GET') {
}
},
fail: function (err) {
let code = err.code ? err.code : 800;
let message = err.message ? err.message : '';
reject({code, message});
const ERROR_TYPE = {
['request:fail']: 'NETWORK_API_CODE_ERR',
['request:fail timeout']: 'NETWORK_API_TIMEOUT'
};
const errType = ERROR_TYPE[err && err.errMsg || ''] || '';
appReport({
pt: 'NETWORK',
pn: errType,
param: {
url: url,
st: JSON.stringify(err || {})
}
});
}
});
})
... ... @@ -209,6 +228,17 @@ function request(method = 'GET') {
errMsg = res.errMsg,
data = res.data;
if (statusCode !== 200) {
appReport({
pt: 'NETWORK',
pn: 'NETWORK_API_CODE_ERR',
param: {
url: url,
ec: statusCode
}
});
}
if (statusCode == 200) {
resolve(data);
} else {
... ... @@ -223,9 +253,20 @@ function request(method = 'GET') {
}
},
fail: function (err) {
let code = err.code ? err.code : 800;
let message = err.message ? err.message : '';
reject({ code, message });
const ERROR_TYPE = {
['request:fail']: 'NETWORK_API_CODE_ERR',
['request:fail timeout']: 'NETWORK_API_TIMEOUT'
};
const errType = ERROR_TYPE[err && err.errMsg || ''] || '';
appReport({
pt: 'NETWORK',
pn: errType,
param: {
url: url,
st: JSON.stringify(err || {})
}
});
}
});
})
... ... @@ -253,26 +294,6 @@ function uploadLogData(method = 'POST') {
}
}
function appReport(method = 'POST') {
return function (url, params = {}) {
return new Promise(function (resolve, reject) {
let app = getApp();
let data = JSON.stringify(params)
let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
let header = {
'content-type': "application/json",
'x-yoho-sid': md5(sid),
}
wx.request({
url,
data,
method,
header,
});
})
}
}
function _publicParams() {
let app_version = APP_VERSION;
let os_version = '';
... ... @@ -289,14 +310,6 @@ function _publicParams() {
// Do something when catch error
}
// app_version = '5.6.0';
// os_version = '10.3';
// screen_size = '320x568';
// let uid = '0';
// let udid = 'acea1c6170ecca417c67979a406156950bcf4fe5';
// let physical_channel = 1;
return {
app_version,
os_version,
... ... @@ -384,12 +397,10 @@ export const GET = request('GET');
export const POST = request('POST');
export const PUT = request('PUT');
export const DELETE = request('DELETE');
export const UPLOAD_LOG = uploadLogData('POST')
export const APP_REPORT = appReport('POST')
export const UPLOAD_LOG = uploadLogData('POST');
module.exports = {
sign_body,
APP_REPORT,
UPLOAD_LOG,
GET,
POST,
... ...
{
"description": "项目配置文件。",
"setting": {
"urlCheck": true,
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": true,
... ...