P0 - AI交互层:
- ai/prompt.js: 模块化 Prompt 模板
- ai/validator.js: JSON Schema 校验 + normalize
- ai/client.js: DeepSeek API 封装
- 金额计算唯一化,时间格式归一化
P1 - 后端架构:
- routes/: auth/rooms/messages/purchases 独立路由
- middleware/auth.js: 认证授权中间件
- ws/index.js: WebSocket 连接管理
- db.js: 启用 foreign_keys
- server.js: 从588行精简到40行入口
P2 - 前端架构:
- public/css/style.css: CSS 独立
- public/js/store.js: 全局状态 Store
- public/js/{chat,ws,purchases,auth}.js: 功能模块拆分
- index.html: 纯 HTML 结构, v2.6
19 lines
618 B
JavaScript
19 lines
618 B
JavaScript
// 公共工具函数
|
|
const TIMEZONE = 'Asia/Shanghai';
|
|
|
|
function timestamp() {
|
|
return new Date().toLocaleString('zh-CN', { timeZone: TIMEZONE, hour12: false });
|
|
}
|
|
|
|
function normalizeTime(str) {
|
|
if (!str) return timestamp();
|
|
if (/\d{4}\/\d{1,2}\/\d{1,2} \d{2}:\d{2}:\d{2}/.test(str)) return str;
|
|
const clean = str.replace(/-/g, '/');
|
|
if (/^\d{4}\/\d{1,2}\/\d{1,2}$/.test(clean)) return clean + ' 00:00:00';
|
|
const withSlash = str.replace(/-/g, '/');
|
|
if (/\d{4}\/\d{1,2}\/\d{1,2} \d{2}:\d{2}:\d{2}/.test(withSlash)) return withSlash;
|
|
return timestamp();
|
|
}
|
|
|
|
module.exports = { timestamp, normalizeTime };
|