feat: show current gift details in host center

This commit is contained in:
170-carry 2026-04-28 20:15:22 +08:00
parent 76063702bb
commit 229af34633
8 changed files with 330 additions and 91 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
<title>Stream Center</title>
<link rel="stylesheet" href="./style.css?v=20260428-1535" />
<link rel="stylesheet" href="./style.css?v=20260428-1610" />
</head>
<body>
<div class="host-center" aria-label="Stream Center" data-i18n-aria="page_label">
@ -59,9 +59,9 @@
</div>
<div class="vertical-line" aria-hidden="true"></div>
<div class="metric gift-metric">
<div class="label" data-i18n="target">Target</div>
<button class="gift-value" type="button" aria-live="polite">
<span class="amount-text" id="nextTargetValue">-</span>
<div class="label" data-i18n="current">Current</div>
<button class="gift-value" type="button" aria-live="polite" aria-label="Open daily data" data-i18n-aria="open_daily_data">
<span class="amount-text" id="currentGiftValue">0</span>
<span class="chevron">&rsaquo;</span>
</button>
</div>
@ -102,8 +102,23 @@
</section>
</main>
<div class="daily-modal" id="dailyModal" hidden>
<div class="daily-backdrop" data-close-daily></div>
<section class="daily-sheet" role="dialog" aria-modal="true" aria-labelledby="dailyTitle">
<div class="daily-sheet-head">
<h2 id="dailyTitle" data-i18n="daily_details">Daily data</h2>
<button class="daily-close" type="button" aria-label="Close" data-i18n-aria="close" data-close-daily>&times;</button>
</div>
<div class="daily-summary">
<span data-i18n="current">Current</span>
<strong id="dailyCurrentGift">0</strong>
</div>
<div class="daily-list" id="dailyList"></div>
</section>
</div>
<div class="home-indicator" aria-hidden="true"></div>
</div>
<script src="./script.js?v=20260428-1535" defer></script>
<script src="./script.js?v=20260428-1610" defer></script>
</body>
</html>

View File

@ -7,7 +7,13 @@
"uid": "معرّف المستخدم: 1234567890",
"agency": "الوكالة: Bilibili(101013)",
"streaming_duration": "مدة البث<br />(بالدقائق)",
"target": "الهدف",
"current": "الحالي",
"daily_details": "البيانات اليومية",
"gift_points": "نقاط الهدايا",
"online_minutes": "دقائق الاتصال",
"no_daily_data": "لا توجد بيانات يومية",
"close": "إغلاق",
"open_daily_data": "فتح البيانات اليومية",
"my_income": "دخلي",
"withdraw_exchange": "سحب/استبدال",
"open_withdraw_exchange": "فتح صفحة السحب والاستبدال",

View File

@ -7,7 +7,13 @@
"uid": "UID: 1234567890",
"agency": "Agency: Bilibili(101013)",
"streaming_duration": "Streaming Duration<br />(Minutes)",
"target": "Target",
"current": "Current",
"daily_details": "Daily data",
"gift_points": "Gift points",
"online_minutes": "Online minutes",
"no_daily_data": "No daily data",
"close": "Close",
"open_daily_data": "Open daily data",
"my_income": "My Income",
"withdraw_exchange": "Withdraw/Exchange",
"open_withdraw_exchange": "Open withdraw and exchange page",

View File

@ -7,7 +7,13 @@
"uid": "UID: 1234567890",
"agency": "Agensi: Bilibili(101013)",
"streaming_duration": "Durasi Streaming<br />(Menit)",
"target": "Target",
"current": "Saat ini",
"daily_details": "Data harian",
"gift_points": "Poin hadiah",
"online_minutes": "Menit online",
"no_daily_data": "Tidak ada data harian",
"close": "Tutup",
"open_daily_data": "Buka data harian",
"my_income": "Penghasilan Saya",
"withdraw_exchange": "Tarik/Tukar",
"open_withdraw_exchange": "Buka halaman tarik dan tukar",

