update 历史聊天妹子页

This commit is contained in:
2025-09-20 16:05:57 +08:00
parent 62cad1ca15
commit dbbbcc8403
8 changed files with 6363 additions and 8 deletions
+65 -2
View File
@@ -120,6 +120,20 @@ export default class Utils {
return str;
}
/**
* 字符串左侧填充到指定长度
* @param str 要填充的字符串
* @param length 目标长度
* @param padChar 填充字符,默认为 "0"
* @returns 填充后的字符串
*/
static padStart(str: string, length: number, padChar: string = "0"): string {
while (str.length < length) {
str = padChar + str;
}
return str;
}
/**截取字符串,超过长度的用...代替
* @param str 要处理的字符串
* @param labelLimit 字符串长度限制
@@ -367,13 +381,62 @@ export default class Utils {
const days = Math.floor(diffSeconds / (60 * 60 * 24));
const hours = Math.floor((diffSeconds % (60 * 60 * 24)) / 3600);
const minutes = Math.floor((diffSeconds % 3600) / 60);
console.log("vip失效剩余时间差(秒):", diffSeconds, "天:", days, "小时:", hours, "分钟:", minutes);
console.log(
"vip失效剩余时间差(秒):",
diffSeconds,
"天:",
days,
"小时:",
hours,
"分钟:",
minutes
);
if (days > 0) {
return `${days}${LanguageUtils.getText("purchasepanel.day")}`;
}
if (hours > 0) {
return `${hours}${LanguageUtils.getText("purchasepanel.hour")}:${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
return `${hours}${LanguageUtils.getText(
"purchasepanel.hour"
)}:${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
}
return `${minutes}${LanguageUtils.getText("purchasepanel.minute")}`;
}
/**
* 格式化聊天时间显示
* @param timestamp 时间戳(毫秒),如果为null则显示"暂无聊天记录"
* @returns 格式化的时间字符串
* 格式规则:
* - 一日内:显示时和分(HH:mm)
* - 一周内:显示x天前
* - 一个月内:显示x周前
* - 一个月以上:显示"一个月以上"
*/
public static formatChatTime(timestamp: number | null): string {
if (!timestamp) {
return "暂无聊天记录";
}
const now = new Date();
const chatDate = new Date(timestamp);
const diffMs = now.getTime() - chatDate.getTime();
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
if (diffDays === 0) {
// 一日内:显示时和分
const hours = Utils.padStart(chatDate.getHours().toString(), 2);
const minutes = Utils.padStart(chatDate.getMinutes().toString(), 2);
return `${hours}:${minutes}`;
} else if (diffDays < 7) {
// 一周内:显示x天前
return `${diffDays}${LanguageUtils.getText("purchasepanel.day")}}`;
} else if (diffDays < 30) {
// 一个月内:显示x周前
const weeks = Math.floor(diffDays / 7);
return `${weeks}${LanguageUtils.getText("purchasepanel.week")}`;
} else {
// 一个月以上:显示"一个月以上"
return LanguageUtils.getText("purchasepanel.months");
}
}
}