AIFloatingAvatar.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="ai-float-wrapper" @click="goToChat">
  3. <view class="ai-float-avatar" :class="mascotCode">
  4. <text class="ai-float-icon">{{ mascotIcon }}</text>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. name: 'AIFloatingAvatar',
  11. data() {
  12. return {
  13. mascotCode: 'xibao',
  14. mascotIcon: '🌟'
  15. }
  16. },
  17. mounted() {
  18. this.loadMascot()
  19. },
  20. methods: {
  21. loadMascot() {
  22. var userInfo = uni.getStorageSync('userInfo')
  23. if (userInfo && userInfo.mascot) {
  24. if (userInfo.mascot === 'xibao') {
  25. this.mascotCode = 'xibao'
  26. this.mascotIcon = '🌟'
  27. } else if (userInfo.mascot === 'fubao') {
  28. this.mascotCode = 'fubao'
  29. this.mascotIcon = '💪'
  30. }
  31. } else {
  32. // 默认浠宝
  33. this.mascotCode = 'xibao'
  34. this.mascotIcon = '🌟'
  35. }
  36. },
  37. goToChat() {
  38. // 获取当前页面路径作为来源标识
  39. var pages = getCurrentPages()
  40. var currentPage = pages[pages.length - 1]
  41. var fromPage = ''
  42. if (currentPage) {
  43. fromPage = currentPage.route || ''
  44. }
  45. var url = '/pages/ai/chat?fromPage=' + encodeURIComponent(fromPage)
  46. // 健康维度页面(身/智/心)自动切换为健康教练模式
  47. if (fromPage === 'pages/body/index' || fromPage === 'pages/wisdom/index' || fromPage === 'pages/mind/index') {
  48. url += '&mode=health'
  49. }
  50. uni.navigateTo({ url: url })
  51. }
  52. }
  53. }
  54. </script>
  55. <style scoped>
  56. .ai-float-wrapper {
  57. position: fixed;
  58. right: 32rpx;
  59. bottom: calc(160rpx + constant(safe-area-inset-bottom));
  60. bottom: calc(160rpx + env(safe-area-inset-bottom));
  61. z-index: 999;
  62. display: flex;
  63. align-items: center;
  64. justify-content: center;
  65. width: 112rpx;
  66. height: 112rpx;
  67. }
  68. .ai-float-avatar {
  69. width: 96rpx;
  70. height: 96rpx;
  71. border-radius: 50%;
  72. background: #fff;
  73. display: flex;
  74. align-items: center;
  75. justify-content: center;
  76. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.15), 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  77. animation: floatBounce 3s ease-in-out infinite;
  78. position: relative;
  79. z-index: 2;
  80. transition: transform 0.2s;
  81. }
  82. .ai-float-avatar:active {
  83. transform: scale(0.92);
  84. }
  85. .ai-float-avatar.xibao {
  86. background: linear-gradient(135deg, #FFF7ED 0%, #FFE4CC 100%);
  87. border: 3rpx solid #FF8C42;
  88. }
  89. .ai-float-avatar.fubao {
  90. background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%);
  91. border: 3rpx solid #F59E0B;
  92. }
  93. .ai-float-icon {
  94. font-size: 48rpx;
  95. line-height: 1;
  96. }
  97. @keyframes floatBounce {
  98. 0%, 100% { transform: translateY(0); }
  99. 50% { transform: translateY(-8rpx); }
  100. }
  101. </style>