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.

188 lines
3.8 KiB

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