AIFloatingAvatar.vue 2.8 KB

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