record-detail.vue 7.8 KB

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