profile.vue 6.0 KB

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