sleep-checkin.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. <template>
  2. <view class="page" :style="{ '--font-scale': fontScale }">
  3. <view class="content">
  4. <!-- ===== 夜间主题头部:日期 / 本次时长 / 入睡-醒来时间轴 ===== -->
  5. <view class="hero">
  6. <view class="hero-glow"></view>
  7. <view class="hero-stars">
  8. <view class="star" v-for="s in stars" :key="s.id"
  9. :style="{ left: s.left, top: s.top, width: s.size, height: s.size, opacity: s.opacity, animationDelay: s.delay }"></view>
  10. </view>
  11. <view class="hero-moon">🌙</view>
  12. <view class="hero-top">
  13. <view class="hero-chip">
  14. <text class="hero-chip-dot"></text>
  15. <text class="hero-chip-text">今日睡眠打卡</text>
  16. </view>
  17. <text class="hero-date">{{ todayDate }} {{ todayWeek }}</text>
  18. </view>
  19. <view class="hero-duration">
  20. <text class="hero-duration-num">{{ durationText }}</text>
  21. <text class="hero-duration-label">本次睡眠时长</text>
  22. </view>
  23. <view class="tl">
  24. <view class="tl-pills">
  25. <view class="tl-pill tl-pill-moon" :class="timeMode === 'sleep' ? 'tl-pill-on' : ''" @tap="setTimeMode('sleep')">
  26. <text class="tl-pill-ic">🌙</text>
  27. <text class="tl-pill-t">入睡</text>
  28. <text class="tl-pill-time">{{ form.sleepTime || '--:--' }}</text>
  29. </view>
  30. <view class="tl-pill tl-pill-sun" :class="timeMode === 'wake' ? 'tl-pill-on' : ''" @tap="setTimeMode('wake')">
  31. <text class="tl-pill-ic">☀️</text>
  32. <text class="tl-pill-t">醒来</text>
  33. <text class="tl-pill-time">{{ form.wakeTime || '--:--' }}</text>
  34. </view>
  35. </view>
  36. <scroll-view class="tl-scroll" scroll-x :scroll-left="tlScrollLeft" scroll-with-animation :show-scrollbar="false">
  37. <view class="tl-bar">
  38. <view class="tl-seg" v-for="seg in segments" :key="seg.k" :class="seg.cls" @tap="onTimelineTap(seg.k)">
  39. <text class="tl-seg-time" v-if="seg.showLabel">{{ seg.label }}</text>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. <view class="tl-hint">点选「{{ timeMode === 'sleep' ? '入睡' : '醒来' }}」时间 · 每格 30 分钟,左右滑动找时间</view>
  44. </view>
  45. <view class="hero-tip">💡 建议青少年每天睡足 8-10 小时</view>
  46. </view>
  47. <!-- ===== 睡眠质量(点选打分,替代滑动条) ===== -->
  48. <view class="card">
  49. <view class="card-head">
  50. <view class="card-head-icon"><text>⭐</text></view>
  51. <text class="card-title">睡眠质量</text>
  52. <text class="card-hint">1-10 分</text>
  53. </view>
  54. <view class="card-body">
  55. <view class="quality-head">
  56. <view class="quality-face">{{ qualityFace }}</view>
  57. <view class="quality-info">
  58. <view class="quality-score-row">
  59. <text class="quality-score">{{ form.qualityScore }}</text>
  60. <text class="quality-unit">分</text>
  61. <text class="quality-badge" :class="'quality-badge quality-badge-' + qualityTier">{{ qualityLabel }}</text>
  62. </view>
  63. <text class="quality-desc">{{ qualityDesc }}</text>
  64. </view>
  65. </view>
  66. <view class="q-chips">
  67. <view class="q-chip" v-for="o in qualityOptions" :key="o.v"
  68. :class="'q-chip q-chip-' + o.tier + (form.qualityScore === o.v ? ' q-chip-active' : '')"
  69. @tap="setQuality(o.v)">
  70. <text>{{ o.v }}</text>
  71. </view>
  72. </view>
  73. <view class="q-scale">
  74. <text class="q-scale-end">1 · 很差</text>
  75. <text class="q-scale-mid">点击数字打分</text>
  76. <text class="q-scale-end">10 · 很好</text>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- ===== 快速标签(选填,将写入备注) ===== -->
  81. <view class="card">
  82. <view class="card-head">
  83. <view class="card-head-icon"><text>🏷️</text></view>
  84. <text class="card-title">睡眠情况</text>
  85. <text class="card-hint">选填 · 可多选</text>
  86. </view>
  87. <view class="card-body">
  88. <view class="tag-cloud">
  89. <view class="s-tag" v-for="t in quickTags" :key="t"
  90. :class="selectedTags.indexOf(t) > -1 ? 's-tag s-tag-active' : 's-tag'"
  91. @tap="toggleTag(t)">
  92. <text>{{ t }}</text>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. <!-- ===== 备注 ===== -->
  98. <view class="card">
  99. <view class="card-head">
  100. <view class="card-head-icon"><text>📝</text></view>
  101. <text class="card-title">备注</text>
  102. <text class="card-hint">{{ form.remark.length }}/100</text>
  103. </view>
  104. <view class="card-body">
  105. <textarea class="remark-input" v-model="form.remark"
  106. placeholder="昨晚睡得怎么样?有什么想记录的…" placeholder-class="ph-gray" maxlength="100" />
  107. </view>
  108. </view>
  109. <!-- ===== 提交按钮 ===== -->
  110. <view class="submit-wrap">
  111. <view class="submit-btn" :class="submitting ? 'submit-btn submitting' : 'submit-btn'" @tap="doCheckin">
  112. <text class="submit-text">{{ submitting ? '打卡中...' : '完成打卡' }}</text>
  113. </view>
  114. </view>
  115. <!-- ===== 历史记录 ===== -->
  116. <view class="card" v-if="history.length > 0">
  117. <view class="card-head">
  118. <view class="card-head-icon"><text>📜</text></view>
  119. <text class="card-title">近期睡眠</text>
  120. <text class="card-hint" v-if="avgDurationText">平均 {{ avgDurationText }} · {{ avgQuality }} 分</text>
  121. </view>
  122. <view class="card-body">
  123. <view class="history-list">
  124. <view class="history-item" v-for="item in history" :key="item.id">
  125. <view class="history-badge"><text class="history-badge-icon">🌙</text></view>
  126. <view class="history-main">
  127. <text class="history-line1">{{ item._range }}</text>
  128. <text class="history-line2">{{ item._duration }} · 质量 {{ item.qualityScore || '-' }} 分</text>
  129. <view class="qbar">
  130. <view class="qbar-fill" :style="{ width: item._percent + '%', background: item._barBg }"></view>
  131. </view>
  132. </view>
  133. <text class="history-date">{{ formatDate(item.createdAt) }}</text>
  134. </view>
  135. </view>
  136. </view>
  137. </view>
  138. <!-- 底部留白 -->
  139. <view class="bottom-spacer"></view>
  140. </view>
  141. </view>
  142. </template>
  143. <script>
  144. import config from '../../config'
  145. import { resolveCheckinMemberId } from '../../utils/memberNormalize.js'
  146. import { formatDate as formatDateUtil } from '../../utils/format.js'
  147. import { BrandColors } from '../../utils/brand-colors.js'
  148. import fontScaleMixin from '@/mixins/font-scale.js'
  149. export default {
  150. mixins: [fontScaleMixin],
  151. data() {
  152. return {
  153. memberId: null,
  154. taskId: null,
  155. submitting: false,
  156. timeMode: 'sleep',
  157. tlScrollLeft: 0,
  158. tlTotalPx: 0,
  159. tlAdvancePx: 0,
  160. tlViewPx: 0,
  161. history: [],
  162. todayDate: '',
  163. todayWeek: '',
  164. stars: [
  165. { id: 's1', left: '6%', top: '16%', size: '8rpx', opacity: 0.9, delay: '0s' },
  166. { id: 's2', left: '16%', top: '42%', size: '5rpx', opacity: 0.6, delay: '0.8s' },
  167. { id: 's3', left: '26%', top: '12%', size: '6rpx', opacity: 0.75, delay: '1.6s' },
  168. { id: 's4', left: '38%', top: '46%', size: '4rpx', opacity: 0.5, delay: '0.4s' },
  169. { id: 's5', left: '48%', top: '18%', size: '5rpx', opacity: 0.65, delay: '2.2s' }
  170. ],
  171. quickTags: ['入睡困难', '夜醒', '多梦', '打鼾', '早醒', '赖床', '熬夜', '午睡过长'],
  172. selectedTags: [],
  173. qualityOptions: [
  174. { v: 1, tier: 'poor' },
  175. { v: 2, tier: 'poor' },
  176. { v: 3, tier: 'poor' },
  177. { v: 4, tier: 'fair' },
  178. { v: 5, tier: 'fair' },
  179. { v: 6, tier: 'good' },
  180. { v: 7, tier: 'good' },
  181. { v: 8, tier: 'great' },
  182. { v: 9, tier: 'great' },
  183. { v: 10, tier: 'great' }
  184. ],
  185. qualityMap: {
  186. 1: { face: '😣', label: '很差', tier: 'poor', desc: '几乎整晚没睡好,白天完全不在状态' },
  187. 2: { face: '😣', label: '很差', tier: 'poor', desc: '睡得很浅,反复醒,醒来很累' },
  188. 3: { face: '😕', label: '较差', tier: 'poor', desc: '睡得不太踏实,精神差一些' },
  189. 4: { face: '😕', label: '偏差', tier: 'fair', desc: '将就睡了一晚,不算安稳' },
  190. 5: { face: '😐', label: '一般', tier: 'fair', desc: '不好不差,勉强够用' },
  191. 6: { face: '🙂', label: '尚可', tier: 'good', desc: '睡得还行,基本恢复精力' },
  192. 7: { face: '🙂', label: '不错', tier: 'good', desc: '睡得比较踏实,状态正常' },
  193. 8: { face: '😊', label: '良好', tier: 'great', desc: '睡得很沉,醒来神清气爽' },
  194. 9: { face: '😄', label: '很好', tier: 'great', desc: '一觉到天亮,几乎不想起床' },
  195. 10: { face: '🤩', label: '极好', tier: 'great', desc: '完美的一觉,元气满满' }
  196. },
  197. form: {
  198. sleepTime: '21:00',
  199. wakeTime: '07:00',
  200. qualityScore: 7,
  201. remark: ''
  202. }
  203. }
  204. },
  205. computed: {
  206. // 本次睡眠时长(分钟),跨午夜自动换算
  207. durationMinutes: function () {
  208. var s = this.form.sleepTime
  209. var w = this.form.wakeTime
  210. if (!s || !w) return 0
  211. var sp = String(s).split(':')
  212. var wp = String(w).split(':')
  213. var sm = parseInt(sp[0]) * 60 + parseInt(sp[1])
  214. var wm = parseInt(wp[0]) * 60 + parseInt(wp[1])
  215. if (isNaN(sm) || isNaN(wm)) return 0
  216. return wm > sm ? wm - sm : (24 * 60 - sm + wm)
  217. },
  218. durationText: function () {
  219. return this.durationFromMinutes(this.durationMinutes)
  220. },
  221. // 24 小时 × 2 格/小时 = 48 个半小时间隔段(用于时间轴高亮与标签)
  222. segments: function () {
  223. var self = this
  224. var s = this.slotOf(this.form.sleepTime)
  225. var w = this.slotOf(this.form.wakeTime)
  226. var arr = []
  227. for (var i = 0; i < 48; i++) {
  228. var on = false
  229. if (s >= 0 && w >= 0 && s !== w) {
  230. if (w > s) on = i >= s && i <= w
  231. else on = i >= s || i <= w
  232. }
  233. var cls = on ? 'tl-seg tl-seg-on' : 'tl-seg'
  234. if (i === s) cls += ' tl-seg-sleep'
  235. if (i === w) cls += ' tl-seg-wake'
  236. var showLabel = (i % 2 === 0) || i === s || i === w
  237. arr.push({ k: i, cls: cls, showLabel: showLabel, label: self.timeFromSlot(i) })
  238. }
  239. return arr
  240. },
  241. qualityFace: function () {
  242. var m = this.qualityMap[this.form.qualityScore]
  243. return m ? m.face : '🙂'
  244. },
  245. qualityLabel: function () {
  246. var m = this.qualityMap[this.form.qualityScore]
  247. return m ? m.label : '一般'
  248. },
  249. qualityTier: function () {
  250. var m = this.qualityMap[this.form.qualityScore]
  251. return m ? m.tier : 'fair'
  252. },
  253. qualityDesc: function () {
  254. var m = this.qualityMap[this.form.qualityScore]
  255. return m ? m.desc : ''
  256. },
  257. avgDurationText: function () {
  258. var total = 0
  259. var count = 0
  260. this.history.forEach(function (h) {
  261. if (h.durationMinutes) { total += h.durationMinutes; count++ }
  262. })
  263. if (!count) return ''
  264. return this.durationFromMinutes(Math.round(total / count))
  265. },
  266. avgQuality: function () {
  267. var total = 0
  268. var count = 0
  269. this.history.forEach(function (h) {
  270. if (h.qualityScore) { total += h.qualityScore; count++ }
  271. })
  272. if (!count) return 0
  273. return (total / count).toFixed(1)
  274. }
  275. },
  276. onLoad: function (options) {
  277. this.taskId = options.taskId || null
  278. var d = new Date()
  279. var weekdays = ['日', '一', '二', '三', '四', '五', '六']
  280. var m2 = ('0' + (d.getMonth() + 1)).slice(-2)
  281. var day = ('0' + d.getDate()).slice(-2)
  282. this.todayDate = d.getFullYear() + '-' + m2 + '-' + day
  283. this.todayWeek = '周' + weekdays[d.getDay()]
  284. this.memberId = resolveCheckinMemberId(options, {
  285. currentRole: uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent',
  286. currentChildId: uni.getStorageSync('currentChildId'),
  287. currentMemberId: uni.getStorageSync('currentMemberId'),
  288. userId: uni.getStorageSync('userId')
  289. })
  290. this.loadHistory()
  291. },
  292. onReady: function () {
  293. var self = this
  294. // 量取时间轴实际像素宽度,用于把选中时间滚动到可视区中间
  295. uni.createSelectorQuery().in(this).select('.tl-bar').boundingClientRect(function (rect) {
  296. if (rect && rect.width) {
  297. self.tlTotalPx = rect.width
  298. self.tlAdvancePx = rect.width / 48
  299. var winW = uni.getWindowInfo().windowWidth
  300. self.tlViewPx = winW - 112 * (winW / 750)
  301. self.scrollToSlot(self.slotOf(self.form.sleepTime))
  302. }
  303. }).exec()
  304. },
  305. methods: {
  306. formatDate: function(d) { return formatDateUtil(d) },
  307. durationFromMinutes: function (mins) {
  308. if (!mins || mins <= 0) return '--'
  309. var h = Math.floor(mins / 60)
  310. var m = mins % 60
  311. if (h > 0) return h + ' 小时' + (m > 0 ? ' ' + m + ' 分' : '')
  312. return m + ' 分钟'
  313. },
  314. // 时间轴:半小时间隔 (0=00:00 .. 47=23:30)
  315. slotOf: function (t) {
  316. if (!t) return -1
  317. var p = String(t).split(':')
  318. var h = parseInt(p[0]); var m = parseInt(p[1])
  319. if (isNaN(h) || isNaN(m)) return -1
  320. return Math.round((h * 60 + m) / 30) % 48
  321. },
  322. timeFromSlot: function (i) {
  323. var h = Math.floor(i / 2)
  324. var m = (i % 2) * 30
  325. return ('0' + h).slice(-2) + ':' + ('0' + m).slice(-2)
  326. },
  327. setTimeMode: function (mode) {
  328. this.timeMode = mode
  329. this.scrollToSlot(this.slotOf(this.form[mode === 'sleep' ? 'sleepTime' : 'wakeTime']))
  330. },
  331. onTimelineTap: function (i) {
  332. var self = this
  333. var t = this.timeFromSlot(i)
  334. if (self.timeMode === 'sleep') {
  335. self.form.sleepTime = t
  336. self.timeMode = 'wake'
  337. } else {
  338. self.form.wakeTime = t
  339. }
  340. self.scrollToSlot(i)
  341. },
  342. scrollToSlot: function (slot) {
  343. if (slot < 0 || !this.tlAdvancePx) return
  344. var target = slot * this.tlAdvancePx - this.tlViewPx / 2 + this.tlAdvancePx / 2
  345. var max = Math.max(0, this.tlTotalPx - this.tlViewPx)
  346. this.tlScrollLeft = Math.max(0, Math.min(target, max))
  347. },
  348. setQuality: function (score) {
  349. this.form.qualityScore = score
  350. },
  351. toggleTag: function (tag) {
  352. var idx = this.selectedTags.indexOf(tag)
  353. if (idx > -1) {
  354. this.selectedTags.splice(idx, 1)
  355. } else {
  356. this.selectedTags.push(tag)
  357. }
  358. },
  359. loadHistory: function () {
  360. var self = this
  361. var token = uni.getStorageSync('token')
  362. if (!token || !self.memberId) return
  363. uni.request({
  364. url: config.API_BASE_URL + '/api/health/sleep/list',
  365. method: 'POST',
  366. data: { memberId: self.memberId },
  367. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  368. success: function (res) {
  369. if (res.data && res.data.code === 200 && res.data.data) {
  370. var arr = Array.isArray(res.data.data) ? res.data.data : []
  371. self.history = arr.slice(0, 5).map(function (item) {
  372. self.decorateHistoryItem(item)
  373. return item
  374. })
  375. }
  376. }
  377. })
  378. },
  379. // 预计算列表渲染字段(避免模板中调用带参方法)
  380. decorateHistoryItem: function (item) {
  381. var score = item.qualityScore || 0
  382. item._range = (item.sleepTime ? String(item.sleepTime).slice(0, 5) : '--:--') +
  383. ' - ' + (item.wakeTime ? String(item.wakeTime).slice(0, 5) : '--:--')
  384. item._duration = this.durationFromMinutes(item.durationMinutes)
  385. item._percent = Math.min(100, Math.max(0, Math.round(score * 10)))
  386. if (score >= 8) item._barBg = `linear-gradient(90deg, ${BrandColors.wisdomLight}, ${BrandColors.wisdom})`
  387. else if (score >= 6) item._barBg = `linear-gradient(90deg, ${BrandColors.successLight3}, ${BrandColors.success})`
  388. else if (score >= 4) item._barBg = `linear-gradient(90deg, ${BrandColors.warning}, ${BrandColors.wealth})`
  389. else item._barBg = `linear-gradient(90deg, ${BrandColors.dangerLight2}, ${BrandColors.danger})`
  390. },
  391. buildRemark: function () {
  392. var remark = this.form.remark ? this.form.remark.trim() : ''
  393. var tagText = this.selectedTags.join(',')
  394. if (tagText && remark) return tagText + ',' + remark
  395. if (tagText) return tagText
  396. return remark
  397. },
  398. doCheckin: function () {
  399. var self = this
  400. if (self.submitting) return
  401. if (!self.form.sleepTime) { uni.showToast({ title: '请选择入睡时间', icon: 'none' }); return }
  402. if (!self.form.wakeTime) { uni.showToast({ title: '请选择醒来时间', icon: 'none' }); return }
  403. if (self.form.sleepTime === self.form.wakeTime) { uni.showToast({ title: '入睡和醒来时间不能相同', icon: 'none' }); return }
  404. if (!self.form.qualityScore) { uni.showToast({ title: '请选择睡眠质量', icon: 'none' }); return }
  405. if (!self.memberId) { uni.showToast({ title: '成员ID无效', icon: 'none' }); return }
  406. self.submitting = true
  407. var token = uni.getStorageSync('token')
  408. uni.request({
  409. url: config.API_BASE_URL + '/api/health/sleep/create',
  410. method: 'POST',
  411. data: {
  412. memberId: self.memberId,
  413. taskId: self.taskId || undefined,
  414. sleepTime: self.form.sleepTime,
  415. wakeTime: self.form.wakeTime,
  416. durationMinutes: self.durationMinutes,
  417. qualityScore: self.form.qualityScore,
  418. remark: self.buildRemark()
  419. },
  420. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  421. success: function (res) {
  422. self.submitting = false
  423. if (res.data && res.data.code === 200) {
  424. uni.showToast({ title: self.taskId ? '打卡成功,任务已完成' : '打卡成功', icon: 'success' })
  425. // 本地插入新记录(复用已返回的数据,不重复请求列表接口)
  426. var created = res.data.data
  427. if (created) {
  428. self.decorateHistoryItem(created)
  429. var list = self.history.slice()
  430. list.unshift(created)
  431. self.history = list.slice(0, 5)
  432. }
  433. // 打卡成功:任务已完成(后端 create 已按任务归属自动完成并自纠成员,
  434. // 无需再调 /api/tasks/{id}/complete——历史冗余调用在双身份/已完成时会触发 500)
  435. setTimeout(function () {
  436. uni.navigateBack()
  437. }, 800)
  438. } else {
  439. uni.showToast({ title: (res.data && res.data.message) || '打卡失败', icon: 'none' })
  440. }
  441. },
  442. fail: function () {
  443. self.submitting = false
  444. uni.showToast({ title: '网络错误', icon: 'none' })
  445. }
  446. })
  447. }
  448. }
  449. }
  450. </script>
  451. <style scoped lang="scss">
  452. // ===== 睡眠页专属色阶(雪夜蓝 + 月光米黄,单页主题专用;约定见 uni.scss §14)=====
  453. $c-night-page: #EEF1F8; // 页面底(深夜蓝灰)
  454. $c-night-1: #3B4A8C; // 雪夜蓝渐变档 1(起点)
  455. $c-night-2: #2A3470; // 雪夜蓝渐变档 2(中段)
  456. $c-night-3: #1B2350; // 雪夜蓝渐变档 3(终点)
  457. $c-moon-soft: #FFE9A8; // 月光浅黄
  458. $c-moon: #FFD166; // 月光主黄(星星/月牙)
  459. $c-moon-deep: #FFB84D; // 月光深黄
  460. $c-dusk-1: #FF9F68; // 暮色橙渐档 1
  461. $c-dusk-2: #FF7A45; // 暮色橙渐档 2
  462. $c-sepia-ink: #4A2A00; // 深棕文字(暖卡内)
  463. $c-sky-ghost: #F8FAFF; // 极浅蓝(卡底)
  464. $c-sky-soft: #F1F5FF; // 浅蓝(卡内底)
  465. $c-sky-line: #EDF1F7; // 浅蓝分隔线
  466. $c-emerald-700: $status-success-deep-2; // 好质量徽章文字(vs 全局 $status-success-deep $status-success-deep)
  467. $c-rose-400: #FB7185; // 差质量徽章渐变起点(rose-400,全局 danger 族无此档)
  468. /* ===== 页面基础 ===== */
  469. .page { min-height: 100vh; background: $c-night-page; }
  470. .content { padding: 20rpx 0 0; }
  471. /* ===== 夜间主题头部 ===== */
  472. .hero {
  473. position: relative;
  474. margin: 8rpx 24rpx 8rpx;
  475. padding: 36rpx 32rpx 32rpx;
  476. border-radius: 24rpx;
  477. overflow: hidden;
  478. background: linear-gradient(155deg, $c-night-1 0%, $c-night-2 45%, $c-night-3 100%);
  479. box-shadow: 0 16rpx 40rpx rgba(27, 35, 80, 0.35);
  480. color: $app-surface;
  481. }
  482. .hero-glow {
  483. position: absolute;
  484. top: -120rpx;
  485. right: -80rpx;
  486. width: 320rpx;
  487. height: 320rpx;
  488. border-radius: 50%;
  489. background: radial-gradient(circle, rgba(255, 209, 102, 0.4) 0%, rgba(255, 209, 102, 0) 70%);
  490. }
  491. .hero-moon {
  492. position: absolute;
  493. top: 20rpx;
  494. right: 32rpx;
  495. font-size: calc($uni-font-size-5xl * var(--font-scale, 1));
  496. line-height: 1;
  497. animation: moon-float 4s ease-in-out infinite;
  498. }
  499. @keyframes moon-float {
  500. 0%, 100% { transform: translateY(0); }
  501. 50% { transform: translateY(-10rpx); }
  502. }
  503. .star {
  504. position: absolute;
  505. border-radius: 50%;
  506. background: $c-moon-soft;
  507. animation: star-twinkle 2.4s ease-in-out infinite;
  508. }
  509. @keyframes star-twinkle {
  510. 0%, 100% { opacity: 0.2; transform: scale(0.8); }
  511. 50% { opacity: 0.95; transform: scale(1.15); }
  512. }
  513. .hero-top {
  514. display: flex;
  515. align-items: center;
  516. justify-content: space-between;
  517. position: relative;
  518. z-index: 1;
  519. }
  520. .hero-chip {
  521. display: flex;
  522. align-items: center;
  523. gap: 10rpx;
  524. padding: 8rpx 20rpx;
  525. border-radius: 999rpx;
  526. background: rgba(255, 255, 255, 0.14);
  527. }
  528. .hero-chip-dot {
  529. width: 10rpx;
  530. height: 10rpx;
  531. border-radius: 50%;
  532. background: $c-moon;
  533. box-shadow: 0 0 12rpx rgba(255, 209, 102, 0.9);
  534. }
  535. .hero-chip-text { font-size: calc(22rpx * var(--font-scale, 1)); color: $app-surface; }
  536. .hero-date { font-size: calc(24rpx * var(--font-scale, 1)); color: rgba(255, 255, 255, 0.75); }
  537. .hero-duration {
  538. position: relative;
  539. z-index: 1;
  540. margin-top: 24rpx;
  541. }
  542. .hero-duration-num {
  543. font-size: calc($uni-font-size-display * var(--font-scale, 1));
  544. font-weight: $uni-font-weight-extra-heavy;
  545. color: $app-surface;
  546. line-height: 1.1;
  547. }
  548. .hero-duration-label {
  549. display: block;
  550. font-size: calc(24rpx * var(--font-scale, 1));
  551. color: rgba(255, 255, 255, 0.7);
  552. margin-top: 6rpx;
  553. }
  554. .tl {
  555. position: relative;
  556. z-index: 1;
  557. margin-top: 28rpx;
  558. }
  559. .tl-pills {
  560. display: flex;
  561. gap: 16rpx;
  562. }
  563. .tl-pill {
  564. flex: 1;
  565. display: flex;
  566. align-items: center;
  567. gap: 10rpx;
  568. padding: 16rpx 20rpx;
  569. border-radius: 24rpx;
  570. background: rgba(255, 255, 255, 0.1);
  571. border: 2rpx solid rgba(255, 255, 255, 0.14);
  572. transition: transform 0.2s ease;
  573. }
  574. .tl-pill:active { transform: scale(0.97); }
  575. .tl-pill-on {
  576. background: rgba(255, 255, 255, 0.22);
  577. border-color: rgba(255, 209, 102, 0.75);
  578. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.22);
  579. }
  580. .tl-pill-ic { font-size: calc(30rpx * var(--font-scale, 1)); line-height: 1; }
  581. .tl-pill-t { font-size: calc(24rpx * var(--font-scale, 1)); color: rgba(255, 255, 255, 0.72); }
  582. .tl-pill-time {
  583. flex: 1;
  584. text-align: right;
  585. font-size: calc(34rpx * var(--font-scale, 1));
  586. font-weight: 700;
  587. color: $app-surface;
  588. }
  589. .tl-pill-on .tl-pill-time { color: $c-moon; }
  590. .tl-scroll {
  591. margin-top: 20rpx;
  592. width: 100%;
  593. height: 92rpx;
  594. }
  595. .tl-bar {
  596. display: flex;
  597. gap: 4rpx;
  598. padding: 0 2rpx;
  599. align-items: stretch;
  600. }
  601. .tl-seg {
  602. width: 96rpx;
  603. height: 76rpx;
  604. flex-shrink: 0;
  605. border-radius: 8rpx;
  606. background: rgba(255, 255, 255, 0.13);
  607. display: flex;
  608. align-items: center;
  609. justify-content: center;
  610. transition: background 0.15s ease;
  611. }
  612. .tl-seg:active { background: rgba(255, 255, 255, 0.4); }
  613. .tl-seg-time {
  614. font-size: calc(18rpx * var(--font-scale, 1));
  615. color: rgba(255, 255, 255, 0.8);
  616. line-height: 1;
  617. }
  618. .tl-seg-on { background: rgba(255, 209, 102, 0.55); }
  619. .tl-seg-on .tl-seg-time { color: rgba(255, 255, 255, 0.95); }
  620. .tl-seg-sleep {
  621. background: linear-gradient(180deg, $c-moon, $c-moon-deep);
  622. box-shadow: 0 0 12rpx rgba(255, 209, 102, 0.8);
  623. }
  624. .tl-seg-wake {
  625. background: linear-gradient(180deg, $c-dusk-1, $c-dusk-2);
  626. box-shadow: 0 0 12rpx rgba(255, 159, 104, 0.8);
  627. }
  628. .tl-seg-sleep .tl-seg-time, .tl-seg-wake .tl-seg-time {
  629. color: $c-sepia-ink;
  630. font-weight: 700;
  631. }
  632. .tl-hint {
  633. font-size: calc(20rpx * var(--font-scale, 1));
  634. color: rgba(255, 255, 255, 0.55);
  635. margin-top: 14rpx;
  636. }
  637. .hero-tip {
  638. position: relative;
  639. z-index: 1;
  640. margin-top: 24rpx;
  641. padding-top: 20rpx;
  642. border-top: 1rpx solid rgba(255, 255, 255, 0.12);
  643. font-size: calc(22rpx * var(--font-scale, 1));
  644. color: rgba(255, 255, 255, 0.65);
  645. }
  646. /* ===== 卡片通用 ===== */
  647. .card {
  648. margin: 24rpx 24rpx 0;
  649. background: $app-surface;
  650. border-radius: 24rpx;
  651. box-shadow: 0 8rpx 28rpx rgba(15, 23, 42, 0.05);
  652. }
  653. .card-head {
  654. display: flex;
  655. align-items: center;
  656. gap: 14rpx;
  657. padding: 26rpx 28rpx 14rpx;
  658. }
  659. .card-head-icon {
  660. width: 56rpx;
  661. height: 56rpx;
  662. border-radius: 16rpx;
  663. background: linear-gradient(135deg, $dim-wisdom-tint-2, $accent-indigo-tint);
  664. display: flex;
  665. align-items: center;
  666. justify-content: center;
  667. font-size: calc(30rpx * var(--font-scale, 1));
  668. flex-shrink: 0;
  669. }
  670. .card-title {
  671. flex: 1;
  672. font-size: calc(30rpx * var(--font-scale, 1));
  673. font-weight: 600;
  674. color: $uni-text-color;
  675. }
  676. .card-hint { font-size: calc(22rpx * var(--font-scale, 1)); color: $app-text-subtle; }
  677. .card-body { padding: 4rpx 28rpx $uni-space-lg; }
  678. /* ===== 睡眠质量 ===== */
  679. .quality-head {
  680. display: flex;
  681. align-items: center;
  682. gap: 24rpx;
  683. background: linear-gradient(160deg, $c-sky-ghost, $c-sky-soft);
  684. border-radius: 24rpx;
  685. padding: 26rpx 24rpx;
  686. margin-bottom: 26rpx;
  687. }
  688. .quality-face {
  689. width: 116rpx;
  690. height: 116rpx;
  691. border-radius: 50%;
  692. background: $app-surface;
  693. box-shadow: 0 6rpx 18rpx rgba(79, 70, 229, 0.12);
  694. display: flex;
  695. align-items: center;
  696. justify-content: center;
  697. font-size: calc(62rpx * var(--font-scale, 1));
  698. flex-shrink: 0;
  699. }
  700. .quality-info { flex: 1; min-width: 0; }
  701. .quality-score-row { display: flex; align-items: baseline; }
  702. .quality-score {
  703. font-size: calc(54rpx * var(--font-scale, 1));
  704. font-weight: $uni-font-weight-extra-heavy;
  705. color: $uni-text-color;
  706. line-height: 1;
  707. }
  708. .quality-unit { font-size: calc(24rpx * var(--font-scale, 1)); color: $app-text-subtle; margin-left: 6rpx; }
  709. .quality-badge {
  710. margin-left: 14rpx;
  711. padding: 6rpx 18rpx;
  712. border-radius: 999rpx;
  713. font-size: calc(22rpx * var(--font-scale, 1));
  714. font-weight: 600;
  715. }
  716. .quality-badge-poor { background: $status-danger-soft; color: $status-danger-deep; }
  717. .quality-badge-fair { background: $status-warning-soft; color: $status-warning-strong-2; }
  718. .quality-badge-good { background: $status-success-soft; color: $c-emerald-700; }
  719. .quality-badge-great { background: $accent-indigo-tint; color: $accent-indigo-ink; }
  720. .quality-desc { display: block; font-size: calc(24rpx * var(--font-scale, 1)); color: $uni-text-color-secondary; margin-top: 12rpx; }
  721. .q-chips { display: flex; flex-wrap: wrap; gap: 14rpx; }
  722. .q-chip {
  723. flex: 1;
  724. height: 78rpx;
  725. border-radius: 24rpx;
  726. background: $facade-fill-slate-50;
  727. border: 2rpx solid $c-sky-line;
  728. display: flex;
  729. align-items: center;
  730. justify-content: center;
  731. transition: transform 0.18s ease;
  732. }
  733. .q-chip text { font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 600; color: $uni-text-color-secondary; }
  734. .q-chip:active { transform: scale(0.94); }
  735. .q-chip-active { border-color: transparent; transform: translateY(-4rpx); }
  736. .q-chip-active text { color: $app-surface; }
  737. .q-chip-poor text { color: $status-danger-light; }
  738. .q-chip-fair text { color: $status-warning-deep; }
  739. .q-chip-good text { color: $status-success-deep; }
  740. .q-chip-great text { color: $dim-wisdom-deep; }
  741. .q-chip-poor.q-chip-active { background: linear-gradient(135deg, $c-rose-400, $status-danger); box-shadow: 0 8rpx 20rpx rgba(239, 68, 68, 0.3); }
  742. .q-chip-fair.q-chip-active { background: linear-gradient(135deg, $status-warning, $dim-wealth); box-shadow: 0 8rpx 20rpx rgba(245, 158, 11, 0.3); }
  743. .q-chip-good.q-chip-active { background: linear-gradient(135deg, $status-success-light-3, $status-success); box-shadow: 0 8rpx 20rpx rgba(16, 185, 129, 0.3); }
  744. .q-chip-great.q-chip-active { background: linear-gradient(135deg, $dim-wisdom-light, $dim-wisdom); box-shadow: 0 8rpx 20rpx rgba(99, 102, 241, 0.3); }
  745. .q-scale {
  746. display: flex;
  747. justify-content: space-between;
  748. align-items: center;
  749. margin-top: 14rpx;
  750. }
  751. .q-scale-end { font-size: calc(22rpx * var(--font-scale, 1)); color: $app-text-subtle; }
  752. .q-scale-mid { font-size: calc(20rpx * var(--font-scale, 1)); color: $uni-border-color; }
  753. /* ===== 快速标签 ===== */
  754. .tag-cloud { display: flex; flex-wrap: wrap; gap: 16rpx; }
  755. .s-tag {
  756. padding: 14rpx 26rpx;
  757. border-radius: 999rpx;
  758. background: $facade-fill-slate-50;
  759. border: 2rpx solid $c-sky-line;
  760. transition: transform 0.18s ease;
  761. }
  762. .s-tag text { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-slate-deep; }
  763. .s-tag:active { transform: scale(0.96); }
  764. .s-tag-active { background: $dim-wisdom-tint-2; border-color: $dim-wisdom; }
  765. .s-tag-active text { color: $dim-wisdom-deep; font-weight: 600; }
  766. /* ===== 备注 ===== */
  767. .remark-input {
  768. width: 100%;
  769. min-height: 150rpx;
  770. background: $facade-fill-slate-50;
  771. border: 2rpx solid $c-sky-line;
  772. border-radius: 24rpx;
  773. padding: 20rpx;
  774. font-size: calc(26rpx * var(--font-scale, 1));
  775. color: $uni-text-color;
  776. box-sizing: border-box;
  777. }
  778. .ph-gray { color: $uni-border-color; font-size: calc(26rpx * var(--font-scale, 1)); }
  779. /* ===== 提交按钮 ===== */
  780. .submit-wrap { padding: 32rpx 24rpx 8rpx; }
  781. .submit-btn {
  782. background: linear-gradient(135deg, $dim-wisdom, $dim-wisdom-deep 60%, $accent-indigo-ink);
  783. border-radius: 999rpx;
  784. padding: 26rpx 0;
  785. text-align: center;
  786. box-shadow: 0 12rpx 28rpx rgba(79, 70, 229, 0.35);
  787. transition: transform 0.2s ease;
  788. }
  789. .submit-btn:active {
  790. transform: scale(0.98);
  791. box-shadow: 0 6rpx 14rpx rgba(79, 70, 229, 0.25);
  792. }
  793. .submit-text { color: $app-surface; font-size: calc(30rpx * var(--font-scale, 1)); font-weight: 700; letter-spacing: 2rpx; }
  794. .submitting { opacity: 0.6; }
  795. /* ===== 历史记录 ===== */
  796. .history-list { display: flex; flex-direction: column; }
  797. .history-item {
  798. display: flex;
  799. align-items: center;
  800. gap: 20rpx;
  801. padding: 20rpx 0;
  802. border-bottom: 2rpx solid $facade-fill-slate;
  803. }
  804. .history-item:last-child { border-bottom: none; }
  805. .history-badge {
  806. width: 76rpx;
  807. height: 76rpx;
  808. border-radius: 24rpx;
  809. background: linear-gradient(135deg, $dim-wisdom-tint-2, $accent-indigo-tint);
  810. display: flex;
  811. align-items: center;
  812. justify-content: center;
  813. flex-shrink: 0;
  814. }
  815. .history-badge-icon { font-size: calc(36rpx * var(--font-scale, 1)); line-height: 1; }
  816. .history-main { flex: 1; min-width: 0; }
  817. .history-line1 { font-size: calc(28rpx * var(--font-scale, 1)); font-weight: 600; color: $uni-text-color; display: block; }
  818. .history-line2 { font-size: calc(22rpx * var(--font-scale, 1)); color: $uni-text-color-secondary; display: block; margin-top: 6rpx; }
  819. .qbar {
  820. height: 8rpx;
  821. border-radius: 999rpx;
  822. background: $facade-fill-slate;
  823. margin-top: 12rpx;
  824. overflow: hidden;
  825. }
  826. .qbar-fill { height: 100%; border-radius: 999rpx; transition: width 0.3s ease; }
  827. .history-date { font-size: calc(22rpx * var(--font-scale, 1)); color: $app-text-subtle; flex-shrink: 0; }
  828. /* ===== 底部留白 ===== */
  829. .bottom-spacer { height: 60rpx; }
  830. </style>