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.

166 lines
3.1 KiB

4 weeks ago
4 weeks ago
4 weeks ago
  1. <template>
  2. <view class="login-prompt" v-if="showPrompt">
  3. <view class="mask" :class="{ 'mask-show': showAnimation }"></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">
  8. 以访客身份继续
  9. </button>
  10. <text class="prompt-title-small" @click="goRegister"
  11. >如果您还没有账号点击注册</text
  12. >
  13. </view>
  14. </view>
  15. </template>
  16. <script setup>
  17. import { ref, nextTick, onMounted } from "vue";
  18. import { useUserStore } from "../stores/modules/userInfo";
  19. const userStore = useUserStore();
  20. // 初始化
  21. onMounted(() => {
  22. if (!userStore.userInfo) {
  23. show();
  24. }
  25. });
  26. // 定义响应式数据
  27. const showPrompt = ref(false);
  28. const showAnimation = ref(false);
  29. // 显示弹窗
  30. const show = () => {
  31. showPrompt.value = true;
  32. // 在下一帧触发动画
  33. nextTick(() => {
  34. setTimeout(() => {
  35. showAnimation.value = true;
  36. }, 10);
  37. });
  38. };
  39. // 隐藏弹窗
  40. const hide = () => {
  41. showAnimation.value = false;
  42. // 等待动画结束后再隐藏
  43. setTimeout(() => {
  44. showPrompt.value = false;
  45. }, 300);
  46. };
  47. // 跳转到登录页面
  48. const goLogin = () => {
  49. uni.navigateTo({
  50. url: "/pages/start/login/login",
  51. });
  52. hide();
  53. };
  54. // 跳转到登录页面
  55. const goRegister = () => {
  56. uni.navigateTo({
  57. url: "/pages/start/Registration/Registration",
  58. });
  59. hide();
  60. };
  61. // 以访客身份继续
  62. const continueAsVisitor = () => {
  63. // 设置访客模式
  64. uni.setStorageSync("visitorMode", true);
  65. hide();
  66. };
  67. // 暴露方法给外部使用
  68. defineExpose({
  69. show,
  70. hide,
  71. });
  72. </script>
  73. <style scoped>
  74. .login-prompt {
  75. position: fixed;
  76. top: 0;
  77. left: 0;
  78. right: 0;
  79. bottom: 0;
  80. z-index: 999;
  81. }
  82. .mask {
  83. position: absolute;
  84. top: 0;
  85. left: 0;
  86. right: 0;
  87. bottom: 0;
  88. background-color: rgba(0, 0, 0, 0.8);
  89. opacity: 0;
  90. transition: opacity 0.3s ease;
  91. }
  92. .mask.mask-show {
  93. opacity: 1;
  94. }
  95. .prompt-content {
  96. position: absolute;
  97. bottom: 0;
  98. left: 0;
  99. right: 0;
  100. height: 400rpx;
  101. border-radius: 20rpx 20rpx 0 0;
  102. background-color: white;
  103. padding: 20rpx 70rpx;
  104. transform: translateY(100%);
  105. transition: transform 0.3s ease;
  106. box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  107. }
  108. .prompt-content.slide-up {
  109. transform: translateY(0);
  110. }
  111. .prompt-title {
  112. display: block;
  113. text-align: center;
  114. font-size: 40rpx;
  115. font-weight: 700;
  116. color: #000000;
  117. margin-top: 30rpx;
  118. margin-bottom: 40rpx;
  119. }
  120. .login-btn {
  121. width: 100%;
  122. height: 80rpx;
  123. background-color: rgb(0, 0, 0);
  124. color: white;
  125. font-size: 32rpx;
  126. line-height: 80rpx;
  127. border-radius: 40rpx;
  128. margin-bottom: 20rpx;
  129. }
  130. .visitor-btn {
  131. width: 100%;
  132. height: 80rpx;
  133. background-color: #f5f5f5;
  134. color: #333;
  135. font-size: 32rpx;
  136. line-height: 80rpx;
  137. border-radius: 40rpx;
  138. }
  139. .prompt-title-small {
  140. display: block;
  141. text-align: center;
  142. font-size: 24rpx;
  143. color: #6a6a6a;
  144. margin-top: 30rpx;
  145. margin-bottom: 40rpx;
  146. line-height: 15.5px;
  147. letter-spacing: 0.3px;
  148. font-style: normal;
  149. font-family: "PingFang SC";
  150. }
  151. </style>