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.

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