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.

223 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. phoneCountry: "", //手机号所属地区
  103. verifyCode: "", //验证码
  104. password: "", //密码
  105. useCode: "", //是否使用验证码 true/false
  106. idToken: "", //第三方登录idToken
  107. deviceId: deviceStore.deviceInfo.deviceId,
  108. });
  109. if (res.code === 200) {
  110. userStore.setUserInfo(res.data);
  111. console.log("0loginStore.loginInfo", loginStore.loginInfo);
  112. hide();
  113. // 发送游客登录成功事件,通知首页重新加载
  114. uni.$emit("visitorLoginSuccess", {
  115. userInfo: res.data,
  116. });
  117. }
  118. };
  119. // 暴露方法给外部使用
  120. defineExpose({
  121. show,
  122. hide,
  123. });
  124. </script>
  125. <style scoped>
  126. .login-prompt {
  127. position: fixed;
  128. top: 0;
  129. left: 0;
  130. right: 0;
  131. bottom: 0;
  132. z-index: 999;
  133. }
  134. .mask {
  135. position: absolute;
  136. top: 0;
  137. left: 0;
  138. right: 0;
  139. bottom: 0;
  140. background-color: rgba(0, 0, 0, 0.8);
  141. opacity: 0;
  142. transition: opacity 0.3s ease;
  143. }
  144. .mask.mask-show {
  145. opacity: 1;
  146. }
  147. .prompt-content {
  148. position: absolute;
  149. bottom: 0;
  150. left: 0;
  151. right: 0;
  152. height: 400rpx;
  153. border-radius: 20rpx 20rpx 0 0;
  154. background-color: white;
  155. padding: 20rpx 70rpx;
  156. transform: translateY(100%);
  157. transition: transform 0.3s ease;
  158. box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  159. }
  160. .prompt-content.slide-up {
  161. transform: translateY(0);
  162. }
  163. .prompt-title {
  164. display: block;
  165. text-align: center;
  166. font-size: 40rpx;
  167. font-weight: 700;
  168. color: #000000;
  169. margin-top: 30rpx;
  170. margin-bottom: 40rpx;
  171. }
  172. .login-btn {
  173. width: 100%;
  174. height: 80rpx;
  175. background-color: rgb(0, 0, 0);
  176. color: white;
  177. font-size: 32rpx;
  178. line-height: 80rpx;
  179. border-radius: 40rpx;
  180. margin-bottom: 20rpx;
  181. }
  182. .visitor-btn {
  183. width: 100%;
  184. height: 80rpx;
  185. background-color: #f5f5f5;
  186. color: #333;
  187. font-size: 32rpx;
  188. line-height: 80rpx;
  189. border-radius: 40rpx;
  190. }
  191. .prompt-title-small {
  192. display: block;
  193. text-align: center;
  194. font-size: 24rpx;
  195. color: #6a6a6a;
  196. margin-top: 30rpx;
  197. margin-bottom: 40rpx;
  198. line-height: 15.5px;
  199. letter-spacing: 0.3px;
  200. font-style: normal;
  201. font-family: "PingFang SC";
  202. }
  203. </style>