AIFloatingAvatar.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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'
  46. if (fromPage) {
  47. url += '?fromPage=' + encodeURIComponent(fromPage)
  48. }
  49. uni.navigateTo({ url: url })
  50. }
  51. }
  52. }
  53. </script>
  54. <style scoped>
  55. .ai-float-wrapper {
  56. position: fixed;
  57. right: 32rpx;
  58. bottom: calc(160rpx + constant(safe-area-inset-bottom));
  59. bottom: calc(160rpx + env(safe-area-inset-bottom));
  60. z-index: 999;
  61. display: flex;
  62. align-items: center;
  63. justify-content: center;
  64. width: 112rpx;
  65. height: 112rpx;
  66. }
  67. .ai-float-avatar {
  68. width: 96rpx;
  69. height: 96rpx;
  70. border-radius: 50%;
  71. background: #fff;
  72. display: flex;
  73. align-items: center;
  74. justify-content: center;
  75. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.15), 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
  76. animation: floatBounce 3s ease-in-out infinite;
  77. position: relative;
  78. z-index: 2;
  79. transition: transform 0.2s;
  80. }
  81. .ai-float-avatar:active {
  82. transform: scale(0.92);
  83. }
  84. .ai-float-avatar.xibao {
  85. background: linear-gradient(135deg, #FFF7ED 0%, #FFE4CC 100%);
  86. border: 3rpx solid #FF8C42;
  87. }
  88. .ai-float-avatar.fubao {
  89. background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%);
  90. border: 3rpx solid #F59E0B;
  91. }
  92. .ai-float-icon {
  93. font-size: 48rpx;
  94. line-height: 1;
  95. }
  96. @keyframes floatBounce {
  97. 0%, 100% { transform: translateY(0); }
  98. 50% { transform: translateY(-8rpx); }
  99. }
  100. </style>