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.

182 lines
3.7 KiB

4 weeks ago
4 weeks ago
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. import { useDeviceStore } from "../stores/modules/deviceInfo";
  20. import { LoginApi } from "../api/start/login";
  21. const deviceId = ref("");
  22. const userStore = useUserStore();
  23. const deviceStore = useDeviceStore();
  24. // 初始化
  25. onMounted(() => {
  26. if (!userStore.userInfo) {
  27. show();
  28. }
  29. });
  30. // 定义响应式数据
  31. const showPrompt = ref(false);
  32. const showAnimation = ref(false);
  33. // 显示弹窗
  34. const show = () => {
  35. showPrompt.value = true;
  36. // 在下一帧触发动画
  37. nextTick(() => {
  38. setTimeout(() => {
  39. showAnimation.value = true;
  40. }, 10);
  41. });
  42. };
  43. // 隐藏弹窗
  44. const hide = () => {
  45. showAnimation.value = false;
  46. // 等待动画结束后再隐藏
  47. setTimeout(() => {
  48. showPrompt.value = false;
  49. }, 300);
  50. };
  51. // 跳转到登录页面
  52. const goLogin = () => {
  53. uni.navigateTo({
  54. url: "/pages/start/login/login",
  55. });
  56. hide();
  57. };
  58. // 跳转到登录页面
  59. const goRegister = () => {
  60. uni.navigateTo({
  61. url: "/pages/start/Registration/Registration",
  62. });
  63. hide();
  64. };
  65. // 以访客身份继续
  66. const continueAsVisitor = async () => {
  67. // 设置访客模式
  68. const res = await LoginApi({
  69. loginType: "VISITOR", //登录方式EMAIL,PHONE,DCCODE,APPLE,GOOGLE,VISITOR
  70. account: "", //登陆账号 手机号/邮箱/dccode
  71. verifyCode: "", //验证码
  72. password: "", //密码
  73. useCode: "", //是否使用验证码 true/false
  74. idToken: "", //第三方登录idToken
  75. deviceId: deviceStore.deviceInfo.deviceId,
  76. });
  77. if (res.code === 200) {
  78. userStore.setUserInfo(res.data);
  79. hide();
  80. }
  81. };
  82. // 暴露方法给外部使用
  83. defineExpose({
  84. show,
  85. hide,
  86. });
  87. </script>
  88. <style scoped>
  89. .login-prompt {
  90. position: fixed;
  91. top: 0;
  92. left: 0;
  93. right: 0;
  94. bottom: 0;
  95. z-index: 999;
  96. }
  97. .mask {
  98. position: absolute;
  99. top: 0;
  100. left: 0;
  101. right: 0;
  102. bottom: 0;
  103. background-color: rgba(0, 0, 0, 0.8);
  104. opacity: 0;
  105. transition: opacity 0.3s ease;
  106. }
  107. .mask.mask-show {
  108. opacity: 1;
  109. }
  110. .prompt-content {
  111. position: absolute;
  112. bottom: 0;
  113. left: 0;
  114. right: 0;
  115. height: 400rpx;
  116. border-radius: 20rpx 20rpx 0 0;
  117. background-color: white;
  118. padding: 20rpx 70rpx;
  119. transform: translateY(100%);
  120. transition: transform 0.3s ease;
  121. box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  122. }
  123. .prompt-content.slide-up {
  124. transform: translateY(0);
  125. }
  126. .prompt-title {
  127. display: block;
  128. text-align: center;
  129. font-size: 40rpx;
  130. font-weight: 700;
  131. color: #000000;
  132. margin-top: 30rpx;
  133. margin-bottom: 40rpx;
  134. }
  135. .login-btn {
  136. width: 100%;
  137. height: 80rpx;
  138. background-color: rgb(0, 0, 0);
  139. color: white;
  140. font-size: 32rpx;
  141. line-height: 80rpx;
  142. border-radius: 40rpx;
  143. margin-bottom: 20rpx;
  144. }
  145. .visitor-btn {
  146. width: 100%;
  147. height: 80rpx;
  148. background-color: #f5f5f5;
  149. color: #333;
  150. font-size: 32rpx;
  151. line-height: 80rpx;
  152. border-radius: 40rpx;
  153. }
  154. .prompt-title-small {
  155. display: block;
  156. text-align: center;
  157. font-size: 24rpx;
  158. color: #6a6a6a;
  159. margin-top: 30rpx;
  160. margin-bottom: 40rpx;
  161. line-height: 15.5px;
  162. letter-spacing: 0.3px;
  163. font-style: normal;
  164. font-family: "PingFang SC";
  165. }
  166. </style>