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.

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