profile.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. <!-- 菜单列表(仅个人信息 + 设置,不含服务/商城板块) -->
  21. <ProfileMenu :role="role" :show-services="false" @invite-generate="onInviteGenerate" />
  22. </template>
  23. <AIFloatingAvatar />
  24. </view>
  25. </template>
  26. <script>
  27. import TabTransition from '../../components/tab-transition.vue'
  28. import ProfileHeader from './components/ProfileHeader.vue'
  29. import ProfileBadges from './components/ProfileBadges.vue'
  30. import ProfileGrowth from './components/ProfileGrowth.vue'
  31. import ProfileMenu from './components/ProfileMenu.vue'
  32. import AIFloatingAvatar from '../../components/AIFloatingAvatar.vue'
  33. export default {
  34. components: {
  35. TabTransition,
  36. ProfileHeader,
  37. ProfileBadges,
  38. ProfileGrowth,
  39. ProfileMenu,
  40. AIFloatingAvatar
  41. },
  42. data() {
  43. return {
  44. shareData: null,
  45. showTabTransition: true,
  46. selectedMascot: '',
  47. currentMascotName: '小助手'
  48. }
  49. },
  50. computed: {
  51. isLoggedIn() {
  52. return !!uni.getStorageSync('token')
  53. },
  54. role() {
  55. return uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
  56. }
  57. },
  58. onShareAppMessage() {
  59. if (this.shareData) {
  60. return {
  61. title: this.shareData.title,
  62. path: this.shareData.path,
  63. imageUrl: '/static/invite-card.png'
  64. }
  65. }
  66. },
  67. onShow() {
  68. this.showTabTransition = true
  69. if (!uni.getStorageSync('token')) {
  70. this._watchPageReady()
  71. return
  72. }
  73. this.loadMascot()
  74. const currentRole = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
  75. if (currentRole === 'teacher') {
  76. uni.redirectTo({ url: '/pages/teacher/teacher-profile' })
  77. }
  78. this._watchPageReady()
  79. },
  80. methods: {
  81. goLogin() {
  82. uni.navigateTo({ url: '/pages/login/login' })
  83. },
  84. onInviteGenerate(shareData) {
  85. this.shareData = shareData
  86. },
  87. changeMascot(mascot) {
  88. if (this.selectedMascot === mascot) return;
  89. uni.request({
  90. url: this.$config.API_BASE_URL + '/api/user/mascot/set',
  91. method: 'POST',
  92. header: { Authorization: 'Bearer ' + uni.getStorageSync('token') },
  93. data: { mascot },
  94. success: (res) => {
  95. if (res.data.code === 200 || res.data.code === 0) {
  96. this.selectedMascot = mascot;
  97. this.currentMascotName = mascot === 'xibao' ? '浠宝' : '福宝';
  98. // 同步更新 localStorage 以便 AIFloatingAvatar 等组件能读到最新值
  99. var userInfo = uni.getStorageSync('userInfo') || {};
  100. userInfo.mascot = mascot;
  101. uni.setStorageSync('userInfo', userInfo);
  102. uni.showToast({ title: '已更换' });
  103. }
  104. }
  105. });
  106. },
  107. loadMascot() {
  108. var userInfo = uni.getStorageSync('userInfo');
  109. if (userInfo && userInfo.mascot) {
  110. this.selectedMascot = userInfo.mascot;
  111. this.currentMascotName = userInfo.mascot === 'xibao' ? '浠宝' : '福宝';
  112. }
  113. },
  114. _watchPageReady() {
  115. var self = this
  116. this.$nextTick(function() {
  117. self.showTabTransition = false
  118. })
  119. setTimeout(function() {
  120. self.showTabTransition = false
  121. }, 2000)
  122. }
  123. }
  124. }
  125. </script>
  126. <style scoped>
  127. .container {
  128. min-height: 100vh;
  129. background: #f5f7fa;
  130. padding-bottom: 120rpx;
  131. }
  132. .login-prompt {
  133. display: flex;
  134. flex-direction: column;
  135. align-items: center;
  136. justify-content: center;
  137. padding: 200rpx 60rpx;
  138. }
  139. .prompt-icon { font-size: 100rpx; margin-bottom: 30rpx; }
  140. .prompt-title { font-size: 40rpx; font-weight: bold; color: #333; margin-bottom: 16rpx; }
  141. .prompt-desc { font-size: 26rpx; color: #999; margin-bottom: 60rpx; }
  142. .login-btn {
  143. width: 80%;
  144. background: linear-gradient(135deg, #667eea, #764ba2);
  145. color: #fff;
  146. border-radius: 50rpx;
  147. font-size: 30rpx;
  148. padding: 24rpx;
  149. line-height: 1.5;
  150. }
  151. .mascot-selector {
  152. margin: 20rpx 0;
  153. padding: 24rpx;
  154. background: #fff;
  155. border-radius: 16rpx;
  156. }
  157. .selector-header {
  158. margin-bottom: 20rpx;
  159. }
  160. .selector-title {
  161. font-size: 32rpx;
  162. font-weight: bold;
  163. color: #1F2937;
  164. }
  165. .selector-subtitle {
  166. font-size: 24rpx;
  167. color: #6366F1;
  168. margin-left: 16rpx;
  169. }
  170. .mascot-cards {
  171. display: flex;
  172. gap: 20rpx;
  173. }
  174. .mascot-card {
  175. flex: 1;
  176. display: flex;
  177. flex-direction: column;
  178. align-items: center;
  179. padding: 24rpx 0;
  180. border: 2rpx solid #E5E7EB;
  181. border-radius: 12rpx;
  182. }
  183. .mascot-card.active {
  184. border-color: #6366F1;
  185. background: #EEF2FF;
  186. }
  187. .card-icon {
  188. width: 80rpx;
  189. height: 80rpx;
  190. border-radius: 50%;
  191. display: flex;
  192. align-items: center;
  193. justify-content: center;
  194. font-size: 32rpx;
  195. font-weight: bold;
  196. color: #fff;
  197. margin-bottom: 12rpx;
  198. }
  199. .card-icon.xibao {
  200. background: linear-gradient(135deg, #FF8C42, #FF6B9D);
  201. }
  202. .card-icon.fubao {
  203. background: linear-gradient(135deg, #6366F1, #10B981);
  204. }
  205. .card-name {
  206. font-size: 26rpx;
  207. color: #374151;
  208. }
  209. </style>