Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 234ae9213f |
@@ -137,6 +137,11 @@ const slotRateMean = (rows: CouponSlotRow[]): number | null => {
|
||||
return rates.length ? rates.reduce((a, b) => a + b, 0) / rates.length : null;
|
||||
};
|
||||
|
||||
// 汇总卡成功率口径 tooltip 文案
|
||||
const POINT_RATE_HINT =
|
||||
'点位成功率(合计):当前区间内全部券成功率的算术平均(每张券等权);' +
|
||||
'单券成功率=成功(含已领)÷尝试(不含跳过),源自领券每券记录。';
|
||||
|
||||
// 按券表:coupon_id 平台 → 中文
|
||||
const SLOT_PLATFORM: Record<string, string> = {
|
||||
'meituan-waimai': '美团',
|
||||
@@ -592,10 +597,6 @@ export default function CouponDataPage() {
|
||||
const successDenominator = summary ? Math.max(0, summary.started_count - abandonedCount) : 0;
|
||||
const couponSuccessRate =
|
||||
summary && successDenominator > 0 ? summary.completed_count / successDenominator : null;
|
||||
const validCouponSlots = couponSlots.filter((r) => r.success_rate != null);
|
||||
const pointSuccessRate = slotRateMean(validCouponSlots);
|
||||
const pointSucceededTotal = validCouponSlots.reduce((total, r) => total + r.succeeded, 0);
|
||||
const pointTriedTotal = validCouponSlots.reduce((total, r) => total + r.tried, 0);
|
||||
const items = data?.items ?? [];
|
||||
|
||||
return (
|
||||
@@ -713,19 +714,8 @@ export default function CouponDataPage() {
|
||||
<Statistic
|
||||
title={
|
||||
<span>
|
||||
领券完成率{' '}
|
||||
<Tooltip
|
||||
overlayStyle={{ maxWidth: 520 }}
|
||||
title={
|
||||
<div>
|
||||
<div>计算逻辑:领券完成数 ÷(领券发起数-中途退出数)</div>
|
||||
<div style={{ marginTop: 6 }}>
|
||||
本期:{summary.completed_count} ÷({summary.started_count}-{abandonedCount})
|
||||
= {fmtPct(couponSuccessRate)}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
领券成功率{' '}
|
||||
<Tooltip title="领券完成数 ÷(领券发起数-中途退出数)">
|
||||
<InfoCircleOutlined style={{ color: '#999' }} />
|
||||
</Tooltip>
|
||||
</span>
|
||||
@@ -738,33 +728,12 @@ export default function CouponDataPage() {
|
||||
title={
|
||||
<span>
|
||||
点位成功率{' '}
|
||||
<Tooltip
|
||||
overlayStyle={{ maxWidth: 560 }}
|
||||
title={
|
||||
<div>
|
||||
<div>计算逻辑:全部单券成功率的算术平均,每张券等权。</div>
|
||||
<div>单券成功率=成功数(含已领)÷ 尝试数(不含跳过)。</div>
|
||||
<div style={{ marginTop: 6 }}>
|
||||
本期共 {validCouponSlots.length} 张有效券:
|
||||
</div>
|
||||
{validCouponSlots.map((slot) => (
|
||||
<div key={slot.coupon_id}>
|
||||
{slot.coupon_name || slot.coupon_id}:{slot.succeeded} ÷ {slot.tried}=
|
||||
{fmtPct(slot.success_rate)}
|
||||
</div>
|
||||
))}
|
||||
<div style={{ marginTop: 6 }}>
|
||||
等权平均={fmtPct(pointSuccessRate)};累计成功/尝试=
|
||||
{pointSucceededTotal}/{pointTriedTotal}(累计数仅辅助核对,不作为当前加权公式)。
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Tooltip title={POINT_RATE_HINT}>
|
||||
<InfoCircleOutlined style={{ color: '#999' }} />
|
||||
</Tooltip>
|
||||
</span>
|
||||
}
|
||||
value={fmtPct(pointSuccessRate)}
|
||||
value={fmtPct(slotRateMean(couponSlots))}
|
||||
/>
|
||||
</Col>
|
||||
<Col flex="1 1 0">
|
||||
|
||||
@@ -20,7 +20,6 @@ import type { Dayjs } from 'dayjs';
|
||||
import { api } from '@/lib/api';
|
||||
import { canDo } from '@/lib/auth';
|
||||
import { formatWallTime } from '@/lib/format';
|
||||
import { refreshReviewBadge } from '@/lib/reviewBadge';
|
||||
import { usePagedList } from '@/lib/usePagedList';
|
||||
import type { Feedback, FeedbackSummary } from '@/lib/types';
|
||||
import FeedbackHandleDrawer from './FeedbackHandleDrawer';
|
||||
@@ -432,11 +431,7 @@ export default function FeedbacksPage() {
|
||||
feedback={drawerFb}
|
||||
open={drawerOpen}
|
||||
onClose={() => setDrawerOpen(false)}
|
||||
onDone={() => {
|
||||
reload();
|
||||
loadSummary();
|
||||
refreshReviewBadge('/feedbacks');
|
||||
}}
|
||||
onDone={() => { reload(); loadSummary(); }}
|
||||
/>
|
||||
|
||||
<UserRecordsDrawer<Feedback>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { usePathname, useRouter } from 'next/navigation';
|
||||
import {
|
||||
BarChartOutlined,
|
||||
@@ -25,16 +25,7 @@ import {
|
||||
import { Avatar, Dropdown, Layout, Tooltip } from 'antd';
|
||||
import { api } from '@/lib/api';
|
||||
import { clearAuth, getAdmin, getToken, setAuth } from '@/lib/auth';
|
||||
import {
|
||||
REVIEW_BADGE_REFRESH_EVENT,
|
||||
type ReviewBadgeKey,
|
||||
} from '@/lib/reviewBadge';
|
||||
import type {
|
||||
AdminInfo,
|
||||
FeedbackSummary,
|
||||
PriceReportSummary,
|
||||
WithdrawSummary,
|
||||
} from '@/lib/types';
|
||||
import type { AdminInfo } from '@/lib/types';
|
||||
|
||||
const { Sider, Header, Content } = Layout;
|
||||
|
||||
@@ -105,8 +96,6 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
const pathname = usePathname();
|
||||
const [admin, setAdmin] = useState<AdminInfo | null>(null);
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [pendingReviewCounts, setPendingReviewCounts] = useState<Partial<Record<ReviewBadgeKey, number>>>({});
|
||||
const reviewRefreshVersion = useRef<Partial<Record<ReviewBadgeKey, number>>>({});
|
||||
|
||||
useEffect(() => {
|
||||
const token = getToken();
|
||||
@@ -125,44 +114,6 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
.catch(() => {});
|
||||
}, [router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!admin) return;
|
||||
const canAccess = (page: string) =>
|
||||
admin.role === 'super_admin' || !admin.pages || admin.pages.includes(page);
|
||||
|
||||
const refresh = async (key: ReviewBadgeKey) => {
|
||||
if (!canAccess(key.slice(1))) return;
|
||||
const version = (reviewRefreshVersion.current[key] ?? 0) + 1;
|
||||
reviewRefreshVersion.current[key] = version;
|
||||
let count: number;
|
||||
if (key === '/withdraws') {
|
||||
count = (await api.get<WithdrawSummary>('/admin/api/withdraws/summary')).data.reviewing_count;
|
||||
} else if (key === '/price-reports') {
|
||||
count = (await api.get<PriceReportSummary>('/admin/api/price-reports/summary')).data.pending;
|
||||
} else {
|
||||
count = (await api.get<FeedbackSummary>('/admin/api/feedbacks/summary')).data.pending;
|
||||
}
|
||||
if (reviewRefreshVersion.current[key] !== version) return;
|
||||
setPendingReviewCounts((current) => ({ ...current, [key]: count }));
|
||||
};
|
||||
|
||||
const refreshSafely = (key: ReviewBadgeKey) => refresh(key).catch(() => {});
|
||||
void Promise.all([
|
||||
refreshSafely('/withdraws'),
|
||||
refreshSafely('/price-reports'),
|
||||
refreshSafely('/feedbacks'),
|
||||
]);
|
||||
|
||||
const onReviewCompleted = (event: Event) => {
|
||||
const key = (event as CustomEvent<ReviewBadgeKey>).detail;
|
||||
if (key) void refreshSafely(key);
|
||||
};
|
||||
window.addEventListener(REVIEW_BADGE_REFRESH_EVENT, onReviewCompleted);
|
||||
return () => {
|
||||
window.removeEventListener(REVIEW_BADGE_REFRESH_EVENT, onReviewCompleted);
|
||||
};
|
||||
}, [admin]);
|
||||
|
||||
if (!admin) return null; // 守卫期间不闪烁内容
|
||||
|
||||
// 选中态:取路径一级(/users/123 -> /users)
|
||||
@@ -181,20 +132,6 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
hasChildren(group) ? group.children : [group],
|
||||
);
|
||||
|
||||
const reviewBadge = (key: string) => {
|
||||
const count = pendingReviewCounts[key as ReviewBadgeKey] ?? 0;
|
||||
if (count <= 0) return null;
|
||||
return (
|
||||
<span
|
||||
className="nav-review-badge"
|
||||
aria-label={`${count} 条未审核`}
|
||||
title={`${count} 条未审核`}
|
||||
>
|
||||
{count}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
const logout = () => {
|
||||
clearAuth();
|
||||
router.replace('/login');
|
||||
@@ -229,7 +166,6 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
aria-label={item.label}
|
||||
>
|
||||
{item.icon}
|
||||
{reviewBadge(item.key)}
|
||||
</button>
|
||||
</Tooltip>
|
||||
))
|
||||
@@ -247,8 +183,7 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
onClick={() => router.push(group.key)}
|
||||
>
|
||||
<span className="nav-primary-icon">{group.icon}</span>
|
||||
<span className="nav-item-label">{group.label}</span>
|
||||
{reviewBadge(group.key)}
|
||||
<span>{group.label}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -267,8 +202,7 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
onClick={() => router.push(child.key)}
|
||||
>
|
||||
<span className="nav-child-icon">{child.icon}</span>
|
||||
<span className="nav-item-label">{child.label}</span>
|
||||
{reviewBadge(child.key)}
|
||||
<span>{child.label}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -335,29 +269,6 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
font-size: 16px;
|
||||
}
|
||||
.nav-item-label {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
.nav-review-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
flex: 0 0 auto;
|
||||
min-width: 18px;
|
||||
height: 18px;
|
||||
padding: 0 5px;
|
||||
border-radius: 9px;
|
||||
background: #ff4d4f;
|
||||
color: #fff;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
line-height: 18px;
|
||||
white-space: nowrap;
|
||||
font-variant-numeric: tabular-nums;
|
||||
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
.nav-direct,
|
||||
.nav-child,
|
||||
.nav-icon-button {
|
||||
@@ -421,7 +332,6 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
padding: 0 8px 14px;
|
||||
}
|
||||
.nav-icon-button {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -432,11 +342,6 @@ export default function MainLayout({ children }: { children: React.ReactNode })
|
||||
color: rgba(255, 255, 255, 0.72);
|
||||
font-size: 17px;
|
||||
}
|
||||
.nav-icon-button .nav-review-badge {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
right: -6px;
|
||||
}
|
||||
.nav-icon-button:hover,
|
||||
.nav-icon-button.is-selected {
|
||||
background: #1677ff;
|
||||
|
||||
@@ -22,7 +22,6 @@ import dayjs from 'dayjs';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
import { canDo } from '@/lib/auth';
|
||||
import { mediaUrl } from '@/lib/media';
|
||||
import { refreshReviewBadge } from '@/lib/reviewBadge';
|
||||
import { usePagedList } from '@/lib/usePagedList';
|
||||
import type { PriceReport, PriceReportSummary } from '@/lib/types';
|
||||
import UserRecordsDrawer from '@/components/UserRecordsDrawer';
|
||||
@@ -203,7 +202,6 @@ export default function PriceReportsPage() {
|
||||
onOk: async () => {
|
||||
try {
|
||||
await api.post(`/admin/api/price-reports/${r.id}/approve`);
|
||||
refreshReviewBadge('/price-reports');
|
||||
message.success('已通过,已发放 1000 金币');
|
||||
refreshAfterChange();
|
||||
} catch (e) {
|
||||
@@ -222,7 +220,6 @@ export default function PriceReportsPage() {
|
||||
}
|
||||
try {
|
||||
await api.post(`/admin/api/price-reports/${rejecting.id}/reject`, { reason });
|
||||
refreshReviewBadge('/price-reports');
|
||||
message.success('已拒绝');
|
||||
setRejecting(null);
|
||||
setRejectReason('');
|
||||
|
||||
@@ -39,7 +39,6 @@ import dayjs, { type Dayjs } from 'dayjs';
|
||||
import { api, errMsg } from '@/lib/api';
|
||||
import { canDo } from '@/lib/auth';
|
||||
import { formatUtcTime, utcDayjs, utcFromNow, yuan } from '@/lib/format';
|
||||
import { refreshReviewBadge } from '@/lib/reviewBadge';
|
||||
import { usePagedList } from '@/lib/usePagedList';
|
||||
import type {
|
||||
AuditLog,
|
||||
@@ -333,7 +332,6 @@ export default function WithdrawsPage() {
|
||||
onOk: async () => {
|
||||
try {
|
||||
await api.post(`/admin/api/withdraws/${o.out_bill_no}/approve`);
|
||||
refreshReviewBadge('/withdraws');
|
||||
message.success('已通过审核并发起打款');
|
||||
await refreshAfterChange(o.out_bill_no);
|
||||
} catch (e) {
|
||||
@@ -364,7 +362,6 @@ export default function WithdrawsPage() {
|
||||
await api.post(`/admin/api/withdraws/${targets[0].out_bill_no}/reject`, { reason: trimmed });
|
||||
message.success('已拒绝并退回余额');
|
||||
}
|
||||
refreshReviewBadge('/withdraws');
|
||||
setRejecting(null);
|
||||
setBulkRejecting([]);
|
||||
setRejectReason('');
|
||||
@@ -403,7 +400,6 @@ export default function WithdrawsPage() {
|
||||
const { data } = await api.post<WithdrawBulkResult>('/admin/api/withdraws/bulk/approve', {
|
||||
out_bill_nos: selectedReviewing.map((item) => item.out_bill_no),
|
||||
});
|
||||
refreshReviewBadge('/withdraws');
|
||||
const text = bulkResultText('批量通过完成', data);
|
||||
if (data.failed) message.warning(text);
|
||||
else message.success(text);
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
export type ReviewBadgeKey = '/withdraws' | '/price-reports' | '/feedbacks';
|
||||
|
||||
export const REVIEW_BADGE_REFRESH_EVENT = 'review-badge-refresh';
|
||||
|
||||
export function refreshReviewBadge(key: ReviewBadgeKey) {
|
||||
if (typeof window === 'undefined') return;
|
||||
window.dispatchEvent(
|
||||
new CustomEvent<ReviewBadgeKey>(REVIEW_BADGE_REFRESH_EVENT, { detail: key }),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user