physical.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. <template>
  2. <CustomNav title="体格数据" leftType="back" />
  3. <view class="page">
  4. <view class="header">
  5. <view class="month-selector">
  6. <button class="btn" @click="prevPeriod">‹</button>
  7. <view class="period-controls">
  8. <picker mode="multiSelector" :value="pickerValue" :range="pickerRange" @change="onPickerChange">
  9. <view class="month-label">{{ displayPeriod }}</view>
  10. </picker>
  11. <view class="view-toggle">
  12. <button :class="['toggle-btn', { active: viewMode === 'month' }]" @click="setViewMode('month')">月</button>
  13. <button :class="['toggle-btn', { active: viewMode === 'week' }]" @click="setViewMode('week')">周</button>
  14. </view>
  15. <view class="metric-toggle" style="margin-top:8rpx; display:flex; gap:8rpx;">
  16. <button :class="['toggle-btn', { active: selectedMetric === 'all' }]" @click.prevent="selectedMetric = 'all'">全部</button>
  17. <button :class="['toggle-btn', { active: selectedMetric === 'height' }]" @click.prevent="selectedMetric = 'height'">身高</button>
  18. <button :class="['toggle-btn', { active: selectedMetric === 'weight' }]" @click.prevent="selectedMetric = 'weight'">体重</button>
  19. <button :class="['toggle-btn', { active: selectedMetric === 'bmi' }]" @click.prevent="selectedMetric = 'bmi'">BMI</button>
  20. </view>
  21. </view>
  22. <button class="btn" @click="nextPeriod">›</button>
  23. </view>
  24. </view>
  25. <!-- 趋势图 - 简化canvas设置 -->
  26. <view class="chart-wrap">
  27. <view class="chart-header">本月趋势</view>
  28. <canvas
  29. canvas-id="bpChart"
  30. id="bpChart"
  31. class="chart-canvas"
  32. :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }"
  33. ></canvas>
  34. </view>
  35. <view class="content">
  36. <view class="summary">共 {{ records.length }} 条记录,本月平均:{{ averageHeight }} cm / {{ averageWeight }} kg;平均 BMI:{{ averageBMI }}</view>
  37. <view class="list">
  38. <view v-if="records.length === 0" class="empty">暂无记录,点击右下角 + 添加</view>
  39. <view v-for="item in records" :key="item.id" class="list-item" :style="{ backgroundColor: getItemColor(item.h, item.w) }">
  40. <view class="date">{{ item.date }}</view>
  41. <view class="value">{{ item.h }} cm / {{ item.w }} kg · BMI {{ item.bmi }}</view>
  42. <button class="btn-delete" @click="confirmDeleteRecord(item.id)">✕</button>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="fab" @click="openAdd">
  47. <view class="fab-inner">+</view>
  48. </view>
  49. <view class="modal" v-if="showAdd">
  50. <view class="modal-backdrop" @click="closeAdd"></view>
  51. <view class="modal-panel">
  52. <view class="drag-handle"></view>
  53. <view class="modal-header"><text class="modal-title">添加体格数据</text></view>
  54. <view class="modal-inner">
  55. <view class="form-row">
  56. <text class="label">日期</text>
  57. <picker mode="date" :value="addDate" @change="onAddDateChange">
  58. <view class="picker-display">{{ addDateLabel }}</view>
  59. </picker>
  60. </view>
  61. <view class="form-row">
  62. <text class="label">身高 (cm)</text>
  63. <input type="number" v-model.number="addHeight" class="input" placeholder="身高 (cm)" />
  64. </view>
  65. <view class="form-row">
  66. <text class="label">体重 (kg)</text>
  67. <input type="number" v-model.number="addWeight" class="input" placeholder="体重 (kg)" />
  68. </view>
  69. </view>
  70. <!--提供滑动条(收缩压70-200,舒张压40-120)-->
  71. <view class="ruler-wrap">
  72. <view class="ruler-row">
  73. <ScaleRuler v-if="showAdd" :min="100" :max="220" :step="1" :gutter="16" :initialValue="addHeight ?? 170" @update="onHUpdate" @change="onHChange" />
  74. </view>
  75. <view class="ruler-row">
  76. <ScaleRuler v-if="showAdd" :min="30" :max="200" :step="1" :gutter="16" :initialValue="addWeight ?? 65" @update="onWUpdate" @change="onWChange" />
  77. </view>
  78. </view>
  79. <view class="fixed-footer">
  80. <button class="btn-primary btn-full" @click="confirmAdd">保存</button>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </template>
  86. <script setup lang="ts">
  87. import { ref, computed, onMounted, watch, nextTick, onBeforeUnmount, getCurrentInstance } from 'vue'
  88. import { createUChart } from '@/composables/useUChart'
  89. import CustomNav from '@/components/custom-nav.vue'
  90. import ScaleRuler from '@/components/scale-ruler.vue'
  91. import { getWeekStart, getWeekEnd, formatDisplayDate, formatPickerDate, daysInMonth, getTodayStart, isAfterTodayDate, isMonthAfterToday, isWeekAfterToday } from '@/utils/date'
  92. import { getWindowWidth, rpxToPx } from '@/utils/platform'
  93. type RecordItem = { id: string; date: string; h: number; w: number; bmi: number }
  94. // 当前展示年月
  95. const current = ref(new Date())
  96. // 使用 multiSelector 的索引形式: [yearOffset从2000起, month(0-11)]
  97. const pickerValue = ref([current.value.getFullYear() - 2000, current.value.getMonth()])
  98. // 视图模式:'month' 或 'week'
  99. const viewMode = ref<'month' | 'week'>('month')
  100. // 年月选择器的选项范围(与 height/weight 保持一致)
  101. const pickerRange = ref([
  102. Array.from({ length: 50 }, (_, i) => `${2000 + i}年`),
  103. Array.from({ length: 12 }, (_, i) => `${i + 1}月`)
  104. ])
  105. // 明确的canvas尺寸(将由 getCanvasSize 初始化以匹配设备宽度)
  106. const canvasWidth = ref(700) // 初始值,会在 mounted 时覆盖
  107. const canvasHeight = ref(320)
  108. // 获取Canvas实际尺寸的函数 - 参考微信小程序示例使用固定尺寸
  109. function getCanvasSize(): Promise<{ width: number; height: number }> {
  110. return new Promise(async (resolve) => {
  111. const width = await getWindowWidth().catch(() => 375)
  112. const height = Math.round((320 / 750) * width)
  113. resolve({ width, height })
  114. })
  115. }
  116. // 使用 formatPickerDate 从 src/utils/date.ts
  117. const displayYear = computed(() => current.value.getFullYear())
  118. const displayMonth = computed(() => current.value.getMonth() + 1)
  119. // 显示周期(支持月/周)
  120. const displayPeriod = computed(() => {
  121. if (viewMode.value === 'month') {
  122. return `${displayYear.value}年 ${displayMonth.value}月`
  123. } else {
  124. const weekStart = getWeekStart(current.value)
  125. const weekEnd = getWeekEnd(current.value)
  126. return `${formatDisplayDate(weekStart)} - ${formatDisplayDate(weekEnd)}`
  127. }
  128. })
  129. const records = ref<RecordItem[]>(generateMockRecords(current.value))
  130. function generateMockRecords(d: Date): RecordItem[] {
  131. const arr: RecordItem[] = []
  132. if (viewMode.value === 'month') {
  133. const y = d.getFullYear()
  134. const m = d.getMonth()
  135. const n = Math.floor(Math.random() * Math.min(daysInMonth(y, m), 7))
  136. for (let i = 0; i < n; i++) {
  137. const day = Math.max(1, Math.floor(Math.random() * daysInMonth(y, m)) + 1)
  138. const date = new Date(y, m, day)
  139. // 随机生成身高(150-190)和体重(45-100)作为示例数据
  140. const h = 150 + Math.floor(Math.random() * 40)
  141. const w = 45 + Math.floor(Math.random() * 55)
  142. const bmi = Math.round((w / ((h / 100) * (h / 100))) * 10) / 10
  143. arr.push({ id: `${date.getTime()}-${i}`, date: formatDisplayDate(date), h, w, bmi })
  144. }
  145. } else {
  146. const weekStart = getWeekStart(d)
  147. const n = Math.floor(Math.random() * 7)
  148. for (let i = 0; i < n; i++) {
  149. const dayOffset = Math.floor(Math.random() * 7)
  150. const date = new Date(weekStart)
  151. date.setDate(weekStart.getDate() + dayOffset)
  152. const h = 150 + Math.floor(Math.random() * 40)
  153. const w = 45 + Math.floor(Math.random() * 55)
  154. const bmi = Math.round((w / ((h / 100) * (h / 100))) * 10) / 10
  155. arr.push({ id: `${date.getTime()}-${i}`, date: formatDisplayDate(date), h, w, bmi })
  156. }
  157. }
  158. return arr.sort((a, b) => (a.date < b.date ? 1 : -1))
  159. }
  160. // 将 records 聚合为每天一个点(取最新记录)
  161. function aggregateDaily(recordsArr: RecordItem[], year: number, month: number) {
  162. const map = new Map<number, RecordItem>()
  163. for (const r of recordsArr) {
  164. const parts = r.date.split('-')
  165. if (parts.length >= 3) {
  166. const y = parseInt(parts[0], 10)
  167. const m = parseInt(parts[1], 10) - 1
  168. const d = parseInt(parts[2], 10)
  169. if (y === year && m === month) {
  170. // 覆盖同一天,保留最新的(数组头部为最新)
  171. map.set(d, r)
  172. }
  173. }
  174. }
  175. // 返回按日索引的数组
  176. return map
  177. }
  178. const averageHeight = computed(() => {
  179. if (records.value.length === 0) return '--'
  180. const sum = records.value.reduce((s, r) => s + r.h, 0)
  181. return Math.round(sum / records.value.length)
  182. })
  183. const averageWeight = computed(() => {
  184. if (records.value.length === 0) return '--'
  185. const sum = records.value.reduce((s, r) => s + r.w, 0)
  186. return Math.round(sum / records.value.length)
  187. })
  188. const averageBMI = computed(() => {
  189. if (records.value.length === 0) return '--'
  190. const sum = records.value.reduce((s, r) => s + (r.bmi || 0), 0)
  191. return Math.round((sum / records.value.length) * 10) / 10
  192. })
  193. // 根据血压值获取颜色
  194. function getItemColor(h: number, w: number): string {
  195. // 根据 BMI 简单分类
  196. if (!h || !w) return '#ffffff'
  197. const bmi = w / ((h / 100) * (h / 100))
  198. if (bmi < 18.5) return '#fff3cd' // 偏瘦 - 黄
  199. if (bmi < 25) return '#e8f5e8' // 正常 - 绿
  200. if (bmi < 30) return '#fff3cd' // 超重 - 黄
  201. return '#f8d7da' // 肥胖 - 红
  202. }
  203. // 使用共享日期工具 (src/utils/date.ts)
  204. // 使用可复用的 chart composable,支持多序列
  205. const vm = getCurrentInstance()
  206. // 选择显示的指标:'all' | 'height' | 'weight' | 'bmi'
  207. const selectedMetric = ref<'all'|'height'|'weight'|'bmi'>('all')
  208. let bpChart: any = null
  209. function createChartForMetric(metric: 'all'|'height'|'weight'|'bmi') {
  210. const seriesMap: Record<string, { names: string[]; accessors: Array<(r:any)=>number>; colors: string[] }> = {
  211. all: { names: ['身高','体重','BMI'], accessors: [ (r: RecordItem) => r.h, (r: RecordItem) => r.w, (r: RecordItem) => r.bmi ], colors: ['#ff6a00', '#007aff', '#28c76f'] },
  212. height: { names: ['身高'], accessors: [ (r: RecordItem) => r.h ], colors: ['#ff6a00'] },
  213. weight: { names: ['体重'], accessors: [ (r: RecordItem) => r.w ], colors: ['#007aff'] },
  214. bmi: { names: ['BMI'], accessors: [ (r: RecordItem) => r.bmi ], colors: ['#28c76f'] }
  215. }
  216. const cfg = seriesMap[metric]
  217. return createUChart({
  218. canvasId: 'bpChart',
  219. vm,
  220. getCanvasSize,
  221. seriesNames: cfg.names,
  222. valueAccessors: cfg.accessors,
  223. colors: cfg.colors
  224. })
  225. }
  226. // 延迟创建 chart:在 mounted 时先读取路由参数(metric),然后创建 chart 并绘制
  227. function initMetricFromRoute() {
  228. try {
  229. // 在 uni-app 中,可通过 getCurrentPages 获取当前页面的 options(包含 query)
  230. const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : []
  231. const currentPage = pages[pages.length - 1] || {}
  232. const opts = (currentPage && (currentPage as any).options) ? (currentPage as any).options : {}
  233. const metricParam = opts.metric || opts?.metric
  234. if (metricParam && ['all', 'height', 'weight', 'bmi'].includes(metricParam)) {
  235. ;(selectedMetric as any).value = metricParam
  236. }
  237. } catch (e) {
  238. console.warn('initMetricFromRoute error', e)
  239. }
  240. }
  241. onMounted(() => {
  242. // 延迟确保DOM渲染完成并设置canvas尺寸
  243. setTimeout(async () => {
  244. await nextTick()
  245. try {
  246. const size = await getCanvasSize()
  247. canvasWidth.value = size.width
  248. canvasHeight.value = size.height
  249. } catch (e) {
  250. console.warn('getCanvasSize failed on mounted', e)
  251. }
  252. // 先从路由读取 metric(如果有),然后创建 chart
  253. initMetricFromRoute()
  254. try {
  255. if (!bpChart) bpChart = createChartForMetric(selectedMetric.value)
  256. } catch (e) {
  257. console.warn('createChartForMetric failed', e)
  258. }
  259. try {
  260. if (bpChart && bpChart.draw) await bpChart.draw(records, current, viewMode)
  261. } catch (e) {
  262. console.warn('bpChart draw failed', e)
  263. }
  264. }, 500)
  265. })
  266. // 监听并更新图表(轻微去抖)
  267. watch([() => current.value], async () => {
  268. setTimeout(async () => {
  269. await bpChart.update(records, current, viewMode)
  270. }, 100)
  271. })
  272. watch([() => records.value], async () => {
  273. setTimeout(async () => {
  274. // 如果图表实例已被替换,根据 current selectedMetric 的 chart 实例更新
  275. try {
  276. if (bpChart && bpChart.update) await bpChart.update(records, current, viewMode)
  277. } catch (e) {
  278. console.warn('bpChart update failed', e)
  279. }
  280. }, 100)
  281. }, { deep: true })
  282. // 监听 selectedMetric 变化,重建图表以使用不同的 series 配置
  283. watch(() => selectedMetric.value, async (val) => {
  284. try {
  285. if (bpChart && bpChart.destroy) {
  286. try { bpChart.destroy() } catch (e) { /* ignore */ }
  287. }
  288. bpChart = createChartForMetric(val)
  289. // small delay to ensure DOM/canvas availability
  290. await nextTick()
  291. try { await bpChart.draw(records, current, viewMode) } catch (e) { console.warn('draw after metric change failed', e) }
  292. } catch (e) {
  293. console.warn('selectedMetric watch error', e)
  294. }
  295. })
  296. onBeforeUnmount(() => {
  297. try { bpChart.destroy() } catch (e) { console.warn('bpChart destroy error', e) }
  298. })
  299. // 强制重建图表(用于切换月份时彻底刷新)
  300. async function rebuildChart() {
  301. try { if (bpChart && bpChart.rebuild) await bpChart.rebuild(records, current, viewMode) } catch (e) { console.warn('rebuildChart failed', e) }
  302. }
  303. // 周/月周期导航与 Picker 处理
  304. async function prevPeriod() {
  305. const d = new Date(current.value)
  306. if (viewMode.value === 'month') {
  307. d.setMonth(d.getMonth() - 1)
  308. } else {
  309. d.setDate(d.getDate() - 7)
  310. }
  311. current.value = d
  312. pickerValue.value = [d.getFullYear() - 2000, d.getMonth()]
  313. records.value = generateMockRecords(d)
  314. await rebuildChart()
  315. }
  316. async function nextPeriod() {
  317. const d = new Date(current.value)
  318. if (viewMode.value === 'month') {
  319. d.setMonth(d.getMonth() + 1)
  320. if (isMonthAfterToday(d)) {
  321. uni.showToast && uni.showToast({ title: '不能查看未来的日期', icon: 'none' })
  322. return
  323. }
  324. } else {
  325. d.setDate(d.getDate() + 7)
  326. if (isWeekAfterToday(d)) {
  327. uni.showToast && uni.showToast({ title: '不能查看未来的日期', icon: 'none' })
  328. return
  329. }
  330. }
  331. current.value = d
  332. pickerValue.value = [d.getFullYear() - 2000, d.getMonth()]
  333. records.value = generateMockRecords(d)
  334. await rebuildChart()
  335. }
  336. async function setViewMode(mode: 'month' | 'week') {
  337. if (viewMode.value !== mode) {
  338. viewMode.value = mode
  339. records.value = generateMockRecords(current.value)
  340. await rebuildChart()
  341. }
  342. }
  343. async function onPickerChange(e: any) {
  344. const val = e?.detail?.value || e
  345. if (Array.isArray(val) && val.length >= 2) {
  346. const y = 2000 + Number(val[0])
  347. const m = Number(val[1])
  348. let d = new Date(y, m, 1)
  349. if (isMonthAfterToday(d)) {
  350. const today = getTodayStart()
  351. uni.showToast && uni.showToast({ title: '不能选择未来的月份,已切换到当前月份', icon: 'none' })
  352. d = new Date(today.getFullYear(), today.getMonth(), 1)
  353. pickerValue.value = [today.getFullYear() - 2000, today.getMonth()]
  354. } else {
  355. pickerValue.value = [Number(val[0]), Number(val[1])]
  356. }
  357. current.value = d
  358. records.value = generateMockRecords(d)
  359. await rebuildChart()
  360. }
  361. }
  362. // 添加逻辑(体格数据)
  363. const showAdd = ref(false)
  364. const addDate = ref(formatPickerDate(new Date()))
  365. const addDateLabel = ref(formatDisplayDate(new Date()))
  366. const addHeight = ref<number | null>(null)
  367. const addWeight = ref<number | null>(null)
  368. function onHUpdate(v: number) { addHeight.value = Math.round(v) }
  369. function onHChange(v: number) { addHeight.value = Math.round(v) }
  370. function onWUpdate(v: number) { addWeight.value = Math.round(v) }
  371. function onWChange(v: number) { addWeight.value = Math.round(v) }
  372. function openAdd() {
  373. showAdd.value = true;
  374. if (!addHeight.value) addHeight.value = 170;
  375. if (!addWeight.value) addWeight.value = 65
  376. }
  377. function closeAdd() {
  378. showAdd.value = false;
  379. addHeight.value = null;
  380. addWeight.value = null
  381. }
  382. function onAddDateChange(e: any) {
  383. const val = e?.detail?.value || e;
  384. const parts = (val || '').split('-')
  385. const y = parseInt(parts[0] || '', 10)
  386. const m = parseInt(parts[1] || '1', 10) - 1
  387. const d = parseInt(parts[2] || '1', 10)
  388. const sel = new Date(y, m, d)
  389. if (isAfterTodayDate(sel)) {
  390. const today = getTodayStart()
  391. uni.showToast && uni.showToast({ title: '不能选择未来的日期,已切换到今天', icon: 'none' })
  392. addDate.value = formatPickerDate(today)
  393. addDateLabel.value = formatDisplayDate(today)
  394. return
  395. }
  396. addDate.value = val;
  397. addDateLabel.value = val.replace(/^(.{10}).*$/, '$1')
  398. }
  399. async function confirmAdd() {
  400. if (!addHeight.value || !addWeight.value) {
  401. uni.showToast && uni.showToast({ title: '请输入身高和体重', icon: 'none' });
  402. return
  403. }
  404. // 检查 BMI 预警(简单阈值)
  405. const bmi = addWeight.value / ((addHeight.value / 100) * (addHeight.value / 100))
  406. if (bmi >= 25) {
  407. uni.showModal({
  408. title: '体重超标',
  409. content: '当前体重指数偏高,建议注意饮食与运动,必要时就医。',
  410. showCancel: false,
  411. confirmText: '知道了'
  412. })
  413. }
  414. const id = `user-${Date.now()}`
  415. const bmiVal = Math.round((Math.round(addWeight.value) / ((Math.round(addHeight.value) / 100) * (Math.round(addHeight.value) / 100))) * 10) / 10
  416. const item: RecordItem = {
  417. id,
  418. date: addDateLabel.value,
  419. h: Math.round(addHeight.value),
  420. w: Math.round(addWeight.value),
  421. bmi: bmiVal
  422. }
  423. const parts = addDate.value.split('-')
  424. const addY = parseInt(parts[0], 10)
  425. const addM = parseInt(parts[1], 10) - 1
  426. const addD = parseInt(parts[2] || '1', 10)
  427. const addDateObj = new Date(addY, addM, addD)
  428. if (isAfterTodayDate(addDateObj)) {
  429. uni.showToast && uni.showToast({ title: '不能添加未来日期的数据', icon: 'none' })
  430. return
  431. }
  432. if (viewMode.value === 'month') {
  433. if (addY === current.value.getFullYear() && addM === current.value.getMonth()) {
  434. records.value = [item, ...records.value]
  435. }
  436. } else {
  437. const addDateObj = new Date(addY, addM, parseInt(parts[2] || '1', 10))
  438. const addWeekStart = getWeekStart(addDateObj)
  439. const curWeekStart = getWeekStart(current.value)
  440. if (addWeekStart.getTime() === curWeekStart.getTime()) {
  441. records.value = [item, ...records.value]
  442. }
  443. }
  444. uni.showToast && uni.showToast({ title: '已添加', icon: 'success' })
  445. closeAdd()
  446. // 新增记录后彻底重建图表,确保像退出再进入一样刷新
  447. try {
  448. await rebuildChart()
  449. } catch (e) {
  450. console.warn('rebuildChart after add failed', e)
  451. }
  452. }
  453. async function confirmDeleteRecord(id: string) {
  454. if (typeof uni !== 'undefined' && uni.showModal) {
  455. uni.showModal({
  456. title: '删除',
  457. content: '确认删除该条记录吗?',
  458. success: async (res: any) => {
  459. if (res.confirm) {
  460. records.value = records.value.filter(r => r.id !== id)
  461. try { await rebuildChart() } catch (e) { console.warn('rebuildChart after delete failed', e) }
  462. }
  463. }
  464. })
  465. } else {
  466. records.value = records.value.filter(r => r.id !== id)
  467. try { await rebuildChart() } catch (e) { console.warn('rebuildChart after delete failed', e) }
  468. }
  469. }
  470. </script>
  471. <style scoped>
  472. .page {
  473. min-height: calc(100vh);
  474. padding-top: calc(var(--status-bar-height) + 44px);
  475. background: #f5f6f8;
  476. box-sizing: border-box
  477. }
  478. .header {
  479. padding: 20rpx 40rpx
  480. }
  481. .month-selector {
  482. display: flex;
  483. align-items: center;
  484. justify-content: center;
  485. gap: 12rpx
  486. }
  487. .period-controls {
  488. display: flex;
  489. flex-direction: column;
  490. align-items: center;
  491. gap: 8rpx;
  492. }
  493. .view-toggle {
  494. display: flex;
  495. gap: 4rpx;
  496. }
  497. .toggle-btn {
  498. padding: 4rpx 12rpx;
  499. border: 1rpx solid #ddd;
  500. background: #f5f5f5;
  501. color: #666;
  502. border-radius: 6rpx;
  503. font-size: 24rpx;
  504. min-width: 60rpx;
  505. text-align: center;
  506. }
  507. .toggle-btn.active {
  508. background: #ff6a00;
  509. color: #fff;
  510. border-color: #ff6a00;
  511. }
  512. .month-label {
  513. font-size: 34rpx;
  514. color: #333
  515. }
  516. .btn {
  517. background: transparent;
  518. border: none;
  519. font-size: 36rpx;
  520. color: #666
  521. }
  522. .content {
  523. padding: 20rpx 24rpx 100rpx 24rpx
  524. }
  525. .chart-wrap {
  526. height: 380rpx;
  527. overflow: hidden; /* 隐藏溢出内容 */
  528. background: #fff;
  529. border-radius: 12rpx;
  530. padding: 24rpx;
  531. margin: 0 24rpx 20rpx 24rpx;
  532. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.03)
  533. }
  534. .chart-header {
  535. font-size: 32rpx;
  536. color: #333;
  537. margin-bottom: 20rpx;
  538. font-weight: 600
  539. }
  540. /* 关键修复:确保canvas样式正确,参考微信小程序示例 */
  541. .chart-canvas {
  542. height: 320rpx;
  543. background-color: #FFFFFF;
  544. display: block;
  545. }
  546. .summary {
  547. padding: 20rpx;
  548. color: #666;
  549. font-size: 28rpx
  550. }
  551. .list {
  552. background: #fff;
  553. border-radius: 12rpx;
  554. padding: 10rpx;
  555. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.03)
  556. }
  557. .empty {
  558. padding: 40rpx;
  559. text-align: center;
  560. color: #999
  561. }
  562. .list-item {
  563. display: flex;
  564. align-items: center;
  565. padding: 20rpx;
  566. border-bottom: 1rpx solid #f0f0f0
  567. }
  568. .list-item .date {
  569. color: #666
  570. }
  571. .list-item .value {
  572. color: #333;
  573. font-weight: 600;
  574. flex: 1;
  575. text-align: right
  576. }
  577. .btn-delete {
  578. width: 80rpx;
  579. height: 60rpx;
  580. min-width: 60rpx;
  581. min-height: 60rpx;
  582. display: inline-flex;
  583. align-items: center;
  584. justify-content: center;
  585. background: #fff0f0;
  586. color: #d9534f;
  587. border: 1rpx solid rgba(217,83,79,0.15);
  588. border-radius: 8rpx;
  589. margin-left: 30rpx
  590. }
  591. .fab {
  592. position: fixed;
  593. right: 28rpx;
  594. bottom: 160rpx;
  595. width: 110rpx;
  596. height: 110rpx;
  597. border-radius: 999px;
  598. background: linear-gradient(180deg, #ff7a00, #ff4a00);
  599. display: flex;
  600. align-items: center;
  601. justify-content: center;
  602. box-shadow: 0 6rpx 18rpx rgba(0, 0, 0, 0.2);
  603. z-index: 1200
  604. }
  605. .fab-inner {
  606. color: #fff;
  607. font-size: 56rpx;
  608. line-height: 56rpx
  609. }
  610. .modal {
  611. position: fixed;
  612. left: 0;
  613. right: 0;
  614. top: 0;
  615. bottom: 0;
  616. display: flex;
  617. align-items: flex-end;
  618. justify-content: center;
  619. z-index: 1300
  620. }
  621. .modal-backdrop {
  622. position: absolute;
  623. left: 0;
  624. right: 0;
  625. top: 0;
  626. bottom: 0;
  627. background: rgba(0, 0, 0, 0.4)
  628. }
  629. .modal-panel {
  630. position: relative;
  631. width: 100%;
  632. background: #fff;
  633. border-top-left-radius: 18rpx;
  634. border-top-right-radius: 18rpx;
  635. padding: 28rpx 24rpx 140rpx 24rpx;
  636. box-shadow: 0 -8rpx 30rpx rgba(0,0,0,0.12)
  637. }
  638. .modal-title {
  639. font-size: 56rpx;
  640. margin-block: 60rpx;
  641. color: #222;
  642. font-weight: 700;
  643. letter-spacing: 1rpx
  644. }
  645. .modal-inner {
  646. max-width: 70%;
  647. margin: 0 auto
  648. }
  649. .form-row {
  650. display: flex;
  651. align-items: center;
  652. justify-content: space-between;
  653. margin-bottom: 34rpx;
  654. padding: 14rpx 0;
  655. font-size: 32rpx
  656. }
  657. .input {
  658. width: 150rpx;
  659. text-align: right;
  660. padding: 16rpx;
  661. border-radius: 14rpx;
  662. border: 1rpx solid #eee;
  663. background: #fff7f0
  664. }
  665. .picker-display {
  666. color: #333
  667. }
  668. .btn-primary {
  669. background: #ff6a00;
  670. color: #fff;
  671. padding: 18rpx 22rpx;
  672. border-radius: 16rpx;
  673. text-align: center;
  674. width: 50%;
  675. box-shadow: 0 10rpx 28rpx rgba(255,106,0,0.18)
  676. }
  677. .drag-handle {
  678. width: 64rpx;
  679. height: 6rpx;
  680. background: rgba(0,0,0,0.08);
  681. border-radius: 999px;
  682. margin: 10rpx auto 14rpx auto
  683. }
  684. .modal-header {
  685. display: flex;
  686. align-items: center;
  687. justify-content: center;
  688. gap: 12rpx;
  689. margin-bottom: 6rpx
  690. }
  691. .label {
  692. color: #666
  693. }
  694. .ruler-wrap {
  695. margin: 12rpx 0
  696. }
  697. .ruler-row {
  698. margin-bottom: 8rpx
  699. }
  700. .fixed-footer {
  701. position: absolute;
  702. left: 0;
  703. right: 0;
  704. bottom: 40rpx;
  705. padding: 0 24rpx
  706. }
  707. .btn-full {
  708. width: 100%;
  709. padding: 18rpx;
  710. border-radius: 12rpx;
  711. }
  712. </style>