index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="login-page">
  3. <view class="login-bg">
  4. <view class="login-content">
  5. <view class="logo-area">
  6. <view class="logo-icon">🤖</view>
  7. <text class="logo-title">爱伴·AI之旅</text>
  8. <text class="logo-subtitle">L0 家立方-AI管家成长营</text>
  9. </view>
  10. <view class="login-btn-area">
  11. <button class="login-btn" @click="handleLogin" :loading="loading" :disabled="loading">
  12. 微信一键登录
  13. </button>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import { wechatLogin } from '@/utils/api.js'
  21. export default {
  22. data() {
  23. return {
  24. loading: false
  25. }
  26. },
  27. methods: {
  28. handleLogin() {
  29. if (this.loading) return
  30. this.loading = true
  31. var self = this
  32. wx.login({
  33. success: function(res) {
  34. if (res.code) {
  35. wechatLogin(res.code).then(function(resp) {
  36. var data = resp.data
  37. self.$store.dispatch('login', data)
  38. uni.showToast({ title: '登录成功', icon: 'success' })
  39. setTimeout(function() {
  40. if (!data.alumniVerify || data.alumniVerify === 'pending') {
  41. uni.redirectTo({ url: '/pages/verify/index' })
  42. } else if (!data.classId) {
  43. uni.redirectTo({ url: '/pages/class/index' })
  44. } else {
  45. uni.switchTab({ url: '/pages/index/index' })
  46. }
  47. }, 800)
  48. }).catch(function(err) {
  49. console.error('登录失败', err)
  50. }).finally(function() {
  51. self.loading = false
  52. })
  53. } else {
  54. uni.showToast({ title: '微信登录失败', icon: 'none' })
  55. self.loading = false
  56. }
  57. },
  58. fail: function() {
  59. uni.showToast({ title: '微信登录失败', icon: 'none' })
  60. self.loading = false
  61. }
  62. })
  63. }
  64. }
  65. }
  66. </script>
  67. <style scoped>
  68. .login-page {
  69. min-height: 100vh;
  70. background: linear-gradient(135deg, #F97316, #EA580C);
  71. display: flex;
  72. flex-direction: column;
  73. }
  74. .login-bg {
  75. flex: 1;
  76. display: flex;
  77. flex-direction: column;
  78. justify-content: center;
  79. align-items: center;
  80. }
  81. .login-content {
  82. display: flex;
  83. flex-direction: column;
  84. align-items: center;
  85. padding: 0 60rpx;
  86. }
  87. .logo-area {
  88. display: flex;
  89. flex-direction: column;
  90. align-items: center;
  91. margin-bottom: 120rpx;
  92. }
  93. .logo-icon {
  94. font-size: 120rpx;
  95. margin-bottom: 30rpx;
  96. }
  97. .logo-title {
  98. font-size: 48rpx;
  99. font-weight: 700;
  100. color: #FFFFFF;
  101. margin-bottom: 16rpx;
  102. }
  103. .logo-subtitle {
  104. font-size: 28rpx;
  105. color: rgba(255,255,255,0.85);
  106. }
  107. .login-btn-area {
  108. width: 100%;
  109. }
  110. .login-btn {
  111. width: 100%;
  112. height: 96rpx;
  113. line-height: 96rpx;
  114. background: #FFFFFF;
  115. color: #F97316;
  116. font-size: 32rpx;
  117. font-weight: 600;
  118. border-radius: 48rpx;
  119. border: none;
  120. }
  121. .login-btn:active {
  122. opacity: 0.85;
  123. }
  124. </style>