feat(settlement, admin): introduce new types and functions for downline share and settlement period hints
Added new types for downline share breakdown and settlement period open hints to enhance the agent settlement API. Updated the admin console components to support these new features, improving the user experience with better data presentation and interaction. Additionally, refined the date range field to accommodate new calendar markers and hints, ensuring a more intuitive interface for managing settlement periods.
This commit is contained in:
@@ -52,9 +52,75 @@ export function formatAdminCalendarToday(locale: AdminApiLocale, weekdayLabel: s
|
||||
return `${datePart} ${weekdayLabel}`;
|
||||
}
|
||||
|
||||
const NAIVE_SCHEDULE_CLOCK_RE =
|
||||
/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
|
||||
|
||||
/** 浏览器本地时区短标签(如 CST、GMT+8),用于界面说明。 */
|
||||
export function getAdminBrowserTimeZoneLabel(date = new Date()): string {
|
||||
try {
|
||||
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
const parts = new Intl.DateTimeFormat(undefined, {
|
||||
timeZone,
|
||||
timeZoneName: "short",
|
||||
}).formatToParts(date);
|
||||
return parts.find((part) => part.type === "timeZoneName")?.value ?? timeZone;
|
||||
} catch {
|
||||
return "Local";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将接口 ISO 8601 时间转为本地时区的 `YYYY-MM-DD HH:mm:ss`(表单预填、期号展示)。
|
||||
*/
|
||||
export function isoToAdminLocalScheduleValue(
|
||||
iso: string | null | undefined,
|
||||
): string {
|
||||
if (iso == null || iso === "") {
|
||||
return "";
|
||||
}
|
||||
const ms = Date.parse(iso);
|
||||
if (Number.isNaN(ms)) {
|
||||
return "";
|
||||
}
|
||||
return formatParts(new Date(ms));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本地时区下的计划时刻转为指定排期时区(默认 UTC)的 naive `YYYY-MM-DD HH:mm:ss`,供创建/编辑期号 API。
|
||||
*/
|
||||
export function adminLocalScheduleValueToTimezoneNaive(
|
||||
clock: string,
|
||||
scheduleTimezone = "UTC",
|
||||
): string {
|
||||
const trimmed = clock.trim();
|
||||
if (trimmed === "") {
|
||||
return "";
|
||||
}
|
||||
const match = NAIVE_SCHEDULE_CLOCK_RE.exec(trimmed);
|
||||
if (!match) {
|
||||
return trimmed;
|
||||
}
|
||||
const [, y, mo, d, h, mi, s] = match;
|
||||
const localMs = new Date(
|
||||
Number(y),
|
||||
Number(mo) - 1,
|
||||
Number(d),
|
||||
Number(h),
|
||||
Number(mi),
|
||||
Number(s),
|
||||
).getTime();
|
||||
if (Number.isNaN(localMs)) {
|
||||
return trimmed;
|
||||
}
|
||||
try {
|
||||
return formatParts(new Date(localMs), scheduleTimezone);
|
||||
} catch {
|
||||
return trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将接口返回的 ISO 时间串格式化为浏览器本地时区下的 `YYYY-MM-DD HH:mm:ss`。
|
||||
* 期号相关列表请使用 {@link formatAdminInstantInTimeZone} 并传入 UTC。
|
||||
*/
|
||||
export function formatAdminInstant(
|
||||
iso: string | null | undefined,
|
||||
|
||||
Reference in New Issue
Block a user