View File

@ -7,7 +7,13 @@
"uid": "UID: 1234567890",
"agency": "Ajans: Bilibili(101013)",
"streaming_duration": "Yayın Süresi<br />(Dakika)",
"target": "Hedef",
"current": "Mevcut",
"daily_details": "Günlük veri",
"gift_points": "Hediye puanı",
"online_minutes": "Online dakika",
"no_daily_data": "Günlük veri yok",
"close": "Kapat",
"open_daily_data": "Günlük veriyi aç",
"my_income": "Gelirim",
"withdraw_exchange": "Çek/Değiştir",
"open_withdraw_exchange": "Çekme ve değişim sayfasını aç",

View File

@ -92,6 +92,8 @@
- `historySalary` 写入本地变量
- 读取 `targets[0]`
- 当前 `hyapp/host-center` 的 Streaming Duration 使用 `targets[0].target.onlineTime` 作为总直播时长
- 当前 `hyapp/host-center` 的 Current 使用 `targets[0].target.acceptGiftValue` 作为当前礼物积分
- Current 点击明细使用 `targets[0].target.dailyTargets[]`,展示每日 `dateNumber``acceptGiftValue``onlineTime`
- 结算状态映射:
- `SETTLED` -> `Completed`
- `UNPAID` -> `In Progress`
@ -255,6 +257,8 @@
- `historySalary`
- `targets`
- `targets[0].target.onlineTime`,当前 `hyapp/host-center` 用作 Streaming Duration 总时长
- `targets[0].target.acceptGiftValue`,当前 `hyapp/host-center` 用作 Current 礼物积分
- `targets[0].target.dailyTargets[]`,当前 `hyapp/host-center` 用作每日明细
- `targets[].status`
- `targets[].target.settlementResult.level`
- `targets[].target.level`

View File

