测试
This commit is contained in:
parent
d089f4f282
commit
09fb0c3c81
@ -15,6 +15,13 @@ cors:
|
||||
- "http://127.0.0.1:3000"
|
||||
- "http://localhost:5173"
|
||||
- "http://127.0.0.1:5173"
|
||||
# 本地工具页会用 10300/8787/8788 承载静态 HTML;精确放行测试端口,避免用 "*" 破坏凭证请求边界。
|
||||
- "http://localhost:10300"
|
||||
- "http://127.0.0.1:10300"
|
||||
- "http://localhost:8787"
|
||||
- "http://127.0.0.1:8787"
|
||||
- "http://localhost:8788"
|
||||
- "http://127.0.0.1:8788"
|
||||
- "https://global-interaction.com"
|
||||
- "https://www.global-interaction.com"
|
||||
- "https://h5.global-interaction.com"
|
||||
|
||||
@ -15,6 +15,13 @@ cors:
|
||||
- "http://127.0.0.1:3000"
|
||||
- "http://localhost:5173"
|
||||
- "http://127.0.0.1:5173"
|
||||
# 本地工具页会用 10300/8787/8788 承载静态 HTML;精确放行测试端口,避免用 "*" 破坏凭证请求边界。
|
||||
- "http://localhost:10300"
|
||||
- "http://127.0.0.1:10300"
|
||||
- "http://localhost:8787"
|
||||
- "http://127.0.0.1:8787"
|
||||
- "http://localhost:8788"
|
||||
- "http://127.0.0.1:8788"
|
||||
- "https://global-interaction.com"
|
||||
- "https://www.global-interaction.com"
|
||||
- "https://h5.global-interaction.com"
|
||||
|
||||
@ -155,13 +155,27 @@
|
||||
const $ = (id) => document.getElementById(id);
|
||||
const defaultApiBase = "https://api-test.global-interaction.com";
|
||||
const isLocalProxy = ["localhost", "127.0.0.1", "::1"].includes(window.location.hostname);
|
||||
const bundledProxyPorts = new Set(["8787", "8788"]);
|
||||
const isBundledProxy = isLocalProxy && bundledProxyPorts.has(window.location.port);
|
||||
const localDirectApiBasePattern = /^https?:\/\/(?:localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/;
|
||||
|
||||
$("token").value = localStorage.getItem("baishun_test_access_token") || "";
|
||||
$("account").value = localStorage.getItem("baishun_test_account") || "";
|
||||
const savedApiBase = localStorage.getItem("baishun_test_api_base") || "";
|
||||
$("apiBase").value = isLocalProxy && (!savedApiBase || savedApiBase === defaultApiBase) ? "" : (savedApiBase || defaultApiBase);
|
||||
$("apiBase").value = initialApiBase(savedApiBase);
|
||||
$("appCode").value = localStorage.getItem("baishun_test_app_code") || $("appCode").value;
|
||||
|
||||
function initialApiBase(savedValue) {
|
||||
const saved = savedValue.trim().replace(/\/+$/, "");
|
||||
// 仓库自带 Node 代理默认监听 8787,本地占用时可切到 8788;空 API Base 会让请求走同源 /api 转发。Python 等纯静态服务
|
||||
// 没有这个代理能力,因此必须保留用户手动填写的本地 gateway 地址,交给 gateway CORS 白名单处理。
|
||||
if (isLocalProxy && (!saved || saved === defaultApiBase || (isBundledProxy && localDirectApiBasePattern.test(saved)))) {
|
||||
localStorage.setItem("baishun_test_api_base", "");
|
||||
return "";
|
||||
}
|
||||
return saved || defaultApiBase;
|
||||
}
|
||||
|
||||
function apiBase() {
|
||||
return $("apiBase").value.trim().replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
@ -158,6 +158,15 @@
|
||||
pool_id
|
||||
<input id="poolId" value="lucky" />
|
||||
</label>
|
||||
<label>
|
||||
奖池预设
|
||||
<select id="poolPreset">
|
||||
<option value="lucky">旧奖池 lucky</option>
|
||||
<option value="super_lucky">旧奖池 super_lucky</option>
|
||||
<option value="lucky_100">新奖池 lucky_100</option>
|
||||
<option value="">手动输入</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
gift_count
|
||||
<input id="giftCount" inputmode="numeric" value="1" />
|
||||
@ -167,6 +176,7 @@
|
||||
<button id="randomReadyBtn" type="button">随机房间和礼物</button>
|
||||
<button id="loadPanelBtn" type="button">读取礼物面板</button>
|
||||
<button id="checkBtn" class="secondary" type="button">检查幸运礼物</button>
|
||||
<button id="newPoolDrawBtn" type="button">新奖池抽奖</button>
|
||||
<button id="imBtn" type="button">登录 IM</button>
|
||||
<button id="joinBtn" class="secondary" type="button">进房并加入 IM 群</button>
|
||||
<span id="roomStatus" class="status"></span>
|
||||
@ -238,7 +248,8 @@
|
||||
$("targetUserId").value = localStorage.getItem("lucky_gift_target_user_id") || "";
|
||||
$("imGroupId").value = localStorage.getItem("lucky_gift_im_group_id") || "";
|
||||
$("giftId").value = localStorage.getItem("lucky_gift_gift_id") || $("giftId").value;
|
||||
$("poolId").value = "lucky";
|
||||
$("poolId").value = localStorage.getItem("lucky_gift_pool_id") || "lucky";
|
||||
$("poolPreset").value = presetValue($("poolId").value.trim());
|
||||
$("giftCount").value = localStorage.getItem("lucky_gift_count") || $("giftCount").value;
|
||||
|
||||
function apiBase() {
|
||||
@ -265,6 +276,7 @@
|
||||
localStorage.setItem("lucky_gift_gift_id", $("giftId").value.trim());
|
||||
localStorage.setItem("lucky_gift_pool_id", $("poolId").value.trim());
|
||||
localStorage.setItem("lucky_gift_count", $("giftCount").value.trim());
|
||||
$("poolPreset").value = presetValue($("poolId").value.trim());
|
||||
}
|
||||
|
||||
async function request(path, options = {}) {
|
||||
@ -332,7 +344,6 @@
|
||||
if (data.account || data.uid) $("account").value = data.account || data.uid;
|
||||
state.selfUserID = String(data.uid || data.user_id || data.account || jwtUserID(accessToken) || "").trim();
|
||||
if (state.selfUserID) $("targetUserId").value = state.selfUserID;
|
||||
$("poolId").value = "lucky";
|
||||
rememberForm();
|
||||
}
|
||||
|
||||
@ -409,7 +420,6 @@
|
||||
setStatus("roomStatus", "随机获取本地房间...");
|
||||
try {
|
||||
setSelfRecipient();
|
||||
$("poolId").value = "lucky";
|
||||
const room = await randomLocalRoom();
|
||||
$("roomId").value = room.room_id || room.roomId || "";
|
||||
$("imGroupId").value = room.im_group_id || room.imGroupId || $("roomId").value.trim();
|
||||
@ -440,7 +450,7 @@
|
||||
if (!luckyGifts.length) throw new Error("当前房间礼物面板没有 lucky / super_lucky 礼物");
|
||||
renderGiftOptions(luckyGifts, { random: true });
|
||||
setSelfRecipient();
|
||||
$("poolId").value = "lucky";
|
||||
applyPoolFallbackFromGift($("giftId").value, luckyGifts.find((gift) => gift.gift_id === $("giftId").value));
|
||||
rememberForm();
|
||||
addLog("随机选中幸运礼物", { gift_id: $("giftId").value, pool_id: $("poolId").value });
|
||||
}
|
||||
@ -453,7 +463,7 @@
|
||||
return;
|
||||
}
|
||||
for (const gift of gifts) {
|
||||
const poolID = "lucky";
|
||||
const poolID = luckyPoolID(gift) || fallbackPoolID(gift);
|
||||
const label = `${gift.name || gift.gift_id} / ${gift.gift_id} / pool=${poolID || "-"}`;
|
||||
const option = new Option(label, JSON.stringify({ gift_id: gift.gift_id, pool_id: poolID, coin_price: gift.coin_price }));
|
||||
select.append(option);
|
||||
@ -479,10 +489,46 @@
|
||||
const gift = parseJSON(value);
|
||||
if (!gift) return;
|
||||
$("giftId").value = gift.gift_id || $("giftId").value;
|
||||
$("poolId").value = "lucky";
|
||||
if (gift.pool_id) $("poolId").value = gift.pool_id;
|
||||
rememberForm();
|
||||
}
|
||||
|
||||
function fallbackPoolID(gift) {
|
||||
const typeCode = String(gift?.gift_type_code || "");
|
||||
if (typeCode === "super_lucky") return "super_lucky";
|
||||
return "lucky";
|
||||
}
|
||||
|
||||
function applyPoolFallbackFromGift(giftID, gift) {
|
||||
// 新奖池测试需要尊重手动输入和后台面板下发的 lucky_pool_id;只有礼物没有携带奖池时才按礼物类型兜底。
|
||||
const configured = luckyPoolID(gift);
|
||||
if (configured) {
|
||||
$("poolId").value = configured;
|
||||
return;
|
||||
}
|
||||
if (!$("poolId").value.trim()) {
|
||||
$("poolId").value = fallbackPoolID(gift || { gift_type_code: giftID.includes("super") ? "super_lucky" : "lucky" });
|
||||
}
|
||||
}
|
||||
|
||||
function usePoolPreset(value) {
|
||||
if (value) $("poolId").value = value;
|
||||
rememberForm();
|
||||
}
|
||||
|
||||
function presetValue(poolID) {
|
||||
return ["lucky", "super_lucky", "lucky_100"].includes(poolID) ? poolID : "";
|
||||
}
|
||||
|
||||
async function sendNewPoolLuckyGift() {
|
||||
// 新奖池第一步的验收重点是 room-service 送礼时明确传入 pool_id;这里固定 lucky_100,礼物 ID 仍允许手动改。
|
||||
$("poolId").value = "lucky_100";
|
||||
$("poolPreset").value = "lucky_100";
|
||||
rememberForm();
|
||||
if (!(await checkLuckyGift())) return;
|
||||
await sendLuckyGift();
|
||||
}
|
||||
|
||||
function setSelfRecipient() {
|
||||
const selfID = state.selfUserID || state.loginUserID || jwtUserID(token()) || $("account").value.trim();
|
||||
if (selfID) {
|
||||
@ -505,9 +551,11 @@
|
||||
});
|
||||
addLog("幸运礼物检查结果", data);
|
||||
setStatus("roomStatus", data.enabled ? "幸运礼物可用" : `不可用:${data.reason || "-"}`, data.enabled ? "ok" : "error");
|
||||
return Boolean(data.enabled);
|
||||
} catch (err) {
|
||||
addLog("幸运礼物检查失败", errorMessage(err), "error");
|
||||
setStatus("roomStatus", errorMessage(err), "error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -755,6 +803,7 @@
|
||||
$("randomReadyBtn").onclick = prepareRandomRoomAndGift;
|
||||
$("loadPanelBtn").onclick = loadGiftPanel;
|
||||
$("checkBtn").onclick = checkLuckyGift;
|
||||
$("newPoolDrawBtn").onclick = sendNewPoolLuckyGift;
|
||||
$("imBtn").onclick = loginIM;
|
||||
$("joinBtn").onclick = joinRoomAndGroup;
|
||||
$("sendBtn").onclick = sendLuckyGift;
|
||||
@ -764,6 +813,8 @@
|
||||
renderEmptyResult("已清空");
|
||||
};
|
||||
$("giftSelect").onchange = applySelectedGift;
|
||||
$("poolId").oninput = rememberForm;
|
||||
$("poolPreset").onchange = (event) => usePoolPreset(event.target.value);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user