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.

222 lines
4.7 KiB

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