You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
2.5 KiB

  1. <template>
  2. <view class="login-prompt" v-if="showPrompt">
  3. <view class="mask" :class="{ 'mask-show': showAnimation }" @click="hide"></view>
  4. <view class="prompt-content" :class="{ 'slide-up': showAnimation }">
  5. <text class="prompt-title">登录以获得更好的体验</text>
  6. <button class="login-btn" @click="goLogin">登录(推荐)</button>
  7. <button class="visitor-btn" @click="continueAsVisitor">以访客身份继续</button>
  8. </view>
  9. </view>
  10. </template>
  11. <script setup>
  12. import { ref, nextTick } from 'vue';
  13. // 定义响应式数据
  14. const showPrompt = ref(false);
  15. const showAnimation = ref(false);
  16. // 显示弹窗
  17. const show = () => {
  18. showPrompt.value = true;
  19. // 在下一帧触发动画
  20. nextTick(() => {
  21. setTimeout(() => {
  22. showAnimation.value = true;
  23. }, 10);
  24. });
  25. };
  26. // 隐藏弹窗
  27. const hide = () => {
  28. showAnimation.value = false;
  29. // 等待动画结束后再隐藏
  30. setTimeout(() => {
  31. showPrompt.value = false;
  32. }, 300);
  33. };
  34. // 跳转到登录页面
  35. const goLogin = () => {
  36. uni.navigateTo({
  37. url: '/pages/login/login'
  38. });
  39. hide();
  40. };
  41. // 以访客身份继续
  42. const continueAsVisitor = () => {
  43. // 设置访客模式
  44. uni.setStorageSync('visitorMode', true);
  45. hide();
  46. };
  47. // 暴露方法给外部使用
  48. defineExpose({
  49. show,
  50. hide
  51. });
  52. </script>
  53. <style scoped>
  54. .login-prompt {
  55. position: fixed;
  56. top: 0;
  57. left: 0;
  58. right: 0;
  59. bottom: 0;
  60. z-index: 999;
  61. }
  62. .mask {
  63. position: absolute;
  64. top: 0;
  65. left: 0;
  66. right: 0;
  67. bottom: 0;
  68. background-color: rgba(0, 0, 0, 0.8);
  69. opacity: 0;
  70. transition: opacity 0.3s ease;
  71. }
  72. .mask.mask-show {
  73. opacity: 1;
  74. }
  75. .prompt-content {
  76. position: absolute;
  77. bottom: 0;
  78. left: 0;
  79. right: 0;
  80. height: 300rpx;
  81. border-radius: 20rpx 20rpx 0 0;
  82. background-color: white;
  83. padding: 20rpx 30rpx;
  84. transform: translateY(100%);
  85. transition: transform 0.3s ease;
  86. box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  87. }
  88. .prompt-content.slide-up {
  89. transform: translateY(0);
  90. }
  91. .prompt-title {
  92. display: block;
  93. text-align: left;
  94. font-size: 28rpx;
  95. font-weight: 700;
  96. color: #333;
  97. margin-top: 10rpx;
  98. margin-bottom: 30rpx;
  99. }
  100. .login-btn {
  101. width: 100%;
  102. height: 80rpx;
  103. background-color:rgb(35, 84, 230);
  104. color: white;
  105. font-size: 32rpx;
  106. line-height: 80rpx;
  107. border-radius: 40rpx;
  108. margin-bottom: 20rpx;
  109. }
  110. .visitor-btn {
  111. width: 100%;
  112. height: 80rpx;
  113. background-color: #f5f5f5;
  114. color: #333;
  115. font-size: 32rpx;
  116. line-height: 80rpx;
  117. border-radius: 40rpx;
  118. }
  119. </style>