fix bd center agency display

This commit is contained in:
zhx 2026-06-22 20:43:55 +08:00
parent 82f430c83d
commit 467b582ddd
3 changed files with 118 additions and 71 deletions

View File

@ -16,10 +16,7 @@
</head> </head>
<body> <body>
<div <div class="bd-center" aria-label="BD Center">
class="bd-center"
aria-label="BD Center"
>
<div class="hero-bg" aria-hidden="true"></div> <div class="hero-bg" aria-hidden="true"></div>
<nav class="title-bar"> <nav class="title-bar">
@ -170,7 +167,7 @@
aria-label="Month" aria-label="Month"
data-i18n-aria="bd_center.month" data-i18n-aria="bd_center.month"
> >
<span id="billMonthText">2026年06月</span> <span id="billMonthText">2026/06</span>
<svg viewBox="0 0 24 24" aria-hidden="true"> <svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M7 2v4M17 2v4" /> <path d="M7 2v4M17 2v4" />
<path <path
@ -182,7 +179,6 @@
</svg> </svg>
</button> </button>
</label> </label>
<div class="bill-range" id="billRange"></div>
</div> </div>
<div class="team-list-summary" id="teamListSummary"></div> <div class="team-list-summary" id="teamListSummary"></div>
</section> </section>

View File

