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.

187 lines
3.8 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. uni.$emit('visitorLoginSuccess', {
  82. userInfo: res.data
  83. });
  84. }
  85. };
  86. // 暴露方法给外部使用
  87. defineExpose({
  88. show,
  89. hide,
  90. });
  91. </script>
  92. <style scoped>
  93. .login-prompt {
  94. position: fixed;
  95. top: 0;
  96. left: 0;
  97. right: 0;
  98. bottom: 0;
  99. z-index: 999;
  100. }
  101. .mask {
  102. position: absolute;
  103. top: 0;
  104. left: 0;
  105. right: 0;
  106. bottom: 0;
  107. background-color: rgba(0, 0, 0, 0.8);
  108. opacity: 0;
  109. transition: opacity 0.3s ease;
  110. }
  111. .mask.mask-show {
  112. opacity: 1;
  113. }
  114. .prompt-content {
  115. position: absolute;
  116. bottom: 0;
  117. left: 0;
  118. right: 0;
  119. height: 400rpx;
  120. border-radius: 20rpx 20rpx 0 0;
  121. background-color: white;
  122. padding: 20rpx 70rpx;
  123. transform: translateY(100%);
  124. transition: transform 0.3s ease;
  125. box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  126. }
  127. .prompt-content.slide-up {
  128. transform: translateY(0);
  129. }
  130. .prompt-title {
  131. display: block;
  132. text-align: center;
  133. font-size: 40rpx;
  134. font-weight: 700;
  135. color: #000000;
  136. margin-top: 30rpx;
  137. margin-bottom: 40rpx;
  138. }
  139. .login-btn {
  140. width: 100%;
  141. height: 80rpx;
  142. background-color: rgb(0, 0, 0);
  143. color: white;
  144. font-size: 32rpx;
  145. line-height: 80rpx;
  146. border-radius: 40rpx;
  147. margin-bottom: 20rpx;
  148. }
  149. .visitor-btn {
  150. width: 100%;
  151. height: 80rpx;
  152. background-color: #f5f5f5;
  153. color: #333;
  154. font-size: 32rpx;
  155. line-height: 80rpx;
  156. border-radius: 40rpx;
  157. }
  158. .prompt-title-small {
  159. display: block;
  160. text-align: center;
  161. font-size: 24rpx;
  162. color: #6a6a6a;
  163. margin-top: 30rpx;
  164. margin-bottom: 40rpx;
  165. line-height: 15.5px;
  166. letter-spacing: 0.3px;
  167. font-style: normal;
  168. font-family: "PingFang SC";
  169. }
  170. </style>