|
|
@@ -839,6 +839,53 @@
|
|
|
return readQueryParam('wxDebug') === '1';
|
|
|
}
|
|
|
|
|
|
+ /** URL 加 apiDebug=1 或 wxDebug=1;localhost / test.ailien.shop 等测试域默认开启 */
|
|
|
+ function isApiDebugOn() {
|
|
|
+ if (readQueryParam('apiDebug') === '1' || isWxDebugOn()) return true;
|
|
|
+ if (readQueryParam('apiDebug') === '0') return false;
|
|
|
+ return isWxPcAutoDebugHost();
|
|
|
+ }
|
|
|
+
|
|
|
+ function apiDebugAlert(title, payload) {
|
|
|
+ if (!isApiDebugOn()) return;
|
|
|
+ var text = '';
|
|
|
+ try {
|
|
|
+ if (payload == null) {
|
|
|
+ text = '(null)';
|
|
|
+ } else if (typeof payload === 'string') {
|
|
|
+ text = payload;
|
|
|
+ } else {
|
|
|
+ text = JSON.stringify(payload, null, 2);
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ text = String(payload);
|
|
|
+ }
|
|
|
+ if (text.length > 1400) {
|
|
|
+ text = text.slice(0, 1400) + '\n…(已截断,完整见控制台)';
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ window.alert('[' + title + ']\n' + text);
|
|
|
+ } catch (e2) {
|
|
|
+ console.log('[apiDebug]', title, payload);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function apiDebugFailAlert(title, err, extra) {
|
|
|
+ var msg = err && err.message ? String(err.message) : String(err || '未知错误');
|
|
|
+ var tip =
|
|
|
+ '[' +
|
|
|
+ title +
|
|
|
+ ']\n' +
|
|
|
+ msg +
|
|
|
+ (extra ? '\n\n' + extra : '') +
|
|
|
+ '\n\n若为 HTTPS 页面请求 HTTP 接口,可能被浏览器拦截(混合内容)。';
|
|
|
+ try {
|
|
|
+ window.alert(tip);
|
|
|
+ } catch (e2) {
|
|
|
+ console.warn('[apiDebug-fail]', title, err, extra);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function isWxForceDebug() {
|
|
|
return readQueryParam('wxForce') === '1';
|
|
|
}
|
|
|
@@ -1809,8 +1856,21 @@
|
|
|
form.set('longitude', formBody.longitude);
|
|
|
form.set('latitude', formBody.latitude);
|
|
|
form.set('phoneId', formBody.phoneId);
|
|
|
-
|
|
|
- return fetch(API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT', {
|
|
|
+
|
|
|
+ var detailPath = '/recommend/querySecondGoodsDetailWithOutJWT';
|
|
|
+ var detailUrl = API_BASE_SECOND + detailPath;
|
|
|
+ var formStr = form.toString();
|
|
|
+ apiDebugAlert('querySecondGoodsDetailWithOutJWT 请求', {
|
|
|
+ url: detailUrl,
|
|
|
+ method: 'POST',
|
|
|
+ contentType: 'application/x-www-form-urlencoded',
|
|
|
+ body: formStr,
|
|
|
+ pageProtocol: location.protocol,
|
|
|
+ pageHost: location.host
|
|
|
+ });
|
|
|
+ console.log('[querySecondGoodsDetailWithOutJWT] POST', detailUrl, formStr);
|
|
|
+
|
|
|
+ return fetch(detailUrl, {
|
|
|
method: 'POST',
|
|
|
mode: 'cors',
|
|
|
credentials: 'omit',
|
|
|
@@ -1818,19 +1878,31 @@
|
|
|
Accept: 'application/json',
|
|
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
},
|
|
|
- body: form.toString()
|
|
|
+ body: formStr
|
|
|
})
|
|
|
.then(function (res) {
|
|
|
+ apiDebugAlert('querySecondGoodsDetailWithOutJWT HTTP', {
|
|
|
+ status: res.status,
|
|
|
+ ok: res.ok,
|
|
|
+ url: detailUrl
|
|
|
+ });
|
|
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
|
return res.json();
|
|
|
})
|
|
|
.then(function (res) {
|
|
|
+ console.log('[querySecondGoodsDetailWithOutJWT] JSON', res);
|
|
|
+ apiDebugAlert('querySecondGoodsDetailWithOutJWT 返回', res);
|
|
|
redirectCtx = redirectCtx || {};
|
|
|
if (isDetailResponseGoodsUnavailable(res)) {
|
|
|
var gsPick =
|
|
|
res && res.data && res.data.goodsStatus != null
|
|
|
? res.data.goodsStatus
|
|
|
: null;
|
|
|
+ apiDebugAlert('判定不可用,跳转 shareUndefined', {
|
|
|
+ goodsStatus: gsPick,
|
|
|
+ code: res && res.code,
|
|
|
+ msg: res && res.msg
|
|
|
+ });
|
|
|
redirectToShareUndefined(gsPick, redirectCtx);
|
|
|
return { redirected: true, exists: false };
|
|
|
}
|
|
|
@@ -1856,7 +1928,13 @@
|
|
|
'&pageNum=' + encodeURIComponent(String(pageNum || 1)) +
|
|
|
'&pageSize=' + encodeURIComponent(String(pageSize || 10)) +
|
|
|
'&userId=' + encodeURIComponent(userId != null ? String(userId) : '');
|
|
|
+ var commentUrl = API_BASE + path;
|
|
|
+ apiDebugAlert('getListBySourceType 请求', { url: commentUrl, method: 'GET' });
|
|
|
+ console.log('[getListBySourceType] GET', commentUrl);
|
|
|
+
|
|
|
return apiGet(path).then(function (res) {
|
|
|
+ console.log('[getListBySourceType] JSON', res);
|
|
|
+ apiDebugAlert('getListBySourceType 返回', res);
|
|
|
if (!isApiOk(res)) {
|
|
|
if (res && res.msg) console.warn('[getListBySourceType]', res.msg);
|
|
|
renderCommentsList([], 0);
|
|
|
@@ -1899,10 +1977,27 @@
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ apiDebugAlert('run 开始', {
|
|
|
+ goodsId: goodsId,
|
|
|
+ API_BASE_SECOND: API_BASE_SECOND,
|
|
|
+ API_BASE: API_BASE,
|
|
|
+ longitude: lonResolved,
|
|
|
+ latitude: latResolved,
|
|
|
+ phoneId: phoneId || '(空)',
|
|
|
+ hint: '联调请在 URL 加 apiDebug=1'
|
|
|
+ });
|
|
|
+
|
|
|
fetchSecondGoodsDetail(goodsId, lon, lat, phoneId, redirectCtx)
|
|
|
.catch(function (e) {
|
|
|
console.warn('[querySecondGoodsDetailWithOutJWT]', e);
|
|
|
- redirectToShareUndefined(null, redirectCtx);
|
|
|
+ apiDebugFailAlert(
|
|
|
+ 'querySecondGoodsDetailWithOutJWT 失败',
|
|
|
+ e,
|
|
|
+ '请求地址: ' + API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT'
|
|
|
+ );
|
|
|
+ if (!isApiDebugOn()) {
|
|
|
+ redirectToShareUndefined(null, redirectCtx);
|
|
|
+ }
|
|
|
return { redirected: true, exists: false };
|
|
|
})
|
|
|
.then(function (detailResult) {
|
|
|
@@ -1911,6 +2006,11 @@
|
|
|
}
|
|
|
return fetchCommentList(goodsId, userId, pageNum, pageSize).catch(function (e) {
|
|
|
console.warn('[getListBySourceType]', e);
|
|
|
+ apiDebugFailAlert(
|
|
|
+ 'getListBySourceType 失败',
|
|
|
+ e,
|
|
|
+ '留言接口前缀: ' + API_BASE
|
|
|
+ );
|
|
|
renderCommentsList([], 0);
|
|
|
});
|
|
|
});
|