Files
lotteryAdmin/src/modules/settlement/settlement-center-nav.ts
kang 0d984b00f0
Some checks failed
lotteryadmin CI / build (push) Has been cancelled
feat(admin): 仪表盘重构、代理线路修复与后台体验优化
- 各角色仪表盘:KPI 可点击跳转、快捷入口、去重冗余区块,代理/站点降级 analytics
- 代理线路:创建玩家权限、侧栏搜索、深链 URL、档案保存与删除预检等修复
- 统一密码最短 6 位;代理模块表格/侧栏背景色一致(admin-table-inset)
- 报表、钱包、对账、开奖、结算、配置等模块结构与 i18n 同步更新
2026-06-26 14:39:22 +08:00

115 lines
3.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { SettlementBillListScope } from "@/api/admin-agent-settlement";
export type SettlementPeriodView = "bills" | "ledger";
export type SettlementBillScopeFilter = "all" | SettlementBillListScope;
const VALID_VIEWS: SettlementPeriodView[] = ["bills", "ledger"];
const VALID_BILL_SCOPES: SettlementBillScopeFilter[] = [
"all",
"pending_confirm",
"awaiting_payment",
"settled",
"adjustment",
];
function parsePositiveInt(raw: string | null): number | null {
if (raw === null || raw === "") {
return null;
}
const value = Number(raw);
return Number.isInteger(value) && value > 0 ? value : null;
}
export function settlementCenterListHref(adminSiteId?: number | null): string {
return settlementCenterScopeHref(adminSiteId, "all");
}
/** 结算中心列表深链,可带账单筛选 scope待确认 / 待收付等)。 */
export function settlementCenterScopeHref(
adminSiteId?: number | null,
billScope: SettlementBillScopeFilter = "all",
): string {
const params = new URLSearchParams();
if (adminSiteId != null && adminSiteId > 0) {
params.set("site", String(adminSiteId));
}
if (billScope !== "all") {
params.set("scope", billScope);
}
const qs = params.toString();
return qs ? `/admin/settlement-center?${qs}` : "/admin/settlement-center";
}
export function settlementPeriodViewHref(
periodId: number,
view: SettlementPeriodView = "bills",
adminSiteId?: number | null,
billScope?: SettlementBillScopeFilter | null,
): string {
const params = new URLSearchParams({
period: String(periodId),
view,
});
if (adminSiteId != null && adminSiteId > 0) {
params.set("site", String(adminSiteId));
}
if (billScope != null && billScope !== "all") {
params.set("scope", billScope);
}
return `/admin/settlement-center?${params.toString()}`;
}
export function preferredBillScopeForPeriod(summary?: {
pending_confirm?: number;
awaiting_payment?: number;
}): SettlementBillScopeFilter {
const pending = summary?.pending_confirm ?? 0;
const awaiting = summary?.awaiting_payment ?? 0;
if (pending > 0) {
return "pending_confirm";
}
if (awaiting > 0) {
return "awaiting_payment";
}
return "all";
}
export function parseSettlementCenterView(
siteRaw: string | null,
periodRaw: string | null,
viewRaw: string | null,
scopeRaw?: string | null,
): {
siteId: number | null;
periodId: number | null;
view: SettlementPeriodView;
billScope: SettlementBillScopeFilter;
} {
const normalizedView =
viewRaw === "reports" || viewRaw === "operations" ? "bills" : viewRaw;
const view =
normalizedView !== null && VALID_VIEWS.includes(normalizedView as SettlementPeriodView)
? (normalizedView as SettlementPeriodView)
: "bills";
const billScope =
scopeRaw !== null &&
scopeRaw !== "" &&
VALID_BILL_SCOPES.includes(scopeRaw as SettlementBillScopeFilter)
? (scopeRaw as SettlementBillScopeFilter)
: "all";
return {
siteId: parsePositiveInt(siteRaw),
periodId: parsePositiveInt(periodRaw),
view,
billScope,
};
}
export function isSettlementPeriodView(value: string): value is SettlementPeriodView {
return VALID_VIEWS.includes(value as SettlementPeriodView);
}