login.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="login-container">
  3. <view class="login-content">
  4. <image
  5. class="logo"
  6. src="/static/images/map-logo.png"
  7. mode="aspectFit"
  8. />
  9. <view class="title fs-36 fw-600 mt-40">欢迎使用充电桩</view>
  10. <view class="subtitle fs-28 color-666 mt-16">登录后可享受更多功能</view>
  11. <view class="btn-area mt-60">
  12. <button
  13. class="login-btn"
  14. open-type="getPhoneNumber"
  15. @getphonenumber="handleLogin"
  16. >
  17. 微信手机号一键登录
  18. </button>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { login } from "@/api/auth";
  25. import { isAuthenticated, isTabBarPage } from "@/utils/auth";
  26. import { onLoad } from "@dcloudio/uni-app";
  27. import { ref } from "vue";
  28. const redirect = ref("");
  29. onLoad((query: any) => {
  30. if (isAuthenticated()) {
  31. performRedirect(query?.redirect || "");
  32. return;
  33. }
  34. if (query?.redirect) {
  35. redirect.value = decodeURIComponent(query.redirect);
  36. }
  37. });
  38. const handleLogin = (e: any) => {
  39. login(e)
  40. .then(() => {
  41. uni.showToast({
  42. title: "登录成功",
  43. icon: "success",
  44. duration: 1000,
  45. });
  46. setTimeout(() => {
  47. performRedirect(redirect.value);
  48. }, 1000);
  49. })
  50. .catch(() => {});
  51. };
  52. const performRedirect = (url: string) => {
  53. if (url && isTabBarPage(url)) {
  54. uni.switchTab({ url });
  55. return;
  56. }
  57. if (url) {
  58. uni.navigateBack({
  59. fail() {
  60. uni.switchTab({ url: "/pages/map/map" });
  61. },
  62. });
  63. return;
  64. }
  65. const pages = getCurrentPages();
  66. if (pages.length > 1) {
  67. uni.navigateBack({
  68. fail() {
  69. uni.switchTab({ url: "/pages/map/map" });
  70. },
  71. });
  72. } else {
  73. uni.switchTab({ url: "/pages/map/map" });
  74. }
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .login-container {
  79. min-height: 100vh;
  80. display: flex;
  81. flex-direction: column;
  82. align-items: center;
  83. justify-content: center;
  84. background: #fff;
  85. padding: 0 60rpx;
  86. }
  87. .login-content {
  88. display: flex;
  89. flex-direction: column;
  90. align-items: center;
  91. }
  92. .logo {
  93. width: 180rpx;
  94. height: 180rpx;
  95. }
  96. .title {
  97. color: #000;
  98. }
  99. .subtitle {
  100. color: #999;
  101. }
  102. .btn-area {
  103. width: 100%;
  104. }
  105. .login-btn {
  106. width: 100%;
  107. height: 88rpx;
  108. background: var(--color-primary);
  109. color: #fff;
  110. font-size: 32rpx;
  111. border-radius: 44rpx;
  112. line-height: 88rpx;
  113. border: none;
  114. }
  115. .login-btn::after {
  116. border: none;
  117. }
  118. </style>