@ -109,9 +109,9 @@
var date = monthDate(value); var date = monthDate(value);
return ( return (
String(date.getFullYear()) + String(date.getFullYear()) +
'' + '/' +
String(date.getMonth() + 1).padStart(2, '0') + String(date.getMonth() + 1).padStart(2, '0') +
'' ''
); );
} }
@ -168,7 +168,12 @@
function displayID(user, fallback) { function displayID(user, fallback) {
return ( return (
firstValue(user, ['display_user_id', 'displayUserID']) || firstValue(user, [
'short_id',
'shortId',
'display_user_id',
'displayUserID',
]) ||
firstValue(user, ['user_id', 'userId', 'id']) || firstValue(user, ['user_id', 'userId', 'id']) ||
fallback || fallback ||
'-' '-'
@ -177,8 +182,10 @@
function salaryAmount(salary) { function salaryAmount(salary) {
if (!salary) return 0; if (!salary) return 0;
if (salary.display_amount !== undefined) return Number(salary.display_amount); if (salary.display_amount !== undefined)
if (salary.displayAmount !== undefined) return Number(salary.displayAmount); return Number(salary.display_amount);
if (salary.displayAmount !== undefined)
return Number(salary.displayAmount);
if (salary.available_amount !== undefined) { if (salary.available_amount !== undefined) {
return Number(salary.available_amount || 0) / 100; return Number(salary.available_amount || 0) / 100;
} }
@ -236,24 +243,37 @@
} }
function normalizeProfile(payload) { function normalizeProfile(payload) {
var profile = payload && payload.profile ? payload.profile : payload || {}; var profile =
payload && payload.profile ? payload.profile : payload || {};
var name = displayName(profile, 'BD'); var name = displayName(profile, 'BD');
return { return {
name: name, name: name,
uid: displayID(profile), uid: displayID(profile),
avatar: firstValue(profile, ['avatar']) || avatarData(initial(name) || 'B', '#dbc8ff', '#7d57c7'), avatar:
firstValue(profile, ['avatar']) ||
avatarData(initial(name) || 'B', '#dbc8ff', '#7d57c7'),
}; };
} }
function normalizeAgencyItem(item) { function normalizeAgencyItem(item) {
var agency = (item && item.agency) || item || {}; var agency = (item && item.agency) || item || {};
var owner = (item && item.owner) || {}; var owner = (item && item.owner) || {};
// Agency 列表展示的是负责人维度;用户改昵称后应跟随 owner 最新资料agency.name 只作为旧数据兜底。
var name = var name =
displayName(owner, '') ||
firstValue(agency, ['name']) || firstValue(agency, ['name']) ||
displayName(owner, 'Agency ' + displayID(owner, displayID(agency))); 'Agency ' + displayID(owner, displayID(agency));
var account = var account =
firstValue(agency, ['agency_id', 'agencyId']) || displayID(owner, '') ||
displayID(owner, displayID(agency)); firstValue(agency, [
'short_id',
'shortId',
'display_user_id',
'displayUserID',
'agency_id',
'agencyId',
]) ||
'-';
return { return {
name: name, name: name,
account: account, account: account,
@ -261,8 +281,12 @@
firstValue(agency, ['avatar']) || firstValue(agency, ['avatar']) ||
firstValue(owner, ['avatar']) || firstValue(owner, ['avatar']) ||
avatarData(initial(name) || 'A', '#dbc8ff', '#7d57c7'), avatarData(initial(name) || 'A', '#dbc8ff', '#7d57c7'),
teamSalaryAmount: Number(firstValue(item, ['team_salary', 'teamSalary']) || 0), teamSalaryAmount: Number(
teamRechargeAmount: Number(firstValue(item, ['team_recharge', 'teamRecharge']) || 0), firstValue(item, ['team_salary', 'teamSalary']) || 0
),
teamRechargeAmount: Number(
firstValue(item, ['team_recharge', 'teamRecharge']) || 0
),
teamMemberCount: Number( teamMemberCount: Number(
firstValue(item, ['host_count', 'hostCount']) || firstValue(item, ['host_count', 'hostCount']) ||
firstValue(agency, ['host_count', 'hostCount']) || firstValue(agency, ['host_count', 'hostCount']) ||
@ -281,7 +305,10 @@
} }
function applyAgencies(payload) { function applyAgencies(payload) {
var items = payload && (payload.items || payload.agencies) ? payload.items || payload.agencies : []; var items =
payload && (payload.items || payload.agencies)
? payload.items || payload.agencies
: [];
var rows = items.map(normalizeAgencyItem); var rows = items.map(normalizeAgencyItem);
data.agencyBill.memberBillList = rows; data.agencyBill.memberBillList = rows;
data.agencyBill.agencyNumber = rows.length; data.agencyBill.agencyNumber = rows.length;
@ -305,7 +332,9 @@
id: String(userID), id: String(userID),
name: name, name: name,
account: account, account: account,
avatar: firstValue(user, ['avatar']) || avatarData(initial(name) || 'U', '#dbc8ff', '#7d57c7'), avatar:
firstValue(user, ['avatar']) ||
avatarData(initial(name) || 'U', '#dbc8ff', '#7d57c7'),
}; };
} }
@ -315,11 +344,7 @@
var profile = data.profile || {}; var profile = data.profile || {};
var loading = Boolean(state.loading); var loading = Boolean(state.loading);
setSkeleton($('profileName'), loading, profile.name || '-'); setSkeleton($('profileName'), loading, profile.name || '-');
setSkeleton( setSkeleton($('profileUID'), loading, 'UID: ' + (profile.uid || '-'));
$('profileUID'),
loading,
'UID: ' + (profile.uid || '-')
);
fallback.classList.toggle('avatar-skeleton', loading); fallback.classList.toggle('avatar-skeleton', loading);
if (loading) { if (loading) {
image.hidden = true; image.hidden = true;
@ -443,7 +468,6 @@
function renderTeamList() { function renderTeamList() {
var bill = data.agencyBill; var bill = data.agencyBill;
$('billMonthText').textContent = monthLabel(state.billMonth); $('billMonthText').textContent = monthLabel(state.billMonth);
$('billRange').textContent = state.billMonth.replace('-', '.');
if (state.loading) { if (state.loading) {
replaceChildren($('teamListSummary'), [ replaceChildren($('teamListSummary'), [
@ -536,10 +560,15 @@
} }
function statusLabel(status) { function statusLabel(status) {
if (status === 'success' || status === 'Success' || status === 'accepted') { if (
status === 'success' ||
status === 'Success' ||
status === 'accepted'
) {
return t('bd_center.success', 'Success'); return t('bd_center.success', 'Success');
} }
if (status === 'pending' || status === 'Pending') return t('bd_center.pending', 'Pending'); if (status === 'pending' || status === 'Pending')
return t('bd_center.pending', 'Pending');
return ''; return '';
} }
@ -555,15 +584,14 @@
function normalizeInvitationMessage(item) { function normalizeInvitationMessage(item) {
var invitation = (item && item.invitation) || item || {}; var invitation = (item && item.invitation) || item || {};
var inviter = (item && item.inviter) || {}; var inviter = (item && item.inviter) || {};
var id = String(invitation.invitation_id || invitation.invitationId || ''); var id = String(
invitation.invitation_id || invitation.invitationId || ''
);
var type = firstValue(invitation, [ var type = firstValue(invitation, [
'invitation_type', 'invitation_type',
'invitationType', 'invitationType',
]); ]);
var agencyName = firstValue(invitation, [ var agencyName = firstValue(invitation, ['agency_name', 'agencyName']);
'agency_name',
'agencyName',
]);
var inviterName = var inviterName =
displayName(inviter, '') || displayName(inviter, '') ||
firstValue(invitation, ['inviter_user_id', 'inviterUserId']) || firstValue(invitation, ['inviter_user_id', 'inviterUserId']) ||
@ -587,7 +615,10 @@
'{name} invited you to join {agency}' '{name} invited you to join {agency}'
) )
.replace('{name}', inviterName) .replace('{name}', inviterName)
.replace('{agency}', agencyName || t('bd_center.agency', 'Agency')); .replace(
'{agency}',
agencyName || t('bd_center.agency', 'Agency')
);
} }
if (type === 'agency') { if (type === 'agency') {
return t( return t(
@ -595,7 +626,10 @@
'{name} invited you to create agency {agency}' '{name} invited you to create agency {agency}'
) )
.replace('{name}', inviterName) .replace('{name}', inviterName)
.replace('{agency}', agencyName || t('bd_center.agency', 'Agency')); .replace(
'{agency}',
agencyName || t('bd_center.agency', 'Agency')
);
} }
if (type === 'bd') { if (type === 'bd') {
return t( return t(
@ -639,7 +673,9 @@
var badge = document.createElement('span'); var badge = document.createElement('span');
badge.className = badge.className =
'invite-badge ' + 'invite-badge ' +
(status === 'pending' || status === 'Pending' ? 'pending' : 'success'); (status === 'pending' || status === 'Pending'
? 'pending'
: 'success');
badge.textContent = statusLabel(status); badge.textContent = statusLabel(status);
side.appendChild(badge); side.appendChild(badge);
} else { } else {
@ -717,7 +753,12 @@
refuse.type = 'button'; refuse.type = 'button';
agree.disabled = Boolean(state.processingMessages[message.id]); agree.disabled = Boolean(state.processingMessages[message.id]);
refuse.disabled = Boolean(state.processingMessages[message.id]); refuse.disabled = Boolean(state.processingMessages[message.id]);
renderImageAvatar(avatar, message.avatar, message.name, 'message-fallback'); renderImageAvatar(
avatar,
message.avatar,
message.name,
'message-fallback'
);
title.textContent = message.title; title.textContent = message.title;
meta.textContent = message.account ? 'ID: ' + message.account : ''; meta.textContent = message.account ? 'ID: ' + message.account : '';
agree.textContent = t('bd_center.agree', 'Agree'); agree.textContent = t('bd_center.agree', 'Agree');
@ -800,7 +841,10 @@
.catch(function (error) { .catch(function (error) {
state.inviteStatus = state.inviteStatus =
(error && error.message) || (error && error.message) ||
t('bd_center.search_failed', 'Search failed. Try again later.'); t(
'bd_center.search_failed',
'Search failed. Try again later.'
);
state.inviteStatusType = 'error'; state.inviteStatusType = 'error';
state.searched = []; state.searched = [];
renderInviteModal(); renderInviteModal();
@ -850,7 +894,10 @@
.catch(function (error) { .catch(function (error) {
state.inviteStatus = state.inviteStatus =
(error && error.message) || (error && error.message) ||
t('bd_center.invite_failed', 'Invite failed. Try again later.'); t(
'bd_center.invite_failed',
'Invite failed. Try again later.'
);
state.inviteStatusType = 'error'; state.inviteStatusType = 'error';
renderInviteModal(); renderInviteModal();
}) })
@ -871,10 +918,7 @@
} }
function loadRoleInvitations() { function loadRoleInvitations() {
if ( if (!api().roleInvitations || !api().roleInvitations.list) {
!api().roleInvitations ||
!api().roleInvitations.list
) {
state.messages = []; state.messages = [];
renderMessages(); renderMessages();
return Promise.resolve(false); return Promise.resolve(false);
@ -977,29 +1021,31 @@
) { ) {
setLoading(false); setLoading(false);
return Promise.reject( return Promise.reject(
new Error(t('bd_center.api_not_ready', 'API module is not ready.')) new Error(
t('bd_center.api_not_ready', 'API module is not ready.')
)
); );
} }
return Promise.all([ return Promise.all([service.overview(), service.agencies(50)])
service.overview(), .then(function (results) {
service.agencies(50), applyOverview(results[0] || {});
]).then(function (results) { applyAgencies(results[1] || {});
applyOverview(results[0] || {}); return true;
applyAgencies(results[1] || {}); })
return true; .catch(function (error) {
}).catch(function (error) { data.profile = null;
data.profile = null; data.balance = { available: 0 };
data.balance = { available: 0 }; data.agencyBill = {
data.agencyBill = { agencyNumber: 0,
agencyNumber: 0, totalSalary: 0,
totalSalary: 0, totalRecharge: 0,
totalRecharge: 0, memberBillList: [],
memberBillList: [], };
}; throw error;
throw error; })
}).finally(function () { .finally(function () {
setLoading(false); setLoading(false);
}); });
} }
function bindEvents() { function bindEvents() {
@ -1052,12 +1098,17 @@
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
render(); render();
bindEvents(); bindEvents();
loadRealData().catch(function (error) { loadRealData()
toast( .catch(function (error) {
(error && error.message) || toast(
t('bd_center.load_failed', 'Load failed. Try again later.') (error && error.message) ||
); t(
}).finally(loadRoleInvitations); 'bd_center.load_failed',
'Load failed. Try again later.'
)
);
})
.finally(loadRoleInvitations);
if (window.HyAppBridge) { if (window.HyAppBridge) {
window.HyAppBridge.ready({ window.HyAppBridge.ready({
page: 'bd-center', page: 'bd-center',

View File

@ -84,7 +84,7 @@
.team-list-period { .team-list-period {
display: grid; display: grid;
grid-template-columns: minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
align-items: center; align-items: center;
gap: 10px; gap: 10px;
} }