profile.vue 6.8 KB

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