UNPKG

@alauda-fe/common

Version:

Alauda frontend team common codes.

123 lines (122 loc) 5.2 kB
/** * @packageDocumentation * @module translate */ import { ChangeDetectorRef, OnDestroy, PipeTransform } from '@angular/core'; import { Subject } from 'rxjs'; import { TranslateService } from './translate.service'; import * as i0 from "@angular/core"; /** * 基础国际化格式化 Pipe 抽象类 * 提供响应式的 locale 变化监听功能 */ declare abstract class BaseIntlPipe implements PipeTransform, OnDestroy { protected readonly destroy$$: Subject<void>; protected readonly cdr: ChangeDetectorRef; protected readonly translate: TranslateService; constructor(); ngOnDestroy(): void; abstract transform(value: any, ...args: any[]): string; static ɵfac: i0.ɵɵFactoryDeclaration<BaseIntlPipe, never>; static ɵprov: i0.ɵɵInjectableDeclaration<BaseIntlPipe>; } /** * 数字格式化 Pipe * @example * {{ 1234.56 | aclIntlNumber }} // "1,234.56" * {{ 0.85 | aclIntlNumber:{ style: 'percent' } }} // "85%" * {{ 1234.56 | aclIntlNumber:{ minimumFractionDigits: 2 } }} // "1,234.56" */ export declare class IntlNumberPipe extends BaseIntlPipe implements PipeTransform { transform(value: number, options?: Intl.NumberFormatOptions): string; static ɵfac: i0.ɵɵFactoryDeclaration<IntlNumberPipe, never>; static ɵpipe: i0.ɵɵPipeDeclaration<IntlNumberPipe, "aclIntlNumber", true>; } /** * 货币格式化 Pipe * @example * {{ 1234.56 | aclIntlCurrency }} // "¥1,234.56" * {{ 1234.56 | aclIntlCurrency:'USD' }} // "$1,234.56" * {{ 1234.56 | aclIntlCurrency:'EUR':{ minimumFractionDigits: 2 } }} // "€1,234.56" */ export declare class IntlCurrencyPipe extends BaseIntlPipe implements PipeTransform { transform(value: number, currency?: string, options?: Intl.NumberFormatOptions): string; static ɵfac: i0.ɵɵFactoryDeclaration<IntlCurrencyPipe, never>; static ɵpipe: i0.ɵɵPipeDeclaration<IntlCurrencyPipe, "aclIntlCurrency", true>; } /** * 百分比格式化 Pipe * @example * {{ 0.85 | aclIntlPercent }} // "85%" * {{ 0.8567 | aclIntlPercent:{ minimumFractionDigits: 2 } }} // "85.67%" */ export declare class IntlPercentPipe extends BaseIntlPipe implements PipeTransform { transform(value: number, options?: Omit<Intl.NumberFormatOptions, 'style'>): string; static ɵfac: i0.ɵɵFactoryDeclaration<IntlPercentPipe, never>; static ɵpipe: i0.ɵɵPipeDeclaration<IntlPercentPipe, "aclIntlPercent", true>; } /** * 日期格式化 Pipe * @example * {{ date | aclIntlDate }} // "2025/01/01" * {{ date | aclIntlDate:{ dateStyle: 'long' } }} // "2025年1月1日" * {{ date | aclIntlDate:{ year: 'numeric', month: 'long' } }} // "2025年1月" */ export declare class IntlDatePipe extends BaseIntlPipe implements PipeTransform { transform(value: Date | string | number, options?: Intl.DateTimeFormatOptions): string; static ɵfac: i0.ɵɵFactoryDeclaration<IntlDatePipe, never>; static ɵpipe: i0.ɵɵPipeDeclaration<IntlDatePipe, "aclIntlDate", true>; } /** * 日期时间格式化 Pipe * @example * {{ date | aclIntlDateTime }} // "2025/01/01 14:30:00" * {{ date | aclIntlDateTime:{ dateStyle: 'medium', timeStyle: 'short' } }} // "2025年1月1日 14:30" */ export declare class IntlDateTimePipe extends BaseIntlPipe implements PipeTransform { transform(value: Date | string | number, options?: Intl.DateTimeFormatOptions): string; static ɵfac: i0.ɵɵFactoryDeclaration<IntlDateTimePipe, never>; static ɵpipe: i0.ɵɵPipeDeclaration<IntlDateTimePipe, "aclIntlDateTime", true>; } /** * 相对时间格式化 Pipe * 支持两种使用方式: * 1. 传入 Date 对象,自动计算相对时间 * 2. 传入数值和单位,手动指定相对时间 * * 特性: * - 自动刷新UI:根据时间距离智能调整刷新频率 * - 性能优化:共享定时器,避免大量单独计时器 * - 响应式设计:监听语言变化自动更新 * * @example * // 自动计算 * {{ pastDate | aclIntlRelativeTime }} // "2 hours ago" * {{ futureDate | aclIntlRelativeTime:{ numeric: 'always' } }} // "in 2 hours" * * // 手动指定 * {{ -1 | aclIntlRelativeTime:'day' }} // "yesterday" * {{ 2 | aclIntlRelativeTime:'hour':{ numeric: 'always' } }} // "in 2 hours" * {{ -30 | aclIntlRelativeTime:'minute':{ numeric: 'always' } }} // "30 minutes ago" */ export declare class IntlRelativeTimePipe extends BaseIntlPipe implements PipeTransform, OnDestroy { private readonly relativeTimeManager; private currentInterval?; private refreshSubscription?; private currentValue?; ngOnDestroy(): void; transform(value: Date | number, unitOrOptions?: Intl.RelativeTimeFormatUnit | Intl.RelativeTimeFormatOptions, options?: Intl.RelativeTimeFormatOptions): string; /** * 设置自动刷新机制 * 使用共享的计时器管理器,提高多实例场景下的性能 * 时间间隔大于一天时不设置自动刷新 */ private setupAutoRefresh; /** * 清理刷新相关资源 */ private cleanupRefresh; static ɵfac: i0.ɵɵFactoryDeclaration<IntlRelativeTimePipe, never>; static ɵpipe: i0.ɵɵPipeDeclaration<IntlRelativeTimePipe, "aclIntlRelativeTime", true>; } export {};