sunshibo пре 1 недеља
родитељ
комит
1fbddf4934
1 измењених фајлова са 12 додато и 111 уклоњено
  1. 12 111
      HBuilderProjects/secondShareGoods.html

+ 12 - 111
HBuilderProjects/secondShareGoods.html

@@ -668,12 +668,10 @@
 		'use strict';
 
 		/**
-		 * 进入页先校验商品是否存在
+		 * 进入页仅用 querySecondGoodsDetailWithOutJWT 判断商品是否存在(不用其 data 渲染页面)
 		 *   POST {API_BASE_SECOND}/recommend/querySecondGoodsDetailWithOutJWT
-		 *   body(x-www-form-urlencoded):goodsId、longitude、latitude、phoneId(均为字符串)
-		 * 无有效 data 或已下架/删除 → shareUndefined.html;有 data → renderGoodsDetail 再拉留言
-		 * 留言:GET {API_BASE}/commonComment/getListBySourceType
-		 * URL:goodsId、userId、phoneId、longitude/lon/jingdu、latitude/lat/weidu、alienSecondBase(可选覆盖二手接口前缀)
+		 *   body:goodsId、longitude、latitude、phoneId
+		 * 不存在/已下架/删除 → shareUndefined;存在 → applyFromUrl(分享链参数)+ 留言列表
 		 */
 		/**
 		 * 唤起 App 落地:二手商品详情(与 pages.json 路径一致)
@@ -839,53 +837,6 @@
 			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';
 		}
@@ -1828,10 +1779,10 @@
 		}
 
 		/**
-		 * 载入时校验商品是否存在(querySecondGoodsDetailWithOutJWT)
+		 * 仅用 querySecondGoodsDetailWithOutJWT 判断商品是否存在,不渲染接口返回的详情字段
 		 * @returns {Promise<{redirected:boolean, exists:boolean}>}
 		 */
-		function fetchSecondGoodsDetail(goodsId, lon, lat, phoneId, redirectCtx) {
+		function checkSecondGoodsExists(goodsId, lon, lat, phoneId, redirectCtx) {
 			var lonStr =
 				lon != null && String(lon).trim() !== ''
 					? String(lon).trim()
@@ -1857,18 +1808,9 @@
 			form.set('latitude', formBody.latitude);
 			form.set('phoneId', formBody.phoneId);
 
-			var detailPath = '/recommend/querySecondGoodsDetailWithOutJWT';
-			var detailUrl = API_BASE_SECOND + detailPath;
+			var detailUrl =
+				API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT';
 			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',
@@ -1881,34 +1823,21 @@
 				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 };
 					}
 					var d = isApiOk(res) ? res.data || res.result : null;
 					if (d && typeof d === 'object') {
-						renderGoodsDetail(d);
 						return { redirected: false, exists: true };
 					}
 					if (res && res.msg) {
@@ -1928,13 +1857,7 @@
 				'&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);
@@ -1977,40 +1900,18 @@
 				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)
+			checkSecondGoodsExists(goodsId, lon, lat, phoneId, redirectCtx)
 				.catch(function (e) {
 					console.warn('[querySecondGoodsDetailWithOutJWT]', e);
-					apiDebugFailAlert(
-						'querySecondGoodsDetailWithOutJWT 失败',
-						e,
-						'请求地址: ' + API_BASE_SECOND + '/recommend/querySecondGoodsDetailWithOutJWT'
-					);
-					if (!isApiDebugOn()) {
-						redirectToShareUndefined(null, redirectCtx);
-					}
-					return { redirected: true, exists: false };
+					return { redirected: false, exists: null, checkFailed: true };
 				})
-				.then(function (detailResult) {
-					if (!detailResult || detailResult.redirected) {
+				.then(function (checkResult) {
+					if (checkResult && checkResult.redirected) {
 						return;
 					}
+					applyFromUrl();
 					return fetchCommentList(goodsId, userId, pageNum, pageSize).catch(function (e) {
 						console.warn('[getListBySourceType]', e);
-						apiDebugFailAlert(
-							'getListBySourceType 失败',
-							e,
-							'留言接口前缀: ' + API_BASE
-						);
 						renderCommentsList([], 0);
 					});
 				});