@ -18,7 +18,13 @@
uid: "UID: 1234567890",
agency: "Agency: Bilibili(101013)",
streaming_duration: "Streaming Duration<br />(Minutes)",
target: "Target",
current: "Current",
daily_details: "Daily data",
gift_points: "Gift points",
online_minutes: "Online minutes",
no_daily_data: "No daily data",
close: "Close",
open_daily_data: "Open daily data",
my_income: "My Income",
withdraw_exchange: "Withdraw/Exchange",
open_withdraw_exchange: "Open withdraw and exchange page",
@ -45,7 +51,13 @@
uid: "معرّف المستخدم: 1234567890",
agency: "الوكالة: Bilibili(101013)",
streaming_duration: "مدة البث<br />(بالدقائق)",
target: "الهدف",
current: "الحالي",
daily_details: "البيانات اليومية",
gift_points: "نقاط الهدايا",
online_minutes: "دقائق الاتصال",
no_daily_data: "لا توجد بيانات يومية",
close: "إغلاق",
open_daily_data: "فتح البيانات اليومية",
my_income: "دخلي",
withdraw_exchange: "سحب/استبدال",
open_withdraw_exchange: "فتح صفحة السحب والاستبدال",
@ -72,7 +84,13 @@
uid: "UID: 1234567890",
agency: "Ajans: Bilibili(101013)",
streaming_duration: "Yayın Süresi<br />(Dakika)",
target: "Hedef",
current: "Mevcut",
daily_details: "Günlük veri",
gift_points: "Hediye puanı",
online_minutes: "Online dakika",
no_daily_data: "Günlük veri yok",
close: "Kapat",
open_daily_data: "Günlük veriyi aç",
my_income: "Gelirim",
withdraw_exchange: "Çek/Değiştir",
open_withdraw_exchange: "Çekme ve değişim sayfasını aç",
@ -99,7 +117,13 @@
uid: "UID: 1234567890",
agency: "Agensi: Bilibili(101013)",
streaming_duration: "Durasi Streaming<br />(Menit)",
target: "Target",
current: "Saat ini",
daily_details: "Data harian",
gift_points: "Poin hadiah",
online_minutes: "Menit online",
no_daily_data: "Tidak ada data harian",
close: "Tutup",
open_daily_data: "Buka data harian",
my_income: "Penghasilan Saya",
withdraw_exchange: "Tarik/Tukar",
open_withdraw_exchange: "Buka halaman tarik dan tukar",
@ -128,7 +152,8 @@
let currentIdentity = null;
let currentSalary = "0.00";
let currentStreamingDuration = "0";
let nextTargetValue = "-";
let currentGiftValue = "0";
let currentDailyTargets = [];
function readURLParams() {
const result = new URLSearchParams(window.location.search);
@ -177,7 +202,7 @@
if (window.location.protocol === "file:") return fallbackMessages[normalizedLang];
try {
const response = await fetch(`./locales/${normalizedLang}.json`, { cache: "no-store" });
const response = await fetch(`./locales/${normalizedLang}.json?v=20260428-1610`, { cache: "no-store" });
if (response.ok) return await response.json();
} catch (error) {
return fallbackMessages[normalizedLang];
@ -434,17 +459,20 @@
if (durationNode) durationNode.textContent = currentStreamingDuration;
}
function formatTargetValue(value) {
function formatCountValue(value) {
if (value === null || value === undefined || value === "") return "-";
const number = Number(value);
if (Number.isFinite(number) && Number.isInteger(number)) return String(number);
if (Number.isFinite(number)) return String(Number(number.toFixed(2)));
return String(value);
}
function renderNextTargetValue(value) {
nextTargetValue = formatTargetValue(value);
const targetNode = document.querySelector("#nextTargetValue");
if (targetNode) targetNode.textContent = nextTargetValue;
function renderCurrentGiftValue(value) {
currentGiftValue = formatCountValue(value === null || value === undefined || value === "" ? 0 : value);
const giftNode = document.querySelector("#currentGiftValue");
const dailyGiftNode = document.querySelector("#dailyCurrentGift");
if (giftNode) giftNode.textContent = currentGiftValue;
if (dailyGiftNode) dailyGiftNode.textContent = currentGiftValue;
}
function pickFirstMemberWorkTarget(body) {
@ -457,33 +485,79 @@
return target.acceptGiftValue ?? target.giftValue ?? target.giftScore ?? target.currentGiftValue ?? null;
}
function pickDirectNextTargetValue(workTarget) {
function pickDailyTargets(workTarget) {
const target = workTarget?.target || workTarget || {};
return target.nextTarget ?? target.nextLevelTarget ?? target.nextTargetValue ?? workTarget?.nextTarget ?? null;
return Array.isArray(target.dailyTargets) ? target.dailyTargets : [];
}
function pickPolicyRows(policyBody) {
if (Array.isArray(policyBody?.policy)) return policyBody.policy;
if (Array.isArray(policyBody?.policies)) return policyBody.policies;
return [];
function formatDateNumber(value) {
const text = String(value || "");
if (/^\d{8}$/.test(text)) {
return `${text.slice(0, 4)}.${text.slice(4, 6)}.${text.slice(6, 8)}`;
}
return text || "-";
}
function calculateNextTargetValue(giftValue, policyRows) {
const giftNumber = Number(giftValue);
if (!Number.isFinite(giftNumber) || !policyRows.length) return null;
function createDailyRow(item) {
const row = document.createElement("div");
row.className = "daily-row";
const rows = policyRows
.map((row) => ({
target: Number(row.target),
rawTarget: row.target
}))
.filter((row) => Number.isFinite(row.target))
.sort((a, b) => a.target - b.target);
const date = document.createElement("div");
date.className = "daily-date";
date.textContent = formatDateNumber(item?.dateNumber);
if (!rows.length) return null;
const values = document.createElement("div");
values.className = "daily-values";
const next = rows.find((row) => giftNumber < row.target);
return next ? next.rawTarget : null;
const gift = document.createElement("div");
gift.className = "daily-cell";
gift.innerHTML = `<span>${currentMessages.gift_points || fallbackMessages.en.gift_points}</span><strong>${formatCountValue(item?.acceptGiftValue ?? 0)}</strong>`;
const online = document.createElement("div");
online.className = "daily-cell";
online.innerHTML = `<span>${currentMessages.online_minutes || fallbackMessages.en.online_minutes}</span><strong>${formatCountValue(item?.onlineTime ?? 0)}</strong>`;
values.appendChild(gift);
values.appendChild(online);
row.appendChild(date);
row.appendChild(values);
return row;
}
function replaceNodeChildren(node, children) {
while (node.firstChild) node.removeChild(node.firstChild);
children.forEach((child) => node.appendChild(child));
}
function renderDailyTargets(targets = currentDailyTargets) {
currentDailyTargets = Array.isArray(targets) ? targets : [];
const list = document.querySelector("#dailyList");
if (!list) return;
if (!currentDailyTargets.length) {
const empty = document.createElement("div");
empty.className = "daily-empty";
empty.textContent = currentMessages.no_daily_data || fallbackMessages.en.no_daily_data;
replaceNodeChildren(list, [empty]);
return;
}
replaceNodeChildren(list, currentDailyTargets.map(createDailyRow));
}
function renderMemberWorkSummary(memberWork) {
const workTarget = pickFirstMemberWorkTarget(memberWork);
renderStreamingDuration(pickStreamingDuration(memberWork));
renderCurrentGiftValue(pickGiftValue(workTarget) ?? 0);
renderDailyTargets(pickDailyTargets(workTarget));
}
function setDailyModalOpen(open) {
const modal = document.querySelector("#dailyModal");
if (!modal) return;
modal.hidden = !open;
document.body.classList.toggle("daily-modal-open", open);
if (open) renderDailyTargets();
}
async function fetchUserProfile() {
@ -628,7 +702,7 @@
async function fetchStreamingDuration(memberId) {
const memberWork = await fetchMemberWork(memberId);
renderStreamingDuration(pickStreamingDuration(memberWork));
renderMemberWorkSummary(memberWork);
return memberWork;
}
@ -663,55 +737,6 @@
}
}
async function fetchAnchorPolicyForTarget() {
const token = readRawParam("token");
if (!token) {
console.warn("Missing token for /team/release/policy");
return null;
}
try {
const teamId = currentTeamId || await fetchTeamEntry();
if (!teamId) {
console.warn("Missing teamId for /team/release/policy");
return null;
}
const url = new URL("/team/release/policy", `${apiBaseURL()}/`);
url.searchParams.set("id", teamId);
const response = await fetch(url.toString(), {
cache: "no-store",
headers: authHeadersFromToken(token)
});
const data = await response.json().catch(() => ({}));
if (!response.ok || data.status === false) {
throw new Error(data.errorMsg || data.message || `Request failed: ${response.status}`);
}
return data.body || data.data || null;
} catch (error) {
console.error("Failed to load team policy for next target:", error);
return null;
}
}
async function fetchNextTargetValue(memberId, memberWork = null) {
const work = memberWork || await fetchMemberWork(memberId);
const workTarget = pickFirstMemberWorkTarget(work);
if (!workTarget) {
renderNextTargetValue("-");
return;
}
const directNextTarget = pickDirectNextTargetValue(workTarget);
const giftValue = pickGiftValue(workTarget);
const policy = await fetchAnchorPolicyForTarget();
const calculatedNextTarget = calculateNextTargetValue(giftValue, pickPolicyRows(policy));
renderNextTargetValue(calculatedNextTarget ?? directNextTarget ?? "-");
}
function syncLocalizedLinks() {
const nextParams = new URLSearchParams(params);
const token = readRawParam("token");
@ -776,6 +801,7 @@
syncPolicyLink();
renderProfile(currentProfile, messages);
renderAgencyProfile(currentAgencyProfile, messages);
renderDailyTargets();
}
document.querySelector(".language-button")?.addEventListener("click", (event) => {
@ -804,6 +830,20 @@
if (currentIdentity && shouldOpenJoinAgency(currentIdentity)) openJoinAgencyPage();
});
document.querySelector(".gift-value")?.addEventListener("click", () => {
setDailyModalOpen(true);
});
document.querySelectorAll("[data-close-daily]").forEach((node) => {
node.addEventListener("click", () => {
setDailyModalOpen(false);
});
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") setDailyModalOpen(false);
});
ensureAvatarFallback("Oscar");
applyLanguage(currentLang).then(async () => {
@ -818,8 +858,7 @@
fetchUserProfile().then(async (profile) => {
const memberId = profile?.id || profile?.account;
if (memberId) {
const memberWork = await fetchStreamingDuration(memberId);
fetchNextTargetValue(memberId, memberWork);
await fetchStreamingDuration(memberId);
}
});
fetchBankBalance();

View File

@ -698,6 +698,159 @@ a {
line-height: 1.2;
}
.daily-modal[hidden] {
display: none;
}
.daily-modal {
position: fixed;
z-index: 20;
inset: 0;
display: flex;
align-items: flex-end;
justify-content: center;
}
.daily-backdrop {
position: absolute;
inset: 0;
background: rgba(15, 21, 28, 0.38);
}
.daily-sheet {
position: relative;
width: min(430px, 100%);
max-height: 72vh;
overflow: hidden;
border-radius: 16px 16px 0 0;
background: #fff;
box-shadow: 0 -14px 34px rgba(23, 31, 42, 0.16);
}
.daily-sheet-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 58px;
padding: 16px 18px 12px;
border-bottom: 1px solid #eef0f2;
}
.daily-sheet-head h2 {
margin: 0;
color: #24282e;
font-size: 18px;
font-weight: 950;
line-height: 1.2;
}
.daily-close {
display: flex;
align-items: center;
justify-content: center;
width: 34px;
height: 34px;
border-radius: 50%;
background: #f4f6f7;
color: #50545b;
font-size: 25px;
font-weight: 500;
line-height: 1;
}
.daily-summary {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 13px 18px;
border-bottom: 1px solid #f0f2f3;
color: #8b8d92;
font-size: 14px;
font-weight: 850;
}
.daily-summary strong {
color: #24282e;
font-size: 20px;
font-weight: 950;
overflow-wrap: anywhere;
}
.daily-list {
display: grid;
gap: 10px;
max-height: calc(72vh - 116px);
overflow-y: auto;
padding: 14px 18px max(18px, env(safe-area-inset-bottom));
-webkit-overflow-scrolling: touch;
}
.daily-row {
display: grid;
gap: 10px;
padding: 12px;
border: 1px solid #eef0f2;
border-radius: 8px;
background: #fbfcfc;
}
.daily-date {
color: #24282e;
font-size: 15px;
font-weight: 950;
line-height: 1.2;
}
.daily-values {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
}
.daily-cell {
min-width: 0;
}
.daily-cell span {
display: block;
overflow: hidden;
color: #96989d;
font-size: 12px;
font-weight: 800;
line-height: 1.2;
text-overflow: ellipsis;
white-space: nowrap;
}
.daily-cell strong {
display: block;
margin-top: 4px;
overflow-wrap: anywhere;
color: #292d33;
font-size: 16px;
font-weight: 950;
line-height: 1.2;
}
.daily-empty {
display: flex;
align-items: center;
justify-content: center;
min-height: 92px;
border: 1px dashed #e5e8ea;
border-radius: 8px;
color: #8b8d92;
font-size: 14px;
font-weight: 850;
text-align: center;
}
.daily-modal-open {
overflow: hidden;
}
.home-indicator {
position: absolute;
left: 50%;
@ -755,6 +908,10 @@ a {
text-align: left;
}
[dir="rtl"] .daily-sheet {
direction: rtl;
}
@media (max-width: 360px) {
.status-bar {
padding-right: 22px;