同步:完善质量分析工作台并更新主题字体
同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。 补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。 统一午夜黑及其他主题的控件细节、中文和业务数字字体。 排除本地业务数据、凭据、预览、发布与验收产物。 验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
export type AnalysisPeriod = {
|
||||
year?: number;
|
||||
month?: number;
|
||||
quarter?: number;
|
||||
monthStart?: number;
|
||||
monthEnd?: number;
|
||||
};
|
||||
|
||||
type Row = Record<string, unknown>;
|
||||
const record = (value: unknown): Row => value && typeof value === 'object' && !Array.isArray(value) ? value as Row : {};
|
||||
const present = (value: unknown) => value !== undefined && value !== null && value !== '';
|
||||
|
||||
/** Parse the numeric part of an analysis period without coercing strings. Other
|
||||
* legacy display fields (label/start/end) are intentionally left to callers. */
|
||||
export function parseAnalysisPeriod(value: unknown, minYear = 1900, maxYear = 2200): AnalysisPeriod | null {
|
||||
const raw = record(value);
|
||||
const year = raw.year, month = raw.month, quarter = raw.quarter;
|
||||
const monthStart = raw.monthStart, monthEnd = raw.monthEnd;
|
||||
const hasMonth = present(month), hasQuarter = present(quarter);
|
||||
const hasMonthStart = present(monthStart), hasMonthEnd = present(monthEnd);
|
||||
if (!present(raw.year) && (hasMonth || hasQuarter || hasMonthStart || hasMonthEnd)) return null;
|
||||
if (present(raw.year) && (!Number.isInteger(year) || Number(year) < minYear || Number(year) > maxYear)) return null;
|
||||
if (hasMonth && (!Number.isInteger(month) || Number(month) < 1 || Number(month) > 12)) return null;
|
||||
if (hasQuarter && (!Number.isInteger(quarter) || Number(quarter) < 1 || Number(quarter) > 4)) return null;
|
||||
if (hasMonthStart !== hasMonthEnd) return null;
|
||||
if (hasMonthStart && (!Number.isInteger(monthStart) || Number(monthStart) < 1 || Number(monthStart) > 12
|
||||
|| !Number.isInteger(monthEnd) || Number(monthEnd) < 1 || Number(monthEnd) > 12 || Number(monthStart) > Number(monthEnd))) return null;
|
||||
if ([hasMonth, hasQuarter, hasMonthStart].filter(Boolean).length > 1) return null;
|
||||
return {
|
||||
...(present(year) ? { year: Number(year) } : {}),
|
||||
...(hasMonth ? { month: Number(month) } : {}),
|
||||
...(hasQuarter ? { quarter: Number(quarter) } : {}),
|
||||
...(hasMonthStart ? { monthStart: Number(monthStart), monthEnd: Number(monthEnd) } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function hasAnalysisPeriodFields(value: unknown): boolean {
|
||||
const raw = record(value);
|
||||
return ['year', 'month', 'quarter', 'monthStart', 'monthEnd'].some(key => present(raw[key]));
|
||||
}
|
||||
|
||||
export function isValidAnalysisPeriodContext(value: unknown, minYear = 1900, maxYear = 2200): boolean {
|
||||
return parseAnalysisPeriod(value, minYear, maxYear) !== null;
|
||||
}
|
||||
|
||||
export function analysisPeriodLabel(value: unknown, minYear = 1900, maxYear = 2200): string {
|
||||
const period = parseAnalysisPeriod(value, minYear, maxYear);
|
||||
if (!period?.year) return '';
|
||||
if (period.monthStart !== undefined && period.monthEnd !== undefined) {
|
||||
return period.monthStart === period.monthEnd
|
||||
? `${period.year}年${period.monthStart}月`
|
||||
: `${period.year}年${period.monthStart}—${period.monthEnd}月`;
|
||||
}
|
||||
if (period.month !== undefined) return `${period.year}年${period.month}月`;
|
||||
if (period.quarter !== undefined) return `${period.year}年第${period.quarter}季度`;
|
||||
return `${period.year}年`;
|
||||
}
|
||||
Reference in New Issue
Block a user