index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <scroll-view class="content" scroll-y>
  3. <!-- 基本信息 -->
  4. <view class="card" v-if="profile.member">
  5. <view class="card-accent"></view>
  6. <view class="card-body">
  7. <view class="member-header">
  8. <text class="member-name">{{ profile.member.name || '未知' }}</text>
  9. <text class="member-age" v-if="profile.member.age"> {{ profile.member.age }}岁</text>
  10. </view>
  11. <text class="computed-at" v-if="profile.computed_at">更新于 {{ formatDateTime(profile.computed_at) }}</text>
  12. </view>
  13. </view>
  14. <!-- 五维评分 -->
  15. <view class="card">
  16. <view class="card-accent"></view>
  17. <view class="card-body">
  18. <text class="card-title">五维能量</text>
  19. <view class="dimension-row" v-for="(score, dim) in profile.dimension_scores" :key="dim">
  20. <text class="dim-label">{{ dimName(dim) }}</text>
  21. <view class="dim-bar-bg">
  22. <view class="dim-bar-fill" :style="{ width: score + '%', background: dimColor(dim) }"></view>
  23. </view>
  24. <text class="dim-val">{{ score }}</text>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 身体指标 -->
  29. <view class="card">
  30. <view class="card-accent"></view>
  31. <view class="card-body">
  32. <text class="card-title">身体指标</text>
  33. <view class="metric-row">
  34. <view class="metric-item">
  35. <text class="metric-val">{{ body.sleep_dur_avg || '-' }}</text>
  36. <text class="metric-label">平均睡眠(h)</text>
  37. </view>
  38. <view class="metric-item">
  39. <text class="metric-val">{{ body.exercise_count_week || 0 }}</text>
  40. <text class="metric-label">周运动(次)</text>
  41. </view>
  42. <view class="metric-item">
  43. <text class="metric-val">{{ body.water_intake_avg_ml || '-' }}</text>
  44. <text class="metric-label">日均饮水(ml)</text>
  45. </view>
  46. </view>
  47. <view class="metric-row" v-if="body.deep_sleep_pct != null">
  48. <view class="metric-item">
  49. <text class="metric-val">{{ body.deep_sleep_pct }}%</text>
  50. <text class="metric-label">深睡占比</text>
  51. </view>
  52. <view class="metric-item">
  53. <text class="metric-val">{{ body.meal_records_count || 0 }}</text>
  54. <text class="metric-label">月饮食记录</text>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 心理指标 -->
  60. <view class="card">
  61. <view class="card-accent"></view>
  62. <view class="card-body">
  63. <text class="card-title">心理指标</text>
  64. <view class="metric-row">
  65. <view class="metric-item">
  66. <text class="metric-val">{{ mind.emotion_joy_ratio != null ? (mind.emotion_joy_ratio * 100).toFixed(0) + '%' : '-' }}</text>
  67. <text class="metric-label">正向情绪占比</text>
  68. </view>
  69. <view class="metric-item">
  70. <text class="metric-val">{{ mind.stress_avg || '-' }}</text>
  71. <text class="metric-label">平均压力(1-10)</text>
  72. </view>
  73. </view>
  74. <view class="metric-row">
  75. <view class="metric-item">
  76. <text class="metric-val">{{ mind.energy_avg || '-' }}</text>
  77. <text class="metric-label">平均精力(1-10)</text>
  78. </view>
  79. <view class="metric-item">
  80. <text class="metric-val">{{ mind.mood_score_avg || '-' }}</text>
  81. <text class="metric-label">平均心情效价</text>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. <!-- 能力测评 -->
  87. <view class="card" v-if="wisdom.overall_score != null">
  88. <view class="card-accent"></view>
  89. <view class="card-body">
  90. <text class="card-title">能力测评</text>
  91. <view class="metric-row">
  92. <view class="metric-item">
  93. <text class="metric-val">{{ wisdom.overall_score }}</text>
  94. <text class="metric-label">综合得分</text>
  95. </view>
  96. <view class="metric-item">
  97. <text class="metric-val">{{ wisdom.attention_score || '-' }}</text>
  98. <text class="metric-label">注意力</text>
  99. </view>
  100. <view class="metric-item">
  101. <text class="metric-val">{{ wisdom.focus_score || '-' }}</text>
  102. <text class="metric-label">专注力</text>
  103. </view>
  104. </view>
  105. <view class="metric-row" v-if="wisdom.game_avg_score_7d != null">
  106. <view class="metric-item">
  107. <text class="metric-val">{{ wisdom.game_avg_score_7d }}</text>
  108. <text class="metric-label">近7天游戏均分</text>
  109. </view>
  110. <view class="metric-item">
  111. <text class="metric-val">{{ wisdom.game_count_7d || 0 }}</text>
  112. <text class="metric-label">近7天游戏次数</text>
  113. </view>
  114. </view>
  115. <text class="assessment-date" v-if="wisdom.assessment_date">测评时间: {{ formatDate(wisdom.assessment_date) }}</text>
  116. </view>
  117. </view>
  118. <!-- 行为指标 -->
  119. <view class="card">
  120. <view class="card-accent"></view>
  121. <view class="card-body">
  122. <text class="card-title">行为活跃</text>
  123. <view class="metric-row">
  124. <view class="metric-item">
  125. <text class="metric-val">{{ (action.task_completion_rate * 100).toFixed(0) }}%</text>
  126. <text class="metric-label">任务完成率</text>
  127. </view>
  128. <view class="metric-item">
  129. <text class="metric-val">{{ action.checkin_streak || 0 }}</text>
  130. <text class="metric-label">连续打卡(天)</text>
  131. </view>
  132. <view class="metric-item">
  133. <text class="metric-val">{{ action.points_velocity_7d || 0 }}</text>
  134. <text class="metric-label">7日积分</text>
  135. </view>
  136. </view>
  137. </view>
  138. </view>
  139. <!-- 关注问题域 -->
  140. <view class="card" v-if="problemDomains && problemDomains.length > 0">
  141. <view class="card-accent"></view>
  142. <view class="card-body">
  143. <text class="card-title">关注方向</text>
  144. <view class="domain-tags">
  145. <view class="domain-tag" v-for="d in problemDomains" :key="d">
  146. <text>{{ domainLabel(d) }}</text>
  147. </view>
  148. </view>
  149. </view>
  150. </view>
  151. <!-- 推荐内容 -->
  152. <view class="card" v-if="recommendations.tasks && recommendations.tasks.length > 0">
  153. <view class="card-accent"></view>
  154. <view class="card-body">
  155. <text class="card-title">为你推荐</text>
  156. <!-- 任务推荐 -->
  157. <view class="rec-section" v-if="recommendations.tasks.length > 0">
  158. <text class="rec-title">📋 推荐任务</text>
  159. <view class="rec-list">
  160. <view class="rec-item" v-for="item in recommendations.tasks" :key="item.id">
  161. <text class="rec-item-title">{{ item.title }}</text>
  162. <text class="rec-item-type">{{ item.category }}</text>
  163. </view>
  164. </view>
  165. </view>
  166. <!-- 文章推荐 -->
  167. <view class="rec-section" v-if="recommendations.articles && recommendations.articles.length > 0">
  168. <text class="rec-title">📖 推荐文章</text>
  169. <view class="rec-list">
  170. <view class="rec-item" v-for="item in recommendations.articles" :key="item.id">
  171. <text class="rec-item-title">{{ item.title }}</text>
  172. </view>
  173. </view>
  174. </view>
  175. <!-- 活动推荐 -->
  176. <view class="rec-section" v-if="recommendations.activities && recommendations.activities.length > 0">
  177. <text class="rec-title">🎯 推荐活动</text>
  178. <view class="rec-list">
  179. <view class="rec-item" v-for="item in recommendations.activities" :key="item.id">
  180. <text class="rec-item-title">{{ item.title }}</text>
  181. </view>
  182. </view>
  183. </view>
  184. </view>
  185. </view>
  186. <!-- 空状态 -->
  187. <view class="empty-state" v-if="!profile.member && !loading">
  188. <text class="empty-text">暂无画像数据</text>
  189. <text class="empty-hint">完成打卡后自动生成</text>
  190. </view>
  191. </scroll-view>
  192. </template>
  193. <script>
  194. import config from '../../config'
  195. import { parseDate } from '../../utils/format.js'
  196. export default {
  197. data() {
  198. return {
  199. loading: true,
  200. profile: {},
  201. recommendations: {}
  202. }
  203. },
  204. computed: {
  205. body() {
  206. return this.profile.body_metrics || {}
  207. },
  208. mind() {
  209. return this.profile.mind_metrics || {}
  210. },
  211. wisdom() {
  212. return this.profile.wisdom_metrics || {}
  213. },
  214. action() {
  215. return this.profile.action_metrics || {}
  216. },
  217. problemDomains() {
  218. return this.profile.problem_domains || []
  219. }
  220. },
  221. onLoad() {
  222. this.loadProfile()
  223. },
  224. methods: {
  225. goBack() { uni.navigateBack() },
  226. loadProfile() {
  227. var self = this
  228. self.loading = true
  229. var token = uni.getStorageSync('token')
  230. uni.request({
  231. url: config.API_BASE_URL + '/api/profile/my',
  232. method: 'POST',
  233. data: {},
  234. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  235. success: function(res) {
  236. self.loading = false
  237. if (res.data && res.data.code === 200 && res.data.data) {
  238. self.profile = res.data.data
  239. self.recommendations = res.data.data
  240. }
  241. },
  242. fail: function() {
  243. self.loading = false
  244. uni.showToast({ title: '加载失败', icon: 'none' })
  245. }
  246. })
  247. },
  248. dimName(dim) {
  249. var m = { body: '身', wisdom: '智', mind: '心', action: '行', wealth: '富' }
  250. return m[dim] || dim
  251. },
  252. dimColor(dim) {
  253. var m = { body: '#FF8C42', wisdom: '#6366F1', mind: '#FF6B9D', action: '#10B981', wealth: '#F59E0B' }
  254. return m[dim] || '#999'
  255. },
  256. domainLabel(d) {
  257. var m = { sleep: '睡眠', attention: '注意力', emotion: '情绪' }
  258. return m[d] || d
  259. },
  260. formatDate(dateStr) {
  261. if (!dateStr) return ''
  262. var d = parseDate(dateStr)
  263. if (!d) return dateStr
  264. var y = d.getFullYear()
  265. var m2 = (d.getMonth() + 1).toString().padStart(2, '0')
  266. var day = d.getDate().toString().padStart(2, '0')
  267. return y + '-' + m2 + '-' + day
  268. },
  269. formatDateTime(dateStr) {
  270. if (!dateStr) return ''
  271. var d = parseDate(dateStr)
  272. if (!d) return dateStr
  273. var dt = dateStr.toString()
  274. if (dt.length >= 19) return dt.substring(0, 19).replace('T', ' ')
  275. return this.formatDate(dateStr)
  276. }
  277. }
  278. }
  279. </script>
  280. <style scoped>
  281. .page { min-height: 100vh; background: #FFF7ED; }
  282. .content { height: calc(100vh - 88rpx); }
  283. .card { margin: 16rpx 24rpx; background: #fff; border-radius: 20rpx; overflow: hidden; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06); }
  284. .card-accent { height: 6rpx; background: linear-gradient(90deg, #FF8C42, #F97316); }
  285. .card-body { padding: 24rpx; }
  286. .card-title { font-size: 28rpx; font-weight: bold; color: #333; margin-bottom: 16rpx; display: block; }
  287. .member-header { display: flex; align-items: baseline; gap: 8rpx; margin-bottom: 8rpx; }
  288. .member-name { font-size: 36rpx; font-weight: bold; color: #333; }
  289. .member-age { font-size: 26rpx; color: #999; }
  290. .computed-at { font-size: 22rpx; color: #bbb; }
  291. .dimension-row { display: flex; align-items: center; gap: 12rpx; margin-bottom: 14rpx; }
  292. .dim-label { font-size: 24rpx; color: #666; width: 60rpx; flex-shrink: 0; }
  293. .dim-bar-bg { flex: 1; height: 20rpx; background: #f0f0f0; border-radius: 10rpx; overflow: hidden; }
  294. .dim-bar-fill { height: 100%; border-radius: 10rpx; transition: width 0.3s; }
  295. .dim-val { font-size: 24rpx; color: #333; font-weight: bold; width: 48rpx; text-align: right; flex-shrink: 0; }
  296. .metric-row { display: flex; gap: 16rpx; margin-bottom: 12rpx; }
  297. .metric-item { flex: 1; text-align: center; padding: 16rpx 8rpx; background: #FAFAFA; border-radius: 12rpx; }
  298. .metric-val { font-size: 32rpx; font-weight: bold; color: #F97316; display: block; }
  299. .metric-label { font-size: 20rpx; color: #999; margin-top: 4rpx; display: block; }
  300. .assessment-date { font-size: 20rpx; color: #bbb; margin-top: 8rpx; display: block; }
  301. .domain-tags { display: flex; flex-wrap: wrap; gap: 12rpx; }
  302. .domain-tag { padding: 8rpx 20rpx; border-radius: 20rpx; background: #FFF3E0; border: 1rpx solid #F97316; }
  303. .domain-tag text { font-size: 24rpx; color: #F97316; }
  304. .rec-section { margin-top: 16rpx; }
  305. .rec-title { font-size: 26rpx; color: #666; margin-bottom: 10rpx; display: block; }
  306. .rec-list { display: flex; flex-direction: column; gap: 8rpx; }
  307. .rec-item { display: flex; justify-content: space-between; align-items: center; padding: 12rpx 0; border-bottom: 1rpx solid #f5f5f5; }
  308. .rec-item-title { font-size: 26rpx; color: #333; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  309. .rec-item-type { font-size: 22rpx; color: #999; flex-shrink: 0; margin-left: 16rpx; }
  310. .empty-state { text-align: center; padding: 80rpx 0; }
  311. .empty-text { font-size: 28rpx; color: #999; display: block; }
  312. .empty-hint { font-size: 24rpx; color: #ccc; margin-top: 8rpx; display: block; }
  313. </style>