profile.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view class="container">
  3. <!-- Tabbar 切换过渡页 -->
  4. <tab-transition v-if="showTabTransition" dimCode="wealth" />
  5. <!-- ===== 未登录状态 ===== -->
  6. <view v-if="!isLoggedIn" class="login-prompt">
  7. <view class="prompt-icon">👤</view>
  8. <text class="prompt-title">登录浠艾福</text>
  9. <text class="prompt-desc">登录后可查看个人资料、积分记录等</text>
  10. <button class="login-btn" @click="goLogin">登录 / 注册</button>
  11. </view>
  12. <!-- ===== 已登录状态 ===== -->
  13. <template v-else>
  14. <!-- 用户卡片 -->
  15. <ProfileHeader @avatar-click="goToEditInfo" />
  16. <!-- 成长报告 -->
  17. <ProfileGrowth />
  18. <!-- 成就徽章 -->
  19. <ProfileBadges />
  20. <!-- 健康等级称号(P2-1) -->
  21. <HealthBadge
  22. v-if="levelInfo"
  23. :levelInfo="levelInfo"
  24. :score="score"
  25. :progress="progress"
  26. :nextLevel="nextLevel"
  27. :streakDays="streakDays" />
  28. <!-- 健康故事时间线(P2-1) -->
  29. <HealthTimeline :events="timelineEvents" />
  30. <!-- 菜单列表(仅个人信息 + 设置,不含服务/商城板块) -->
  31. <ProfileMenu :role="role" :show-services="false" @invite-generate="onInviteGenerate" />
  32. </template>
  33. <AIFloatingAvatar />
  34. </view>
  35. </template>
  36. <script>
  37. import TabTransition from '../../components/tab-transition.vue'
  38. import ProfileHeader from './components/ProfileHeader.vue'
  39. import ProfileBadges from './components/ProfileBadges.vue'
  40. import ProfileGrowth from './components/ProfileGrowth.vue'
  41. import ProfileMenu from './components/ProfileMenu.vue'
  42. import AIFloatingAvatar from '../../components/AIFloatingAvatar.vue'
  43. import HealthBadge from '../../components/HealthBadge.vue'
  44. import HealthTimeline from '../../components/HealthTimeline.vue'
  45. import { getHealthScoreInfo, getHealthTimeline } from '../../utils/api.js'
  46. export default {
  47. components: {
  48. TabTransition,
  49. ProfileHeader,
  50. ProfileBadges,
  51. ProfileGrowth,
  52. ProfileMenu,
  53. AIFloatingAvatar,
  54. HealthBadge,
  55. HealthTimeline
  56. },
  57. data() {
  58. return {
  59. shareData: null,
  60. showTabTransition: true,
  61. selectedMascot: '',
  62. currentMascotName: '小助手',
  63. // P2-1 身份重塑
  64. levelInfo: null,
  65. score: 0,
  66. progress: 0,
  67. nextLevel: null,
  68. streakDays: 0,
  69. timelineEvents: []
  70. }
  71. },
  72. computed: {
  73. isLoggedIn() {
  74. return !!uni.getStorageSync('token')
  75. },
  76. role() {
  77. return uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
  78. }
  79. },
  80. onShareAppMessage() {
  81. if (this.shareData) {
  82. return {
  83. title: this.shareData.title,
  84. path: this.shareData.path,
  85. imageUrl: '/static/invite-card.png'
  86. }
  87. }
  88. },
  89. onShow() {
  90. this.showTabTransition = true
  91. if (!uni.getStorageSync('token')) {
  92. this._watchPageReady()
  93. return
  94. }
  95. this.loadMascot()
  96. const currentRole = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
  97. if (currentRole === 'teacher') {
  98. uni.redirectTo({ url: '/pages/teacher/teacher-profile' })
  99. }
  100. this.loadHealthScoreData()
  101. this._watchPageReady()
  102. },
  103. methods: {
  104. goLogin() {
  105. uni.navigateTo({ url: '/pages/login/login' })
  106. },
  107. onInviteGenerate(shareData) {
  108. this.shareData = shareData
  109. },
  110. changeMascot(mascot) {
  111. if (this.selectedMascot === mascot) return;
  112. uni.request({
  113. url: this.$config.API_BASE_URL + '/api/user/mascot/set',
  114. method: 'POST',
  115. header: { Authorization: 'Bearer ' + uni.getStorageSync('token') },
  116. data: { mascot },
  117. success: (res) => {
  118. if (res.data.code === 200 || res.data.code === 0) {
  119. this.selectedMascot = mascot;
  120. this.currentMascotName = mascot === 'xibao' ? '浠宝' : '福宝';
  121. // 同步更新 localStorage 以便 AIFloatingAvatar 等组件能读到最新值
  122. var userInfo = uni.getStorageSync('userInfo') || {};
  123. userInfo.mascot = mascot;
  124. uni.setStorageSync('userInfo', userInfo);
  125. uni.showToast({ title: '已更换' });
  126. }
  127. }
  128. });
  129. },
  130. loadMascot() {
  131. var userInfo = uni.getStorageSync('userInfo');
  132. if (userInfo && userInfo.mascot) {
  133. this.selectedMascot = userInfo.mascot;
  134. this.currentMascotName = userInfo.mascot === 'xibao' ? '浠宝' : '福宝';
  135. }
  136. },
  137. _watchPageReady() {
  138. var self = this
  139. this.$nextTick(function() {
  140. self.showTabTransition = false
  141. })
  142. setTimeout(function() {
  143. self.showTabTransition = false
  144. }, 2000)
  145. },
  146. loadHealthScoreData() {
  147. var childId = uni.getStorageSync('currentChildId') || null
  148. if (!childId) return
  149. var self = this
  150. getHealthScoreInfo({ childId: childId }).then(function(res) {
  151. if (res.code === 200 && res.data) {
  152. self.levelInfo = res.data.level || null
  153. self.score = res.data.score || 0
  154. self.progress = res.data.progress || 0
  155. self.nextLevel = res.data.nextLevel || null
  156. self.streakDays = res.data.streakDays || 0
  157. }
  158. }).catch(function() {})
  159. getHealthTimeline({ childId: childId }).then(function(res) {
  160. if (res.code === 200 && Array.isArray(res.data)) {
  161. self.timelineEvents = res.data.slice(0, 10)
  162. }
  163. }).catch(function() {})
  164. }
  165. }
  166. }
  167. </script>
  168. <style scoped>
  169. .container {
  170. min-height: 100vh;
  171. background: #f5f7fa;
  172. padding-bottom: 120rpx;
  173. }
  174. .login-prompt {
  175. display: flex;
  176. flex-direction: column;
  177. align-items: center;
  178. justify-content: center;
  179. padding: 200rpx 60rpx;
  180. }
  181. .prompt-icon { font-size: 100rpx; margin-bottom: 30rpx; }
  182. .prompt-title { font-size: 40rpx; font-weight: bold; color: #333; margin-bottom: 16rpx; }
  183. .prompt-desc { font-size: 26rpx; color: #999; margin-bottom: 60rpx; }
  184. .login-btn {
  185. width: 80%;
  186. background: linear-gradient(135deg, #667eea, #764ba2);
  187. color: #fff;
  188. border-radius: 50rpx;
  189. font-size: 30rpx;
  190. padding: 24rpx;
  191. line-height: 1.5;
  192. }
  193. .mascot-selector {
  194. margin: 20rpx 0;
  195. padding: 24rpx;
  196. background: #fff;
  197. border-radius: 16rpx;
  198. }
  199. .selector-header {
  200. margin-bottom: 20rpx;
  201. }
  202. .selector-title {
  203. font-size: 32rpx;
  204. font-weight: bold;
  205. color: #1F2937;
  206. }
  207. .selector-subtitle {
  208. font-size: 24rpx;
  209. color: #6366F1;
  210. margin-left: 16rpx;
  211. }
  212. .mascot-cards {
  213. display: flex;
  214. gap: 20rpx;
  215. }
  216. .mascot-card {
  217. flex: 1;
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. padding: 24rpx 0;
  222. border: 2rpx solid #E5E7EB;
  223. border-radius: 12rpx;
  224. }
  225. .mascot-card.active {
  226. border-color: #6366F1;
  227. background: #EEF2FF;
  228. }
  229. .card-icon {
  230. width: 80rpx;
  231. height: 80rpx;
  232. border-radius: 50%;
  233. display: flex;
  234. align-items: center;
  235. justify-content: center;
  236. font-size: 32rpx;
  237. font-weight: bold;
  238. color: #fff;
  239. margin-bottom: 12rpx;
  240. }
  241. .card-icon.xibao {
  242. background: linear-gradient(135deg, #FF8C42, #FF6B9D);
  243. }
  244. .card-icon.fubao {
  245. background: linear-gradient(135deg, #6366F1, #10B981);
  246. }
  247. .card-name {
  248. font-size: 26rpx;
  249. color: #374151;
  250. }
  251. </style>