record-detail.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view class="record-detail-page" :style="{ '--font-scale': fontScale }">
  3. <scroll-view class="content" scroll-y v-if="record">
  4. <!-- 照片 -->
  5. <view class="photo-section" v-if="record.imageUrl">
  6. <image :src="record.imageUrl" mode="aspectFill" class="detail-photo" @tap="previewPhoto" />
  7. </view>
  8. <!-- 基本信息 -->
  9. <view class="card info-card">
  10. <view class="card-accent"></view>
  11. <view class="card-body">
  12. <text class="card-title">基本信息</text>
  13. <view class="info-row">
  14. <text class="info-label">餐次</text>
  15. <text class="info-value">{{ mealLabel(record.mealType) }}</text>
  16. </view>
  17. <view class="info-row">
  18. <text class="info-label">记录方式</text>
  19. <text class="info-value">{{ record.recordMethod === 'photo' ? '📷 拍照识别' : '✏️ 手动记录' }}</text>
  20. </view>
  21. <view class="info-row">
  22. <text class="info-label">记录时间</text>
  23. <text class="info-value">{{ formatTime(record.createdAt) }}</text>
  24. </view>
  25. <view class="info-row" v-if="record.notes">
  26. <text class="info-label">备注</text>
  27. <text class="info-value">{{ record.notes }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- AI识别结果 -->
  32. <view class="card ai-card" v-if="record.aiRecognizedFoods">
  33. <view class="card-accent card-accent--ai"></view>
  34. <view class="card-body">
  35. <text class="card-title">识别结果</text>
  36. <view class="ai-item" v-for="(item, index) in aiFoods" :key="index">
  37. <text class="ai-name">{{ item.name }}</text>
  38. <view class="ai-confidence">
  39. <text class="confidence-bar" :style="'width:' + (item.confidence * 100) + '%'"></text>
  40. <text class="confidence-text">{{ (item.confidence * 100).toFixed(0) }}%</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 用户确认食材 -->
  46. <view class="card foods-card">
  47. <view class="card-accent"></view>
  48. <view class="card-body">
  49. <text class="card-title">确认食材</text>
  50. <view class="food-tags">
  51. <view class="food-tag" v-for="(food, index) in confirmedFoods" :key="index">
  52. <text class="food-name">{{ food.name }}</text>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 操作按钮 -->
  58. <view class="action-area">
  59. <view class="btn-secondary" @tap="editRecord">编辑记录</view>
  60. <view class="btn-delete" @tap="deleteRecord">删除记录</view>
  61. </view>
  62. </scroll-view>
  63. <view class="empty-state" v-else>
  64. <text>加载中...</text>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import { getDietDailyRecords } from '@/utils/api.js'
  70. import { parseDate } from '@/utils/format.js'
  71. import shareMixin from '@/components/share-mixin.js'
  72. import fontScaleMixin from '@/mixins/font-scale.js'
  73. export default {
  74. mixins: [shareMixin, fontScaleMixin],
  75. data() {
  76. return {
  77. recordId: null,
  78. record: null,
  79. aiFoods: [],
  80. confirmedFoods: []
  81. }
  82. },
  83. onLoad: function(options) {
  84. if (options.id) {
  85. this.recordId = parseInt(options.id)
  86. this.loadRecord()
  87. }
  88. },
  89. methods: {
  90. goBack: function() {
  91. uni.navigateBack()
  92. },
  93. loadRecord: function() {
  94. var self = this
  95. var memberId = uni.getStorageSync('currentChildId') || uni.getStorageSync('currentMemberId') || uni.getStorageSync('userId')
  96. var today = self.formatDate(new Date())
  97. getDietDailyRecords({ memberId: memberId, date: today }).then(function(res) {
  98. if (res && res.records) {
  99. var record = res.records.find(function(r) { return r.id === self.recordId })
  100. if (record) {
  101. self.record = record
  102. self.parseAIFoods(record.aiRecognizedFoods)
  103. self.parseConfirmedFoods(record.userConfirmedFoods)
  104. self.setShareInfo('饮食打卡记录', '/pages/diet/record-detail?id=' + self.recordId)
  105. }
  106. }
  107. })
  108. },
  109. parseAIFoods: function(json) {
  110. try {
  111. this.aiFoods = JSON.parse(json || '[]')
  112. } catch (e) {
  113. this.aiFoods = []
  114. }
  115. },
  116. parseConfirmedFoods: function(json) {
  117. try {
  118. this.confirmedFoods = JSON.parse(json || '[]')
  119. } catch (e) {
  120. this.confirmedFoods = []
  121. }
  122. },
  123. formatTime: function(timeStr) {
  124. if (!timeStr) return ''
  125. var d = parseDate(timeStr)
  126. if (!d) return timeStr
  127. var h = d.getHours().toString().padStart(2, '0')
  128. var m = d.getMinutes().toString().padStart(2, '0')
  129. return h + ':' + m
  130. },
  131. mealLabel: function(t) {
  132. var m = { breakfast: '早餐', lunch: '午餐', dinner: '晚餐', snack: '加餐' }
  133. if (!t) return '饮食'
  134. // 兼容逗号拼接多餐次(breakfast,lunch → 早餐、午餐);未知值原样输出
  135. var parts = String(t).split(',')
  136. var labels = []
  137. for (var i = 0; i < parts.length; i++) {
  138. var v = parts[i] && parts[i].trim()
  139. if (!v) continue
  140. labels.push(m[v] || v)
  141. }
  142. return labels.length > 0 ? labels.join('、') : '饮食'
  143. },
  144. formatDate: function(date) {
  145. var d = date
  146. var m = (d.getMonth() + 1).toString().padStart(2, '0')
  147. var day = d.getDate().toString().padStart(2, '0')
  148. return d.getFullYear() + '-' + m + '-' + day
  149. },
  150. previewPhoto: function() {
  151. if (!this.record || !this.record.imageUrl) return
  152. uni.previewImage({
  153. urls: [this.record.imageUrl],
  154. current: this.record.imageUrl
  155. })
  156. },
  157. editRecord: function() {
  158. uni.showToast({ title: '编辑功能开发中', icon: 'none' })
  159. },
  160. deleteRecord: function() {
  161. var self = this
  162. uni.showModal({
  163. title: '确认删除',
  164. content: '确定要删除这条饮食记录吗?',
  165. success: function(res) {
  166. if (res.confirm) {
  167. uni.showToast({ title: '已删除', icon: 'success' })
  168. setTimeout(function() {
  169. uni.navigateBack()
  170. }, 1000)
  171. }
  172. }
  173. })
  174. }
  175. }
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. .record-detail-page {
  180. min-height: 100vh;
  181. background-color: $app-bg;
  182. display: flex;
  183. flex-direction: column;
  184. }
  185. .nav-placeholder {
  186. width: 80rpx;
  187. }
  188. .content {
  189. flex: 1;
  190. padding: $uni-space-page;
  191. }
  192. .photo-section {
  193. margin-bottom: $uni-space-lg;
  194. border-radius: 24rpx;
  195. overflow: hidden;
  196. }
  197. .detail-photo {
  198. width: 100%;
  199. height: 400rpx;
  200. background-color: $facade-fill;
  201. }
  202. .card {
  203. display: flex;
  204. background-color: $app-surface;
  205. border-radius: 24rpx;
  206. margin-bottom: $uni-space-lg;
  207. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  208. overflow: hidden;
  209. }
  210. .card-accent {
  211. width: 8rpx;
  212. background-color: $dim-body;
  213. flex-shrink: 0;
  214. }
  215. .card-accent--ai {
  216. background-color: $mat-blue-base;
  217. }
  218. .card-body {
  219. flex: 1;
  220. padding: $uni-space-page;
  221. }
  222. .card-title {
  223. font-size: calc(28rpx * var(--font-scale, 1));
  224. font-weight: 600;
  225. color: $facade-text-strong;
  226. margin-bottom: 20rpx;
  227. display: block;
  228. }
  229. .info-row {
  230. display: flex;
  231. justify-content: space-between;
  232. padding: 16rpx 0;
  233. border-bottom: 1rpx solid $facade-fill;
  234. }
  235. .info-row:last-child {
  236. border-bottom: none;
  237. }
  238. .info-label {
  239. font-size: calc(26rpx * var(--font-scale, 1));
  240. color: $facade-text-body;
  241. }
  242. .info-value {
  243. font-size: calc(26rpx * var(--font-scale, 1));
  244. color: $facade-text-strong;
  245. font-weight: 500;
  246. }
  247. .ai-item {
  248. display: flex;
  249. justify-content: space-between;
  250. align-items: center;
  251. padding: 16rpx 0;
  252. border-bottom: 1rpx solid $facade-fill;
  253. }
  254. .ai-item:last-child {
  255. border-bottom: none;
  256. }
  257. .ai-name {
  258. font-size: calc(26rpx * var(--font-scale, 1));
  259. color: $facade-text-strong;
  260. }
  261. .ai-confidence {
  262. display: flex;
  263. align-items: center;
  264. gap: 12rpx;
  265. width: 200rpx;
  266. }
  267. .confidence-bar {
  268. height: 8rpx;
  269. background-color: $mat-blue-base;
  270. border-radius: 8rpx;
  271. flex: 1;
  272. }
  273. .confidence-text {
  274. font-size: calc(22rpx * var(--font-scale, 1));
  275. color: $mat-blue-base;
  276. white-space: nowrap;
  277. }
  278. .food-tags {
  279. display: flex;
  280. flex-wrap: wrap;
  281. gap: 16rpx;
  282. }
  283. .food-tag {
  284. padding: 12rpx 24rpx;
  285. background-color: $flat-card;
  286. border-radius: 24rpx;
  287. font-size: calc(24rpx * var(--font-scale, 1));
  288. color: $dim-body;
  289. }
  290. .action-area {
  291. display: flex;
  292. gap: 20rpx;
  293. padding: 40rpx $uni-space-page;
  294. }
  295. .btn-secondary {
  296. flex: 1;
  297. padding: 28rpx 0;
  298. background-color: $app-surface;
  299. border: 1rpx solid $facade-border-soft;
  300. border-radius: 16rpx;
  301. text-align: center;
  302. font-size: calc(28rpx * var(--font-scale, 1));
  303. color: $facade-text-body;
  304. }
  305. .btn-delete {
  306. flex: 1;
  307. padding: 28rpx 0;
  308. background-color: $fortune-1-tint;
  309. border-radius: 16rpx;
  310. text-align: center;
  311. font-size: calc(28rpx * var(--font-scale, 1));
  312. color: $mat-deep-orange;
  313. }
  314. .empty-state {
  315. flex: 1;
  316. display: flex;
  317. align-items: center;
  318. justify-content: center;
  319. font-size: calc(28rpx * var(--font-scale, 1));
  320. color: $facade-text-muted;
  321. }
  322. </style>