index1.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. import { getDingTalkAuthCode } from '@/utils/dingtalk';
  16. import * as dd from 'dingtalk-jsapi';
  17. const userStore = useUserStore();
  18. const toastRef = ref<any>(null);
  19. onMounted(async () => {
  20. // --- 逻辑拦截 ---
  21. // 如果缓存里已经有 Token,说明当前处于已登录状态
  22. if (userStore.token) {
  23. uni.switchTab({ url: '/pages/home/index' }).catch(() => {
  24. uni.reLaunch({ url: '/pages/home/index' });
  25. });
  26. return;
  27. }
  28. // 仅在钉钉环境下尝试免登
  29. if (dd.env.platform !== 'notInDingTalk') {
  30. try {
  31. const corpId = uni.getLaunchOptionsSync()?.query?.corpId || import.meta.env.VITE_DINGTALK_CORPID;
  32. const code = await getDingTalkAuthCode(corpId);
  33. if (code) {
  34. await userStore.dingTalkLogin(code);
  35. toastRef.value.show({ message: '登录成功', type: 'success' });
  36. // 成功,跳转首页
  37. setTimeout(() => {
  38. uni.switchTab({ url: '/pages/home/index' }).catch(() => {
  39. uni.reLaunch({ url: '/pages/home/index' });
  40. });
  41. }, 800);
  42. } else {
  43. throw new Error('未获取到授权码');
  44. }
  45. } catch (error) {
  46. console.error('DingTalk Login Failure in Login Page:', error);
  47. // 免登失败(或账号未绑定),引导去注册
  48. uni.reLaunch({ url: '/pages/login/register' });
  49. }
  50. } else {
  51. // 不在钉钉环境下,直接跳转到注册页(因为不需要登录页)
  52. uni.reLaunch({ url: '/pages/login/register' });
  53. }
  54. });
  55. </script>
  56. <style scoped>
  57. .container {
  58. min-height: 100vh;
  59. position: relative;
  60. background: #f8fafc;
  61. overflow: hidden;
  62. display: flex;
  63. justify-content: center;
  64. align-items: center;
  65. padding: 0 40rpx;
  66. }
  67. .bg-shape {
  68. position: absolute;
  69. top: -100rpx;
  70. right: -100rpx;
  71. width: 500rpx;
  72. height: 500rpx;
  73. border-radius: 50%;
  74. background: linear-gradient(135deg, #3b82f6 0%, #2dd4bf 100%);
  75. opacity: 0.15;
  76. filter: blur(40rpx);
  77. }
  78. .bg-shape2 {
  79. position: absolute;
  80. bottom: -150rpx;
  81. left: -100rpx;
  82. width: 600rpx;
  83. height: 600rpx;
  84. border-radius: 50%;
  85. background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  86. opacity: 0.15;
  87. filter: blur(50rpx);
  88. }
  89. .loading-box {
  90. display: flex;
  91. flex-direction: column;
  92. align-items: center;
  93. z-index: 10;
  94. /* 与左侧输入框 60(height) + 40(padding) + 4(border) 高度保持一致 */
  95. border-radius: 20rpx;
  96. background: #f1f5f9;
  97. flex-shrink: 0;
  98. cursor: pointer;
  99. }
  100. .options {
  101. display: flex;
  102. justify-content: space-between;
  103. align-items: center;
  104. margin-bottom: 50rpx;
  105. }
  106. .forgot {
  107. font-size: 26rpx;
  108. color: #3b82f6;
  109. font-weight: 500;
  110. padding: 10rpx 0;
  111. }
  112. .footer {
  113. margin-top: 40rpx;
  114. display: flex;
  115. justify-content: center;
  116. align-items: center;
  117. }
  118. .footer-text {
  119. font-size: 26rpx;
  120. color: #64748b;
  121. }
  122. .footer-link {
  123. font-size: 26rpx;
  124. color: #3b82f6;
  125. font-weight: 600;
  126. margin-left: 10rpx;
  127. }
  128. </style>