文件
huaqiapp/utils/date.js
linda 5ea1b461f3 feat: 花期 V1.0 纵向切片(暖色调设计系统 + 周期/情绪/会员全链路)
前端(uni-app · Vue3)
- 设计系统:uni.scss 品牌令牌(花红 #E8604C / 蜜橙 #F5A65B / 暖米白 #FFF9F5),
  App.vue 全局原子类(卡片/按钮/胶囊/单元格/空态/进度)
- 页面:登录、首页(聚合)、周期(花瓣日历+当日记录+预测+概览)、情绪(记录+趋势+日记+疗愈)、
  我的(资料/会员/隐私/提醒)、健康报告、会员套餐、内容详情
- 组件:hq-tabbar(自定义底栏)、bloom-calendar(阶段日历)
- 基础层:utils/{config,request,store,api,date}.js(统一 token、401 处理、接口集中定义)

后端(FastAdmin / ThinkPHP 5.0)
- 新增 api 控制器:Home / Cycle / Mood / Content / Member / Setting,User 增补 detail、updateprofile
- 新增服务层:CycleService(四阶段计算、预测、月历、汇总)、MemberService(权益判定)
- 新增表:fa_cycle / fa_cycle_log / fa_symptom_tag / fa_mood_log / fa_content /
  fa_content_category / fa_member_plan / fa_member_order / fa_user_setting
- 初始化数据:20 个症状标签、28 条内容(心语/科普/知识/食谱/运动/睡眠/痛经/冥想)、3 档会员

验证(全部通过)
- 接口全链路 48 项断言(登录→周期→首页→情绪→内容→会员→设置→资料)
- 前后端契约静态校验 24 个接口 0 偏差
- Vue SFC 编译 11/11、SCSS 编译 10/10
- 验证脚本见 scripts/verify/,报告见 docs/04-前端设计系统与联调验证.md
2026-11-05 22:54:02 +08:00

72 行
2.1 KiB
JavaScript

/**
* 日期工具(统一 YYYY-MM-DD / YYYY-MM 字符串口径,与后端一致)
*/
const WEEK_TEXT = ['日', '一', '二', '三', '四', '五', '六']
export function pad(n) {
return n < 10 ? '0' + n : '' + n
}
export function formatDate(date) {
const d = date instanceof Date ? date : new Date(date)
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate())
}
export function today() {
return formatDate(new Date())
}
export function monthOf(date) {
return formatDate(date instanceof Date ? date : new Date(date)).slice(0, 7)
}
export function addDays(dateStr, days) {
const d = new Date(dateStr.replace(/-/g, '/'))
d.setDate(d.getDate() + days)
return formatDate(d)
}
export function addMonths(monthStr, months) {
const parts = monthStr.split('-')
const d = new Date(Number(parts[0]), Number(parts[1]) - 1 + months, 1)
return d.getFullYear() + '-' + pad(d.getMonth() + 1)
}
export function weekText(dateStr) {
const d = new Date(dateStr.replace(/-/g, '/'))
return '周' + WEEK_TEXT[d.getDay()]
}
export function dayText(dateStr) {
const parts = dateStr.split('-')
return Number(parts[1]) + '月' + Number(parts[2]) + '日'
}
export function monthText(monthStr) {
const parts = monthStr.split('-')
return parts[0] + '年' + Number(parts[1]) + '月'
}
/** 相对今天的描述:今天 / 明天 / 还有 N 天 / N 天前 */
export function relativeDay(dateStr) {
const diff = Math.round((new Date(dateStr.replace(/-/g, '/')) - new Date(today().replace(/-/g, '/'))) / 86400000)
if (diff === 0) return '今天'
if (diff === 1) return '明天'
if (diff === -1) return '昨天'
return diff > 0 ? '还有 ' + diff + ' 天' : Math.abs(diff) + ' 天前'
}
/** 生成某月日历所需的空白格数(周日起始) */
export function leadingBlanks(monthStr) {
const d = new Date(monthStr + '-01'.replace(/-/g, '/'))
return d.getDay()
}
export const PHASE_META = {
menstrual: { text: '经期', color: '#E8604C' },
follicular: { text: '卵泡期', color: '#F5A65B' },
ovulation: { text: '排卵期', color: '#F0796A' },
luteal: { text: '黄体期', color: '#C79A7B' },
unknown: { text: '', color: '#F1E4DC' }
}