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