index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <scroll-view class="content" scroll-y :style="{ '--font-scale': fontScale }">
  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 { BrandColors } from '../../../utils/brand-colors.js'
  195. import config from '@/config.js'
  196. import { parseDate } from '@/utils/format.js'
  197. import fontScaleMixin from '@/mixins/font-scale.js'
  198. export default {
  199. mixins: [fontScaleMixin],
  200. data() {
  201. return {
  202. loading: true,
  203. profile: {},
  204. recommendations: {}
  205. }
  206. },
  207. computed: {
  208. body() {
  209. return this.profile.body_metrics || {}
  210. },
  211. mind() {
  212. return this.profile.mind_metrics || {}
  213. },
  214. wisdom() {
  215. return this.profile.wisdom_metrics || {}
  216. },
  217. action() {
  218. return this.profile.action_metrics || {}
  219. },
  220. problemDomains() {
  221. return this.profile.problem_domains || []
  222. }
  223. },
  224. onLoad() {
  225. this.loadProfile()
  226. },
  227. methods: {
  228. goBack() { uni.navigateBack() },
  229. loadProfile() {
  230. var self = this
  231. self.loading = true
  232. var token = uni.getStorageSync('token')
  233. uni.request({
  234. url: config.API_BASE_URL + '/api/profile/my',
  235. method: 'POST',
  236. data: {},
  237. header: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token },
  238. success: function(res) {
  239. self.loading = false
  240. if (res.data && res.data.code === 200 && res.data.data) {
  241. self.profile = res.data.data
  242. self.recommendations = res.data.data
  243. }
  244. },
  245. fail: function() {
  246. self.loading = false
  247. uni.showToast({ title: '加载失败', icon: 'none' })
  248. }
  249. })
  250. },
  251. dimName(dim) {
  252. var m = { body: '身', wisdom: '智', mind: '心', action: '行', wealth: '富' }
  253. return m[dim] || dim
  254. },
  255. dimColor(dim) {
  256. var m = { body: BrandColors.body, wisdom: BrandColors.wisdom, mind: BrandColors.mind, action: BrandColors.success, wealth: BrandColors.wealth }
  257. return m[dim] || BrandColors.textMuted
  258. },
  259. domainLabel(d) {
  260. var m = { sleep: '睡眠', attention: '注意力', emotion: '情绪' }
  261. return m[d] || d
  262. },
  263. formatDate(dateStr) {
  264. if (!dateStr) return ''
  265. var d = parseDate(dateStr)
  266. if (!d) return dateStr
  267. var y = d.getFullYear()
  268. var m2 = (d.getMonth() + 1).toString().padStart(2, '0')
  269. var day = d.getDate().toString().padStart(2, '0')
  270. return y + '-' + m2 + '-' + day
  271. },
  272. formatDateTime(dateStr) {
  273. if (!dateStr) return ''
  274. var d = parseDate(dateStr)
  275. if (!d) return dateStr
  276. var dt = dateStr.toString()
  277. if (dt.length >= 19) return dt.substring(0, 19).replace('T', ' ')
  278. return this.formatDate(dateStr)
  279. }
  280. }
  281. }
  282. </script>
  283. <style scoped lang="scss">
  284. .page { min-height: 100vh; background: $uni-primary-pale; }
  285. .content { height: calc(100vh - 88rpx); }
  286. .card { margin: 16rpx 24rpx; background: $app-surface; border-radius: 24rpx; overflow: hidden; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06); }
  287. .card-accent { height: 6rpx; background: linear-gradient(90deg, $dim-body, $brand-primary); }
  288. .card-body { padding: 24rpx; }
  289. .card-title { font-size: calc(28rpx * var(--font-scale, 1)); font-weight: bold; color: $facade-text-strong; margin-bottom: 16rpx; display: block; }
  290. .member-header { display: flex; align-items: baseline; gap: 8rpx; margin-bottom: 8rpx; }
  291. .member-name { font-size: calc(36rpx * var(--font-scale, 1)); font-weight: bold; color: $facade-text-strong; }
  292. .member-age { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-muted; }
  293. .computed-at { font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-ghost-light; }
  294. .dimension-row { display: flex; align-items: center; gap: 12rpx; margin-bottom: 14rpx; }
  295. .dim-label { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-body; width: 60rpx; flex-shrink: 0; }
  296. .dim-bar-bg { flex: 1; height: 20rpx; background: $facade-fill; border-radius: 8rpx; overflow: hidden; }
  297. .dim-bar-fill { height: 100%; border-radius: 8rpx; transition: width 0.3s; }
  298. .dim-val { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-strong; font-weight: bold; width: 48rpx; text-align: right; flex-shrink: 0; }
  299. .metric-row { display: flex; gap: 16rpx; margin-bottom: 12rpx; }
  300. .metric-item { flex: 1; text-align: center; padding: 16rpx 8rpx; background: $facade-fill-ghost; border-radius: 16rpx; }
  301. .metric-val { font-size: calc(32rpx * var(--font-scale, 1)); font-weight: bold; color: $brand-primary; display: block; }
  302. .metric-label { font-size: calc(20rpx * var(--font-scale, 1)); color: $facade-text-muted; margin-top: 4rpx; display: block; }
  303. .assessment-date { font-size: calc(20rpx * var(--font-scale, 1)); color: $facade-text-ghost-light; margin-top: 8rpx; display: block; }
  304. .domain-tags { display: flex; flex-wrap: wrap; gap: 12rpx; }
  305. .domain-tag { padding: 8rpx 20rpx; border-radius: 24rpx; background: $fortune-1-tint; border: 1rpx solid $brand-primary; }
  306. .domain-tag text { font-size: calc(24rpx * var(--font-scale, 1)); color: $brand-primary; }
  307. .rec-section { margin-top: 16rpx; }
  308. .rec-title { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-body; margin-bottom: 10rpx; display: block; }
  309. .rec-list { display: flex; flex-direction: column; gap: 8rpx; }
  310. .rec-item { display: flex; justify-content: space-between; align-items: center; padding: 12rpx 0; border-bottom: 1rpx solid $facade-fill-2; }
  311. .rec-item-title { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-strong; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  312. .rec-item-type { font-size: calc(22rpx * var(--font-scale, 1)); color: $facade-text-muted; flex-shrink: 0; margin-left: 16rpx; }
  313. .empty-state { text-align: center; padding: 80rpx 0; }
  314. .empty-text { font-size: calc(28rpx * var(--font-scale, 1)); color: $facade-text-muted; display: block; }
  315. .empty-hint { font-size: calc(24rpx * var(--font-scale, 1)); color: $facade-text-ghost; margin-top: 8rpx; display: block; }
  316. </style>