index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="class-page">
  3. <view v-if="classInfo" class="class-card">
  4. <text class="card-title">当前班次</text>
  5. <view class="info-row">
  6. <text class="info-label">班次名称</text>
  7. <text class="info-value">{{ classInfo.name }}</text>
  8. </view>
  9. <view class="info-row">
  10. <text class="info-label">班级码</text>
  11. <text class="info-value">{{ classInfo.code }}</text>
  12. </view>
  13. <view class="info-row" v-if="classInfo.time">
  14. <text class="info-label">时间</text>
  15. <text class="info-value">{{ classInfo.time }}</text>
  16. </view>
  17. <view class="info-row" v-if="classInfo.place">
  18. <text class="info-label">地点</text>
  19. <text class="info-value">{{ classInfo.place }}</text>
  20. </view>
  21. <button class="go-btn" @click="goHome">进入首页</button>
  22. </view>
  23. <view v-else class="join-card">
  24. <text class="card-title">进班</text>
  25. <text class="card-desc">请输入班级码加入您的训练班级</text>
  26. <input class="code-input" v-model="classCode" placeholder="请输入班级码" />
  27. <text class="form-error" v-if="errorMsg">{{ errorMsg }}</text>
  28. <button class="join-btn" @click="handleJoin" :loading="loading" :disabled="loading">进班</button>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { joinClass, getClassInfo } from '@/utils/api.js'
  34. import { guardPage } from '@/utils/guard.js'
  35. export default {
  36. data() {
  37. return {
  38. classInfo: null,
  39. classCode: '',
  40. errorMsg: '',
  41. loading: false
  42. }
  43. },
  44. onShow() {
  45. if (!guardPage()) return
  46. this.loadClassInfo()
  47. },
  48. methods: {
  49. loadClassInfo() {
  50. var self = this
  51. getClassInfo().then(function(resp) {
  52. if (resp.data) {
  53. self.classInfo = resp.data
  54. self.$store.commit('setClassId', resp.data.id)
  55. }
  56. }).catch(function() {
  57. self.classInfo = null
  58. })
  59. },
  60. handleJoin() {
  61. if (!this.classCode.trim()) {
  62. this.errorMsg = '请输入班级码'
  63. return
  64. }
  65. this.errorMsg = ''
  66. if (this.loading) return
  67. this.loading = true
  68. var self = this
  69. joinClass(this.classCode).then(function(resp) {
  70. self.classInfo = resp.data
  71. self.$store.commit('setClassId', resp.data.classId)
  72. uni.showToast({ title: '进班成功', icon: 'success' })
  73. }).catch(function(err) {
  74. self.errorMsg = (err && err.message) || '进班失败'
  75. }).finally(function() {
  76. self.loading = false
  77. })
  78. },
  79. goHome() {
  80. uni.switchTab({ url: '/pages/index/index' })
  81. }
  82. }
  83. }
  84. </script>
  85. <style scoped>
  86. .class-page {
  87. min-height: 100vh;
  88. background: #F5F5F5;
  89. padding: 32rpx;
  90. }
  91. .class-card, .join-card {
  92. background: #FFFFFF;
  93. border-radius: 16rpx;
  94. padding: 40rpx 32rpx;
  95. }
  96. .card-title {
  97. display: block;
  98. font-size: 36rpx;
  99. font-weight: 700;
  100. color: #1E293B;
  101. margin-bottom: 32rpx;
  102. }
  103. .card-desc {
  104. display: block;
  105. font-size: 26rpx;
  106. color: #64748B;
  107. margin-bottom: 32rpx;
  108. }
  109. .info-row {
  110. display: flex;
  111. justify-content: space-between;
  112. padding: 20rpx 0;
  113. border-bottom: 1rpx solid #F1F5F9;
  114. }
  115. .info-label {
  116. font-size: 28rpx;
  117. color: #64748B;
  118. }
  119. .info-value {
  120. font-size: 28rpx;
  121. color: #1E293B;
  122. font-weight: 500;
  123. }
  124. .code-input {
  125. width: 100%;
  126. height: 88rpx;
  127. border: 2rpx solid #E2E8F0;
  128. border-radius: 12rpx;
  129. padding: 0 24rpx;
  130. font-size: 32rpx;
  131. color: #1E293B;
  132. background: #F8FAFC;
  133. margin-bottom: 16rpx;
  134. }
  135. .form-error {
  136. display: block;
  137. font-size: 24rpx;
  138. color: #EF5350;
  139. margin-bottom: 16rpx;
  140. }
  141. .go-btn, .join-btn {
  142. width: 100%;
  143. height: 88rpx;
  144. line-height: 88rpx;
  145. background: #F97316;
  146. color: #FFFFFF;
  147. font-size: 30rpx;
  148. font-weight: 600;
  149. border-radius: 44rpx;
  150. border: none;
  151. margin-top: 32rpx;
  152. }
  153. .go-btn:active, .join-btn:active {
  154. opacity: 0.85;
  155. }
  156. </style>