record-detail.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="record-detail-page">
  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">{{ 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" style="background-color: #2196F3;"></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. export default {
  71. data() {
  72. return {
  73. recordId: null,
  74. record: null,
  75. aiFoods: [],
  76. confirmedFoods: []
  77. }
  78. },
  79. onLoad: function(options) {
  80. if (options.id) {
  81. this.recordId = parseInt(options.id)
  82. this.loadRecord()
  83. }
  84. },
  85. methods: {
  86. goBack: function() {
  87. uni.navigateBack()
  88. },
  89. loadRecord: function() {
  90. var self = this
  91. var memberId = uni.getStorageSync('currentChildId') || uni.getStorageSync('currentMemberId') || uni.getStorageSync('userId')
  92. var today = self.formatDate(new Date())
  93. getDietDailyRecords({ memberId: memberId, date: today }).then(function(res) {
  94. if (res && res.records) {
  95. var record = res.records.find(function(r) { return r.id === self.recordId })
  96. if (record) {
  97. self.record = record
  98. self.parseAIFoods(record.aiRecognizedFoods)
  99. self.parseConfirmedFoods(record.userConfirmedFoods)
  100. }
  101. }
  102. })
  103. },
  104. parseAIFoods: function(json) {
  105. try {
  106. this.aiFoods = JSON.parse(json || '[]')
  107. } catch (e) {
  108. this.aiFoods = []
  109. }
  110. },
  111. parseConfirmedFoods: function(json) {
  112. try {
  113. this.confirmedFoods = JSON.parse(json || '[]')
  114. } catch (e) {
  115. this.confirmedFoods = []
  116. }
  117. },
  118. formatTime: function(timeStr) {
  119. if (!timeStr) return ''
  120. var d = new Date(timeStr)
  121. if (isNaN(d.getTime())) return timeStr
  122. var h = d.getHours().toString().padStart(2, '0')
  123. var m = d.getMinutes().toString().padStart(2, '0')
  124. return h + ':' + m
  125. },
  126. formatDate: function(date) {
  127. var d = date
  128. var m = (d.getMonth() + 1).toString().padStart(2, '0')
  129. var day = d.getDate().toString().padStart(2, '0')
  130. return d.getFullYear() + '-' + m + '-' + day
  131. },
  132. previewPhoto: function() {
  133. if (!this.record || !this.record.imageUrl) return
  134. uni.previewImage({
  135. urls: [this.record.imageUrl],
  136. current: this.record.imageUrl
  137. })
  138. },
  139. editRecord: function() {
  140. uni.showToast({ title: '编辑功能开发中', icon: 'none' })
  141. },
  142. deleteRecord: function() {
  143. var self = this
  144. uni.showModal({
  145. title: '确认删除',
  146. content: '确定要删除这条饮食记录吗?',
  147. success: function(res) {
  148. if (res.confirm) {
  149. uni.showToast({ title: '已删除', icon: 'success' })
  150. setTimeout(function() {
  151. uni.navigateBack()
  152. }, 1000)
  153. }
  154. }
  155. })
  156. }
  157. }
  158. }
  159. </script>
  160. <style scoped>
  161. .record-detail-page {
  162. min-height: 100vh;
  163. background-color: #F5F7FA;
  164. display: flex;
  165. flex-direction: column;
  166. }
  167. .nav-placeholder {
  168. width: 80rpx;
  169. }
  170. .content {
  171. flex: 1;
  172. padding: 30rpx;
  173. }
  174. .photo-section {
  175. margin-bottom: 30rpx;
  176. border-radius: 20rpx;
  177. overflow: hidden;
  178. }
  179. .detail-photo {
  180. width: 100%;
  181. height: 400rpx;
  182. background-color: #f0f0f0;
  183. }
  184. .card {
  185. display: flex;
  186. background-color: #FFFFFF;
  187. border-radius: 20rpx;
  188. margin-bottom: 30rpx;
  189. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
  190. overflow: hidden;
  191. }
  192. .card-accent {
  193. width: 8rpx;
  194. background-color: #FF8C42;
  195. flex-shrink: 0;
  196. }
  197. .card-body {
  198. flex: 1;
  199. padding: 30rpx;
  200. }
  201. .card-title {
  202. font-size: 28rpx;
  203. font-weight: 600;
  204. color: #333;
  205. margin-bottom: 20rpx;
  206. display: block;
  207. }
  208. .info-row {
  209. display: flex;
  210. justify-content: space-between;
  211. padding: 16rpx 0;
  212. border-bottom: 1rpx solid #f0f0f0;
  213. }
  214. .info-row:last-child {
  215. border-bottom: none;
  216. }
  217. .info-label {
  218. font-size: 26rpx;
  219. color: #666;
  220. }
  221. .info-value {
  222. font-size: 26rpx;
  223. color: #333;
  224. font-weight: 500;
  225. }
  226. .ai-item {
  227. display: flex;
  228. justify-content: space-between;
  229. align-items: center;
  230. padding: 16rpx 0;
  231. border-bottom: 1rpx solid #f0f0f0;
  232. }
  233. .ai-item:last-child {
  234. border-bottom: none;
  235. }
  236. .ai-name {
  237. font-size: 26rpx;
  238. color: #333;
  239. }
  240. .ai-confidence {
  241. display: flex;
  242. align-items: center;
  243. gap: 12rpx;
  244. width: 200rpx;
  245. }
  246. .confidence-bar {
  247. height: 8rpx;
  248. background-color: #2196F3;
  249. border-radius: 4rpx;
  250. flex: 1;
  251. }
  252. .confidence-text {
  253. font-size: 22rpx;
  254. color: #2196F3;
  255. white-space: nowrap;
  256. }
  257. .food-tags {
  258. display: flex;
  259. flex-wrap: wrap;
  260. gap: 16rpx;
  261. }
  262. .food-tag {
  263. padding: 12rpx 24rpx;
  264. background-color: #FFF5EB;
  265. border-radius: 30rpx;
  266. font-size: 24rpx;
  267. color: #FF8C42;
  268. }
  269. .action-area {
  270. display: flex;
  271. gap: 20rpx;
  272. padding: 40rpx 30rpx;
  273. }
  274. .btn-secondary {
  275. flex: 1;
  276. padding: 28rpx 0;
  277. background-color: #FFFFFF;
  278. border: 1rpx solid #ddd;
  279. border-radius: 16rpx;
  280. text-align: center;
  281. font-size: 28rpx;
  282. color: #666;
  283. }
  284. .btn-delete {
  285. flex: 1;
  286. padding: 28rpx 0;
  287. background-color: #FFF3E0;
  288. border-radius: 16rpx;
  289. text-align: center;
  290. font-size: 28rpx;
  291. color: #FF5722;
  292. }
  293. .empty-state {
  294. flex: 1;
  295. display: flex;
  296. align-items: center;
  297. justify-content: center;
  298. font-size: 28rpx;
  299. color: #999;
  300. }
  301. </style>