index1.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="container">
  3. <view class="bg-shape shadow"></view>
  4. <view class="bg-shape2 shadow"></view>
  5. <view class="loading-box">
  6. <uv-loading-icon color="#3b82f6" size="30"></uv-loading-icon>
  7. <text class="loading-text">正在自动登录,请稍候...</text>
  8. </view>
  9. <uv-toast ref="toastRef"></uv-toast>
  10. </view>
  11. </template>
  12. <script setup lang="ts">
  13. import { ref, onMounted } from 'vue';
  14. import { useUserStore } from '@/store/modules/user';
  15. const userStore = useUserStore();
  16. const toastRef = ref<any>(null);
  17. onMounted(async () => {
  18. // --- 逻辑拦截 ---
  19. // 如果缓存里已经有 Token,说明当前处于已登录状态
  20. if (userStore.token) {
  21. uni.switchTab({ url: '/pages/home/index' }).catch(() => {
  22. uni.reLaunch({ url: '/pages/home/index' });
  23. });
  24. return;
  25. }
  26. // --- 新增:企业微信免登拦截(URL 带 code) ---
  27. const urlCode = uni.getLaunchOptionsSync()?.query?.code as string | undefined;
  28. if (urlCode) {
  29. try {
  30. await userStore.oAuthLogin(urlCode);
  31. toastRef.value.show({ message: '登录成功', type: 'success' });
  32. // 成功跳转首页
  33. setTimeout(() => {
  34. uni.switchTab({ url: '/pages/home/index' }).catch(() => {
  35. uni.reLaunch({ url: '/pages/home/index' });
  36. });
  37. }, 800);
  38. return;
  39. } catch (error: any) {
  40. console.error('oAuthLogin Failure in Login Page:', error);
  41. toastRef.value.show({
  42. message: error?.message || '企业快捷登录失败',
  43. type: 'error',
  44. });
  45. uni.reLaunch({ url: '/pages/login/register' });
  46. return;
  47. }
  48. }
  49. // 无法进行免登时,回到手动登录页
  50. uni.reLaunch({ url: '/pages/login/index' });
  51. });
  52. </script>
  53. <style scoped>
  54. .container {
  55. min-height: 100vh;
  56. position: relative;
  57. background: #f8fafc;
  58. overflow: hidden;
  59. display: flex;
  60. justify-content: center;
  61. align-items: center;
  62. padding: 0 40rpx;
  63. }
  64. .bg-shape {
  65. position: absolute;
  66. top: -100rpx;
  67. right: -100rpx;
  68. width: 500rpx;
  69. height: 500rpx;
  70. border-radius: 50%;
  71. background: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
  72. opacity: 0.15;
  73. filter: blur(40rpx);
  74. }
  75. .bg-shape2 {
  76. position: absolute;
  77. bottom: -150rpx;
  78. left: -100rpx;
  79. width: 600rpx;
  80. height: 600rpx;
  81. border-radius: 50%;
  82. background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  83. opacity: 0.15;
  84. filter: blur(50rpx);
  85. }
  86. .loading-box {
  87. display: flex;
  88. flex-direction: column;
  89. align-items: center;
  90. z-index: 10;
  91. /* 与左侧输入框 60(height) + 40(padding) + 4(border) 高度保持一致 */
  92. border-radius: 20rpx;
  93. background: #f1f5f9;
  94. flex-shrink: 0;
  95. cursor: pointer;
  96. }
  97. .options {
  98. display: flex;
  99. justify-content: space-between;
  100. align-items: center;
  101. margin-bottom: 50rpx;
  102. }
  103. .forgot {
  104. font-size: 26rpx;
  105. color: #3b82f6;
  106. font-weight: 500;
  107. padding: 10rpx 0;
  108. }
  109. .footer {
  110. margin-top: 40rpx;
  111. display: flex;
  112. justify-content: center;
  113. align-items: center;
  114. }
  115. .footer-text {
  116. font-size: 26rpx;
  117. color: #64748b;
  118. }
  119. .footer-link {
  120. font-size: 26rpx;
  121. color: #3b82f6;
  122. font-weight: 600;
  123. margin-left: 10rpx;
  124. }
  125. </style>