profile.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. }, 1100)
  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. uni.showToast({ title: '已更换' });
  122. }
  123. }
  124. });
  125. },
  126. loadMascot() {
  127. var userInfo = uni.getStorageSync('userInfo');
  128. if (userInfo && userInfo.mascot) {
  129. this.selectedMascot = userInfo.mascot;
  130. this.currentMascotName = userInfo.mascot === 'xibao' ? '浠宝' : '福宝';
  131. }
  132. }
  133. }
  134. }
  135. </script>
  136. <style scoped>
  137. .container {
  138. min-height: 100vh;
  139. background: #f5f7fa;
  140. padding-bottom: 120rpx;
  141. }
  142. .login-prompt {
  143. display: flex;
  144. flex-direction: column;
  145. align-items: center;
  146. justify-content: center;
  147. padding: 200rpx 60rpx;
  148. }
  149. .prompt-icon { font-size: 100rpx; margin-bottom: 30rpx; }
  150. .prompt-title { font-size: 40rpx; font-weight: bold; color: #333; margin-bottom: 16rpx; }
  151. .prompt-desc { font-size: 26rpx; color: #999; margin-bottom: 60rpx; }
  152. .login-btn {
  153. width: 80%;
  154. background: linear-gradient(135deg, #667eea, #764ba2);
  155. color: #fff;
  156. border-radius: 50rpx;
  157. font-size: 30rpx;
  158. padding: 24rpx;
  159. line-height: 1.5;
  160. }
  161. .mascot-selector {
  162. margin: 20rpx 0;
  163. padding: 24rpx;
  164. background: #fff;
  165. border-radius: 16rpx;
  166. }
  167. .selector-header {
  168. margin-bottom: 20rpx;
  169. }
  170. .selector-title {
  171. font-size: 32rpx;
  172. font-weight: bold;
  173. color: #1F2937;
  174. }
  175. .selector-subtitle {
  176. font-size: 24rpx;
  177. color: #6366F1;
  178. margin-left: 16rpx;
  179. }
  180. .mascot-cards {
  181. display: flex;
  182. gap: 20rpx;
  183. }
  184. .mascot-card {
  185. flex: 1;
  186. display: flex;
  187. flex-direction: column;
  188. align-items: center;
  189. padding: 24rpx 0;
  190. border: 2rpx solid #E5E7EB;
  191. border-radius: 12rpx;
  192. }
  193. .mascot-card.active {
  194. border-color: #6366F1;
  195. background: #EEF2FF;
  196. }
  197. .card-icon {
  198. width: 80rpx;
  199. height: 80rpx;
  200. border-radius: 50%;
  201. display: flex;
  202. align-items: center;
  203. justify-content: center;
  204. font-size: 32rpx;
  205. font-weight: bold;
  206. color: #fff;
  207. margin-bottom: 12rpx;
  208. }
  209. .card-icon.xibao {
  210. background: linear-gradient(135deg, #FF8C42, #FF6B9D);
  211. }
  212. .card-icon.fubao {
  213. background: linear-gradient(135deg, #6366F1, #10B981);
  214. }
  215. .card-name {
  216. font-size: 26rpx;
  217. color: #374151;
  218. }
  219. </style>