- 将教练页面中的“Bot”名称更改为“Seal”,提升品牌一致性 - 在布局文件中调整标签标题和图标,确保与新名称一致 - 新增使用次数显示功能,优化用户对使用情况的了解 - 更新日期选择器样式,增强未来日期的禁用效果 - 优化压力分析模态框的颜色和文本,提升可读性
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import dayjs, { Dayjs } from 'dayjs';
|
||
import 'dayjs/locale/zh-cn';
|
||
|
||
dayjs.locale('zh-cn');
|
||
|
||
/**
|
||
* 返回基于当前时间的中文问候语:早上好 / 下午好 / 晚上好
|
||
* - 早上:05:00 - 11:59
|
||
* - 下午:12:00 - 17:59
|
||
* - 晚上:18:00 - 04:59
|
||
*/
|
||
export function getChineseGreeting(now: Date = new Date()): string {
|
||
const hour = now.getHours();
|
||
|
||
if (hour >= 5 && hour < 12) {
|
||
return '早上好';
|
||
}
|
||
if (hour >= 12 && hour < 18) {
|
||
return '下午好';
|
||
}
|
||
return '晚上好';
|
||
}
|
||
|
||
/** 获取中文月份标题,例如:2025年8月 */
|
||
export function getMonthTitleZh(date: Dayjs = dayjs()): string {
|
||
return date.format('YY年M月');
|
||
}
|
||
|
||
export type MonthDay = {
|
||
/** 中文星期:日/一/二/三/四/五/六 */
|
||
weekdayZh: string;
|
||
/** 简化的星期,用于显示 */
|
||
dayAbbr: string;
|
||
/** 月内第几日(1-31) */
|
||
dayOfMonth: number;
|
||
/** 对应的 dayjs 对象 */
|
||
date: Dayjs;
|
||
/** 是否是今天 */
|
||
isToday: boolean;
|
||
};
|
||
|
||
/** 获取某月的所有日期(中文星期+日号) */
|
||
export function getMonthDaysZh(date: Dayjs = dayjs()): MonthDay[] {
|
||
const year = date.year();
|
||
const monthIndex = date.month();
|
||
const daysInMonth = date.daysInMonth();
|
||
const zhWeek = ['日', '一', '二', '三', '四', '五', '六'];
|
||
const today = dayjs();
|
||
|
||
return Array.from({ length: daysInMonth }, (_, i) => {
|
||
const d = dayjs(new Date(year, monthIndex, i + 1));
|
||
const isToday = d.isSame(today, 'day');
|
||
|
||
return {
|
||
weekdayZh: zhWeek[d.day()],
|
||
dayAbbr: zhWeek[d.day()],
|
||
dayOfMonth: i + 1,
|
||
date: d,
|
||
isToday,
|
||
};
|
||
});
|
||
}
|
||
|
||
/** 获取“今天”在当月的索引(0 基) */
|
||
export function getTodayIndexInMonth(date: Dayjs = dayjs()): number {
|
||
return date.date() - 1;
|
||
}
|
||
|
||
|