index.vue 14 KB

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