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'; @@ -6,7 +6,7 @@ import {API_HOST, MINI_APP_TYPE} from './libs/config';
6 import mta from './vendors/mta_analysis'; 6 import mta from './vendors/mta_analysis';
7 import {Event} from '/login/utils/index.js'; 7 import {Event} from '/login/utils/index.js';
8 import {wxLogin} from '/login/utils/login/login'; 8 import {wxLogin} from '/login/utils/login/login';
9 -import {appReport} from './libs/appReport.js'; 9 +import appReport from './libs/appReport';
10 import {isStringEmpty, getYHStorageSync} from './utils/util'; 10 import {isStringEmpty, getYHStorageSync} from './utils/util';
11 import regeneratorRuntime from '/login/libs/regenerator-runtime/index'; 11 import regeneratorRuntime from '/login/libs/regenerator-runtime/index';
12 12
@@ -144,11 +144,21 @@ App({ @@ -144,11 +144,21 @@ App({
144 } 144 }
145 145
146 if (options && options.scene){ 146 if (options && options.scene){
147 - appReport('start', "LIFECYCLE", "RESUME", {  
148 - 'activeWay': options.scene + ""  
149 - }, this) 147 + appReport({
  148 + reportType: 'start',
  149 + pt: 'LIFECYCLE',
  150 + pn: 'RESUME',
  151 + param: {
  152 + 'activeWay': options.scene + ''
  153 + }
  154 + }, this);
150 }else{ 155 }else{
151 - appReport('start', "LIFECYCLE", "RESUME", {}, this) 156 + appReport({
  157 + reportType: 'start',
  158 + pt: 'LIFECYCLE',
  159 + pn: 'RESUME',
  160 + param: {}
  161 + }, this);
152 } 162 }
153 163
154 let scene = options ? options.scene : ''; 164 let scene = options ? options.scene : '';
@@ -157,9 +167,14 @@ App({ @@ -157,9 +167,14 @@ App({
157 167
158 //当应用程序进入后台状态时触发 168 //当应用程序进入后台状态时触发
159 onHide () { 169 onHide () {
160 - let params = {};  
161 - yasReport(YB_ENTER_BACKGROUND,params);  
162 - appReport('start', "LIFECYCLE", "STOP", {},this) 170 + let params = {};
  171 + yasReport(YB_ENTER_BACKGROUND, params);
  172 + appReport({
  173 + reportType: 'start',
  174 + pt: 'LIFECYCLE',
  175 + pn: 'STOP',
  176 + param: {}
  177 + }, this);
163 }, 178 },
164 179
165 getUserInfo: function () { 180 getUserInfo: function () {
@@ -400,7 +415,6 @@ App({ @@ -400,7 +415,6 @@ App({
400 }, 415 },
401 416
402 getShareInfo: function () { 417 getShareInfo: function () {
403 - // console.log('getShareInfo');  
404 let param = { 418 let param = {
405 share_id: this.globalData.shareId, 419 share_id: this.globalData.shareId,
406 } 420 }
@@ -468,10 +482,14 @@ App({ @@ -468,10 +482,14 @@ App({
468 } else { 482 } else {
469 net = '0'; 483 net = '0';
470 } 484 }
471 - // console.log("network:",net)  
472 }, 485 },
473 complete:function(res){ 486 complete:function(res){
474 - appReport('start', "LIFECYCLE", "START", {}, that) 487 + appReport({
  488 + reportType: 'start',
  489 + pt: 'LIFECYCLE',
  490 + pn: 'START',
  491 + param: {}
  492 + }, that);
475 } 493 }
476 }) 494 })
477 that.globalData.networkType = net; 495 that.globalData.networkType = net;
1 -'use strict'  
2 -import { APP_REPORT_HOST, APP_VERSION, APP_BUILD} from '../libs/config';  
3 -import { APP_REPORT } from '../libs/request';  
4 import md5 from '../vendors/md5'; 1 import md5 from '../vendors/md5';
  2 +import Promise from '../vendors/es6-promise';
  3 +import { APP_REPORT_HOST, APP_VERSION, APP_BUILD } from '../libs/config';
5 4
6 let getDeviceInfo = function (app) { 5 let getDeviceInfo = function (app) {
7 - let ak = 'yoholuck_mp';// 6 + let ak = 'yoholuck_mp'; // 小程序标识
8 7
9 let systemInfo = app.globalData.systemInfo 8 let systemInfo = app.globalData.systemInfo
10 let device = {} 9 let device = {}
@@ -12,12 +11,12 @@ let getDeviceInfo = function (app) { @@ -12,12 +11,12 @@ let getDeviceInfo = function (app) {
12 let union_type = app.getUnion_type(); 11 let union_type = app.getUnion_type();
13 device.ak = ak 12 device.ak = ak
14 device.udid = app.globalData.udid ? app.globalData.udid : ''; 13 device.udid = app.globalData.udid ? app.globalData.udid : '';
15 - device.ch = union_type ? union_type: app.globalData.ch; 14 + device.ch = union_type ? union_type : app.globalData.ch;
16 device.os = "weixinapp" 15 device.os = "weixinapp"
17 - device.osv = systemInfo && systemInfo.version ? systemInfo.version:''  
18 - device.dm = systemInfo && systemInfo.model ? systemInfo.model.replace(' ', '_'):'' 16 + device.osv = systemInfo && systemInfo.version ? systemInfo.version : ''
  17 + device.dm = systemInfo && systemInfo.model ? systemInfo.model.replace(' ', '_') : ''
19 18
20 - if (systemInfo.platform == 'ios'){ 19 + if (systemInfo.platform == 'ios') {
21 //针对ios设备,特殊处理dm,转为iphone_7这种格式 20 //针对ios设备,特殊处理dm,转为iphone_7这种格式
22 var start_num = device.dm.indexOf('<') 21 var start_num = device.dm.indexOf('<')
23 var end_num = device.dm.indexOf('>') 22 var end_num = device.dm.indexOf('>')
@@ -30,61 +29,66 @@ let getDeviceInfo = function (app) { @@ -30,61 +29,66 @@ let getDeviceInfo = function (app) {
30 } 29 }
31 } 30 }
32 } 31 }
33 -  
34 return device; 32 return device;
35 } 33 }
36 34
37 -let appReport = function(reportType, pt, pn, param,appObject) {  
38 - let app = appObject; 35 +let appReport = function ({ reportType = 'hb', pt, pn, param = {} } = {}, _this) {
  36 + let app = _this || getApp();
39 37
40 let deviceInfo = getDeviceInfo(app) 38 let deviceInfo = getDeviceInfo(app)
41 if (!pt || !pn || !deviceInfo || !deviceInfo.dm) return; 39 if (!pt || !pn || !deviceInfo || !deviceInfo.dm) return;
42 - if(!param)param = {};  
43 - if(!reportType)reportType='hb'; 40 + if (!reportType) reportType = 'hb';
44 41
45 let ts = new Date().getTime() + '000000'; 42 let ts = new Date().getTime() + '000000';
46 let uid = app && app.globalData && app.globalData.userInfo && app.globalData.userInfo.uid ? md5(app.globalData.userInfo.uid) : ''; 43 let uid = app && app.globalData && app.globalData.userInfo && app.globalData.userInfo.uid ? md5(app.globalData.userInfo.uid) : '';
47 44
48 - if(!uid){ 45 + if (!uid) {
49 uid = md5(app.getUid()); 46 uid = md5(app.getUid());
50 } 47 }
51 48
  49 + let event = {};
52 let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : ''; 50 let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
53 -  
54 let networkType = app && app.globalData && app.globalData.networkType ? app.globalData.networkType : '0'; 51 let networkType = app && app.globalData && app.globalData.networkType ? app.globalData.networkType : '0';
55 52
56 - let event = {}  
57 - event.ps = '0',  
58 - event.av = APP_VERSION,  
59 - event.ab = APP_BUILD,  
60 - event.ca = '0',  
61 - event.net = networkType,  
62 - event.sid = sid,  
63 - event.uid = uid,  
64 - event.ts = ts,  
65 - event.pt = pt,  
66 - event.pn = pn,  
67 - event.param = param 53 + event.ps = '0';
  54 + event.av = APP_VERSION;
  55 + event.ab = APP_BUILD;
  56 + event.ca = '0';
  57 + event.net = networkType;
  58 + event.sid = sid;
  59 + event.uid = uid;
  60 + event.ts = ts;
  61 + event.pt = pt;
  62 + event.pn = pn;
  63 + event.param = param;
68 64
69 let events = []; 65 let events = [];
70 events.push(event) 66 events.push(event)
71 67
72 //组装最终要上报的数据 68 //组装最终要上报的数据
73 let parameters = {}; 69 let parameters = {};
74 - parameters.type = reportType,  
75 - parameters.device = deviceInfo,  
76 - parameters.events = events,  
77 -  
78 -  
79 - APP_REPORT(APP_REPORT_HOST, parameters)  
80 - .then(function (data) {  
81 - // console.log(data) 70 + parameters.type = reportType;
  71 + parameters.device = deviceInfo;
  72 + parameters.events = events;
  73 +
  74 + let _appReport = function (url, params = {}) {
  75 + return new Promise(function (resolve, reject) {
  76 + let app = getApp();
  77 + let data = JSON.stringify(params)
  78 + let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';
  79 + let header = {
  80 + 'content-type': "application/json",
  81 + 'x-yoho-sid': md5(sid),
  82 + }
  83 + wx.request({
  84 + url,
  85 + data,
  86 + header,
  87 + method: 'POST'
  88 + });
82 }) 89 })
83 - .catch(function (error) {  
84 - });  
85 - 90 + };
  91 + _appReport(APP_REPORT_HOST, parameters);
86 } 92 }
87 93
88 -module.exports = {  
89 - appReport,  
90 -}  
  94 +export default appReport;
1 // 线上环境 1 // 线上环境
2 -export const API_HOST = 'https://api.yoho.cn';  
3 -export const SERVICE_HOST = 'https://api.yoho.cn';  
4 -export const ACTIVITY_HOST = 'https://action.yoho.cn'; 2 +// export const API_HOST = 'https://api.yoho.cn';
  3 +// export const SERVICE_HOST = 'https://api.yoho.cn';
  4 +// export const ACTIVITY_HOST = 'https://action.yoho.cn';
  5 +// export const APP_REPORT_HOST = 'https://app.yoho.cn/collect/v3';
  6 +// export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile';
5 7
6 // 测试环境 8 // 测试环境
7 -// export const API_HOST = 'http://api-test3.dev.yohocorp.com';  
8 -// export const SERVICE_HOST = 'http://api-test3.dev.yohocorp.com'; 9 +export const API_HOST = 'http://api-test3.dev.yohocorp.com';
  10 +export const SERVICE_HOST = 'http://api-test3.dev.yohocorp.com';
9 // export const ACTIVITY_HOST = 'http://yoho-activity-platform.test3.ingress.dev.yohocorp.com'; 11 // export const ACTIVITY_HOST = 'http://yoho-activity-platform.test3.ingress.dev.yohocorp.com';
10 -// export const ACTIVITY_HOST = 'http://192.168.102.49:6006';  
11 -  
12 -// export const API_HOST = 'http://dev-api.yohops.com:9999';  
13 -// export const SERVICE_HOST = 'http://dev-api.yohops.com:9999/';  
14 -  
15 -// export const API_HOST = 'http://api-test1.yohops.com:9999';  
16 -// export const SERVICE_HOST = 'http://api-test1.yohops.com:9999/';  
17 -  
18 -  
19 -// export const API_HOST = 'http://api-test2.dev.yohocorp.com';  
20 -// export const SERVICE_HOST = 'http://api-test2.dev.yohocorp.com';  
21 -// export const APP_REPORT_HOST = 'http://app.yoho.cn/collect/v3';  
22 -  
23 -// export const API_HOST = 'https://apigray.yoho.cn';  
24 -// export const SERVICE_HOST = 'https://apigray.yoho.cn';  
25 -  
26 -export const APP_REPORT_HOST = 'https://app.yoho.cn/collect/v3'; 12 +export const ACTIVITY_HOST = 'http://192.168.102.49:6006';
  13 +export const APP_REPORT_HOST = 'http://app.yoho.cn/collect/v3';
27 export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile'; 14 export const LOG_EVENT_HOST = 'https://analysis.yohobuy.com/yas_mobile';
28 15
29 export const MINI_APP_TYPE = 29; 16 export const MINI_APP_TYPE = 29;
30 export const MINI_QR_TYPE = 16; 17 export const MINI_QR_TYPE = 16;
31 18
32 export const OS_VERSION = 'yohobuy:h5'; 19 export const OS_VERSION = 'yohobuy:h5';
33 -  
34 export const APP_VERSION = '2.9.0'; 20 export const APP_VERSION = '2.9.0';
35 export const APP_BUILD = '1041'; 21 export const APP_BUILD = '1041';
36 22
@@ -2,9 +2,9 @@ import Promise from '../vendors/es6-promise'; @@ -2,9 +2,9 @@ import Promise from '../vendors/es6-promise';
2 import objectAssign from '../vendors/object-assign'; 2 import objectAssign from '../vendors/object-assign';
3 import trimObject from '../utils/trimObject'; 3 import trimObject from '../utils/trimObject';
4 import queryString from '../vendors/query-string'; 4 import queryString from '../vendors/query-string';
5 -import md5 from '../vendors/md5';  
6 -import {API_HOST,APP_VERSION, CLIENT_TYPE, PRIVATE_KEY} from '../libs/config';  
7 import { getYHStorageSync } from '../utils/util'; 5 import { getYHStorageSync } from '../utils/util';
  6 +import {API_HOST,APP_VERSION, CLIENT_TYPE, PRIVATE_KEY} from '../libs/config';
  7 +import appReport from './appReport';
8 8
9 let crypto = require('./cryptojs/cryptojs.js').Crypto 9 let crypto = require('./cryptojs/cryptojs.js').Crypto
10 let p1SecretKey = "yoho9646yoho9646" 10 let p1SecretKey = "yoho9646yoho9646"
@@ -38,14 +38,12 @@ function getPrivateKey(){ @@ -38,14 +38,12 @@ function getPrivateKey(){
38 method, 38 method,
39 header: header, 39 header: header,
40 success: function (res) { 40 success: function (res) {
41 - // console.log("res:", res)  
42 if (res && res.data && res.data.data && res.data.data.sk) { 41 if (res && res.data && res.data.data && res.data.data.sk) {
43 app.globalData.p2SecretKey = res.data.data.sk; 42 app.globalData.p2SecretKey = res.data.data.sk;
44 wx.setStorage({ 43 wx.setStorage({
45 key: "p2SecretKey", 44 key: "p2SecretKey",
46 data: res.data.data.sk 45 data: res.data.data.sk
47 }); 46 });
48 -  
49 resolve(app.globalData.p2SecretKey) 47 resolve(app.globalData.p2SecretKey)
50 } 48 }
51 }, 49 },
@@ -54,7 +52,6 @@ function getPrivateKey(){ @@ -54,7 +52,6 @@ function getPrivateKey(){
54 let message = err.message ? err.message : ''; 52 let message = err.message ? err.message : '';
55 let isPrivatekeyError = true 53 let isPrivatekeyError = true
56 reject({ code, message, isPrivatekeyError}); 54 reject({ code, message, isPrivatekeyError});
57 - // console.log("err:",err)  
58 } 55 }
59 }); 56 });
60 57
@@ -127,6 +124,17 @@ function request(method = 'GET') { @@ -127,6 +124,17 @@ function request(method = 'GET') {
127 errMsg = res.errMsg, 124 errMsg = res.errMsg,
128 data = res.data; 125 data = res.data;
129 126
  127 + if (statusCode !== 200) {
  128 + appReport({
  129 + pt: 'NETWORK',
  130 + pn: 'NETWORK_API_CODE_ERR',
  131 + param: {
  132 + url: url,
  133 + ec: statusCode
  134 + }
  135 + });
  136 + }
  137 +
130 if (statusCode == 200) { 138 if (statusCode == 200) {
131 resolve(data); 139 resolve(data);
132 } else { 140 } else {
@@ -141,9 +149,20 @@ function request(method = 'GET') { @@ -141,9 +149,20 @@ function request(method = 'GET') {
141 } 149 }
142 }, 150 },
143 fail: function (err) { 151 fail: function (err) {
144 - let code = err.code ? err.code : 800;  
145 - let message = err.message ? err.message : '';  
146 - reject({code, message}); 152 + const ERROR_TYPE = {
  153 + ['request:fail']: 'NETWORK_API_CODE_ERR',
  154 + ['request:fail timeout']: 'NETWORK_API_TIMEOUT'
  155 + };
  156 + const errType = ERROR_TYPE[err && err.errMsg || ''] || '';
  157 +
  158 + appReport({
  159 + pt: 'NETWORK',
  160 + pn: errType,
  161 + param: {
  162 + url: url,
  163 + st: JSON.stringify(err || {})
  164 + }
  165 + });
147 } 166 }
148 }); 167 });
149 }) 168 })
@@ -209,6 +228,17 @@ function request(method = 'GET') { @@ -209,6 +228,17 @@ function request(method = 'GET') {
209 errMsg = res.errMsg, 228 errMsg = res.errMsg,
210 data = res.data; 229 data = res.data;
211 230
  231 + if (statusCode !== 200) {
  232 + appReport({
  233 + pt: 'NETWORK',
  234 + pn: 'NETWORK_API_CODE_ERR',
  235 + param: {
  236 + url: url,
  237 + ec: statusCode
  238 + }
  239 + });
  240 + }
  241 +
212 if (statusCode == 200) { 242 if (statusCode == 200) {
213 resolve(data); 243 resolve(data);
214 } else { 244 } else {
@@ -223,9 +253,20 @@ function request(method = 'GET') { @@ -223,9 +253,20 @@ function request(method = 'GET') {
223 } 253 }
224 }, 254 },
225 fail: function (err) { 255 fail: function (err) {
226 - let code = err.code ? err.code : 800;  
227 - let message = err.message ? err.message : '';  
228 - reject({ code, message }); 256 + const ERROR_TYPE = {
  257 + ['request:fail']: 'NETWORK_API_CODE_ERR',
  258 + ['request:fail timeout']: 'NETWORK_API_TIMEOUT'
  259 + };
  260 + const errType = ERROR_TYPE[err && err.errMsg || ''] || '';
  261 +
  262 + appReport({
  263 + pt: 'NETWORK',
  264 + pn: errType,
  265 + param: {
  266 + url: url,
  267 + st: JSON.stringify(err || {})
  268 + }
  269 + });
229 } 270 }
230 }); 271 });
231 }) 272 })
@@ -253,26 +294,6 @@ function uploadLogData(method = 'POST') { @@ -253,26 +294,6 @@ function uploadLogData(method = 'POST') {
253 } 294 }
254 } 295 }
255 296
256 -function appReport(method = 'POST') {  
257 - return function (url, params = {}) {  
258 - return new Promise(function (resolve, reject) {  
259 - let app = getApp();  
260 - let data = JSON.stringify(params)  
261 - let sid = app && app.globalData && app.globalData.sid ? app.globalData.sid : '';  
262 - let header = {  
263 - 'content-type': "application/json",  
264 - 'x-yoho-sid': md5(sid),  
265 - }  
266 - wx.request({  
267 - url,  
268 - data,  
269 - method,  
270 - header,  
271 - });  
272 - })  
273 - }  
274 -}  
275 -  
276 function _publicParams() { 297 function _publicParams() {
277 let app_version = APP_VERSION; 298 let app_version = APP_VERSION;
278 let os_version = ''; 299 let os_version = '';
@@ -289,14 +310,6 @@ function _publicParams() { @@ -289,14 +310,6 @@ function _publicParams() {
289 // Do something when catch error 310 // Do something when catch error
290 } 311 }
291 312
292 - // app_version = '5.6.0';  
293 - // os_version = '10.3';  
294 - // screen_size = '320x568';  
295 - // let uid = '0';  
296 - // let udid = 'acea1c6170ecca417c67979a406156950bcf4fe5';  
297 - // let physical_channel = 1;  
298 -  
299 -  
300 return { 313 return {
301 app_version, 314 app_version,
302 os_version, 315 os_version,
@@ -384,12 +397,10 @@ export const GET = request('GET'); @@ -384,12 +397,10 @@ export const GET = request('GET');
384 export const POST = request('POST'); 397 export const POST = request('POST');
385 export const PUT = request('PUT'); 398 export const PUT = request('PUT');
386 export const DELETE = request('DELETE'); 399 export const DELETE = request('DELETE');
387 -export const UPLOAD_LOG = uploadLogData('POST')  
388 -export const APP_REPORT = appReport('POST') 400 +export const UPLOAD_LOG = uploadLogData('POST');
389 401
390 module.exports = { 402 module.exports = {
391 sign_body, 403 sign_body,
392 - APP_REPORT,  
393 UPLOAD_LOG, 404 UPLOAD_LOG,
394 GET, 405 GET,
395 POST, 406 POST,
1 { 1 {
2 "description": "项目配置文件。", 2 "description": "项目配置文件。",
3 "setting": { 3 "setting": {
4 - "urlCheck": true, 4 + "urlCheck": false,
5 "es6": true, 5 "es6": true,
6 "postcss": true, 6 "postcss": true,
7 "minified": true, 7 "minified": true,