profile.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 />
  18. <!-- AI小助手形象选择 -->
  19. <view class="mascot-selector">
  20. <view class="selector-header">
  21. <text class="selector-title">AI小助手</text>
  22. <text class="selector-subtitle">{{ currentMascotName }}为你服务</text>
  23. </view>
  24. <view class="mascot-cards">
  25. <view class="mascot-card" :class="{active: selectedMascot === 'xibao'}" @click="changeMascot('xibao')">
  26. <view class="card-icon xibao">浠</view>
  27. <text class="card-name">浠宝</text>
  28. </view>
  29. <view class="mascot-card" :class="{active: selectedMascot === 'fubao'}" @click="changeMascot('fubao')">
  30. <view class="card-icon fubao">福</view>
  31. <text class="card-name">福宝</text>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- 行动数据 + 财富数据 -->
  36. <ProfileStats />
  37. <!-- 成就徽章 -->
  38. <ProfileBadges />
  39. <!-- 成长报告 -->
  40. <ProfileGrowth />
  41. <!-- 菜单列表 -->
  42. <ProfileMenu :role="role" @invite-generate="onInviteGenerate" />
  43. </template>
  44. </view>
  45. </template>
  46. <script>
  47. import TabTransition from '../../components/tab-transition.vue'
  48. import PageBanner from '../../components/PageBanner.vue'
  49. import ProfileHeader from './components/ProfileHeader.vue'
  50. import ProfileStats from './components/ProfileStats.vue'
  51. import ProfileBadges from './components/ProfileBadges.vue'
  52. import ProfileGrowth from './components/ProfileGrowth.vue'
  53. import ProfileMenu from './components/ProfileMenu.vue'
  54. export default {
  55. components: {
  56. TabTransition,
  57. PageBanner,
  58. ProfileHeader,
  59. ProfileStats,
  60. ProfileBadges,
  61. ProfileGrowth,
  62. ProfileMenu
  63. },
  64. data() {
  65. return {
  66. shareData: null,
  67. showTabTransition: false,
  68. selectedMascot: '',
  69. currentMascotName: '小助手'
  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. // Tabbar 切换过渡动画(最少停留 1 秒)
  91. this.showTabTransition = true
  92. var self = this
  93. setTimeout(function() {
  94. self.showTabTransition = false
  95. }, 1800)
  96. if (!uni.getStorageSync('token')) return
  97. this.loadMascot()
  98. const currentRole = uni.getStorageSync('currentRole') || uni.getStorageSync('role') || 'parent'
  99. if (currentRole === 'teacher') {
  100. uni.redirectTo({ url: '/pages/teacher/teacher-profile' })
  101. }
  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. }
  138. }
  139. </script>
  140. <style scoped>
  141. .container {
  142. min-height: 100vh;
  143. background: #f5f7fa;
  144. padding-bottom: 120rpx;
  145. }
  146. .login-prompt {
  147. display: flex;
  148. flex-direction: column;
  149. align-items: center;
  150. justify-content: center;
  151. padding: 200rpx 60rpx;
  152. }
  153. .prompt-icon { font-size: 100rpx; margin-bottom: 30rpx; }
  154. .prompt-title { font-size: 40rpx; font-weight: bold; color: #333; margin-bottom: 16rpx; }
  155. .prompt-desc { font-size: 26rpx; color: #999; margin-bottom: 60rpx; }
  156. .login-btn {
  157. width: 80%;
  158. background: linear-gradient(135deg, #667eea, #764ba2);
  159. color: #fff;
  160. border-radius: 50rpx;
  161. font-size: 30rpx;
  162. padding: 24rpx;
  163. line-height: 1.5;
  164. }
  165. .mascot-selector {
  166. margin: 20rpx 0;
  167. padding: 24rpx;
  168. background: #fff;
  169. border-radius: 16rpx;
  170. }
  171. .selector-header {
  172. margin-bottom: 20rpx;
  173. }
  174. .selector-title {
  175. font-size: 32rpx;
  176. font-weight: bold;
  177. color: #1F2937;
  178. }
  179. .selector-subtitle {
  180. font-size: 24rpx;
  181. color: #6366F1;
  182. margin-left: 16rpx;
  183. }
  184. .mascot-cards {
  185. display: flex;
  186. gap: 20rpx;
  187. }
  188. .mascot-card {
  189. flex: 1;
  190. display: flex;
  191. flex-direction: column;
  192. align-items: center;
  193. padding: 24rpx 0;
  194. border: 2rpx solid #E5E7EB;
  195. border-radius: 12rpx;
  196. }
  197. .mascot-card.active {
  198. border-color: #6366F1;
  199. background: #EEF2FF;
  200. }
  201. .card-icon {
  202. width: 80rpx;
  203. height: 80rpx;
  204. border-radius: 50%;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. font-size: 32rpx;
  209. font-weight: bold;
  210. color: #fff;
  211. margin-bottom: 12rpx;
  212. }
  213. .card-icon.xibao {
  214. background: linear-gradient(135deg, #FF8C42, #FF6B9D);
  215. }
  216. .card-icon.fubao {
  217. background: linear-gradient(135deg, #6366F1, #10B981);
  218. }
  219. .card-name {
  220. font-size: 26rpx;
  221. color: #374151;
  222. }
  223. </style>