profile.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view class="container">
  3. <!-- Tabbar 切换过渡页 -->
  4. <tab-transition v-if="showTabTransition" dimCode="wealth" ref="tabTransition" @close="showTabTransition = false" />
  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. if (self.$refs.tabTransition) self.$refs.tabTransition.markReady()
  141. })
  142. },
  143. loadHealthScoreData() {
  144. var childId = uni.getStorageSync('currentChildId') || null
  145. if (!childId) return
  146. var self = this
  147. getHealthScoreInfo({ childId: childId }).then(function(res) {
  148. if (res.code === 200 && res.data) {
  149. self.levelInfo = res.data.level || null
  150. self.score = res.data.score || 0
  151. self.progress = res.data.progress || 0
  152. self.nextLevel = res.data.nextLevel || null
  153. self.streakDays = res.data.streakDays || 0
  154. }
  155. }).catch(function() {})
  156. getHealthTimeline({ childId: childId }).then(function(res) {
  157. if (res.code === 200 && Array.isArray(res.data)) {
  158. self.timelineEvents = res.data.slice(0, 10)
  159. }
  160. }).catch(function() {})
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped>
  166. .container {
  167. min-height: 100vh;
  168. background: #f5f7fa;
  169. padding-bottom: 120rpx;
  170. }
  171. .login-prompt {
  172. display: flex;
  173. flex-direction: column;
  174. align-items: center;
  175. justify-content: center;
  176. padding: 200rpx 60rpx;
  177. }
  178. .prompt-icon { font-size: 100rpx; margin-bottom: 30rpx; }
  179. .prompt-title { font-size: 40rpx; font-weight: bold; color: #333; margin-bottom: 16rpx; }
  180. .prompt-desc { font-size: 26rpx; color: #999; margin-bottom: 60rpx; }
  181. .login-btn {
  182. width: 80%;
  183. background: linear-gradient(135deg, #667eea, #764ba2);
  184. color: #fff;
  185. border-radius: 50rpx;
  186. font-size: 30rpx;
  187. padding: 24rpx;
  188. line-height: 1.5;
  189. }
  190. .mascot-selector {
  191. margin: 20rpx 0;
  192. padding: 24rpx;
  193. background: #fff;
  194. border-radius: 16rpx;
  195. }
  196. .selector-header {
  197. margin-bottom: 20rpx;
  198. }
  199. .selector-title {
  200. font-size: 32rpx;
  201. font-weight: bold;
  202. color: #1F2937;
  203. }
  204. .selector-subtitle {
  205. font-size: 24rpx;
  206. color: #6366F1;
  207. margin-left: 16rpx;
  208. }
  209. .mascot-cards {
  210. display: flex;
  211. gap: 20rpx;
  212. }
  213. .mascot-card {
  214. flex: 1;
  215. display: flex;
  216. flex-direction: column;
  217. align-items: center;
  218. padding: 24rpx 0;
  219. border: 2rpx solid #E5E7EB;
  220. border-radius: 12rpx;
  221. }
  222. .mascot-card.active {
  223. border-color: #6366F1;
  224. background: #EEF2FF;
  225. }
  226. .card-icon {
  227. width: 80rpx;
  228. height: 80rpx;
  229. border-radius: 50%;
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. font-size: 32rpx;
  234. font-weight: bold;
  235. color: #fff;
  236. margin-bottom: 12rpx;
  237. }
  238. .card-icon.xibao {
  239. background: linear-gradient(135deg, #FF8C42, #FF6B9D);
  240. }
  241. .card-icon.fubao {
  242. background: linear-gradient(135deg, #6366F1, #10B981);
  243. }
  244. .card-name {
  245. font-size: 26rpx;
  246. color: #374151;
  247. }
  248. </style>