index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. export default {
  35. data() {
  36. return {
  37. classInfo: null,
  38. classCode: '',
  39. errorMsg: '',
  40. loading: false
  41. }
  42. },
  43. onShow() {
  44. this.loadClassInfo()
  45. },
  46. methods: {
  47. loadClassInfo() {
  48. var self = this
  49. getClassInfo().then(function(resp) {
  50. if (resp.data) {
  51. self.classInfo = resp.data
  52. self.$store.commit('setClassId', resp.data.id)
  53. }
  54. }).catch(function() {
  55. self.classInfo = null
  56. })
  57. },
  58. handleJoin() {
  59. if (!this.classCode.trim()) {
  60. this.errorMsg = '请输入班级码'
  61. return
  62. }
  63. this.errorMsg = ''
  64. if (this.loading) return
  65. this.loading = true
  66. var self = this
  67. joinClass(this.classCode).then(function(resp) {
  68. self.classInfo = resp.data
  69. self.$store.commit('setClassId', resp.data.classId)
  70. uni.showToast({ title: '进班成功', icon: 'success' })
  71. }).catch(function(err) {
  72. self.errorMsg = (err && err.message) || '进班失败'
  73. }).finally(function() {
  74. self.loading = false
  75. })
  76. },
  77. goHome() {
  78. uni.switchTab({ url: '/pages/index/index' })
  79. }
  80. }
  81. }
  82. </script>
  83. <style scoped>
  84. .class-page {
  85. min-height: 100vh;
  86. background: #F5F5F5;
  87. padding: 32rpx;
  88. }
  89. .class-card, .join-card {
  90. background: #FFFFFF;
  91. border-radius: 16rpx;
  92. padding: 40rpx 32rpx;
  93. }
  94. .card-title {
  95. display: block;
  96. font-size: 36rpx;
  97. font-weight: 700;
  98. color: #1E293B;
  99. margin-bottom: 32rpx;
  100. }
  101. .card-desc {
  102. display: block;
  103. font-size: 26rpx;
  104. color: #64748B;
  105. margin-bottom: 32rpx;
  106. }
  107. .info-row {
  108. display: flex;
  109. justify-content: space-between;
  110. padding: 20rpx 0;
  111. border-bottom: 1rpx solid #F1F5F9;
  112. }
  113. .info-label {
  114. font-size: 28rpx;
  115. color: #64748B;
  116. }
  117. .info-value {
  118. font-size: 28rpx;
  119. color: #1E293B;
  120. font-weight: 500;
  121. }
  122. .code-input {
  123. width: 100%;
  124. height: 88rpx;
  125. border: 2rpx solid #E2E8F0;
  126. border-radius: 12rpx;
  127. padding: 0 24rpx;
  128. font-size: 32rpx;
  129. color: #1E293B;
  130. background: #F8FAFC;
  131. margin-bottom: 16rpx;
  132. }
  133. .form-error {
  134. display: block;
  135. font-size: 24rpx;
  136. color: #EF5350;
  137. margin-bottom: 16rpx;
  138. }
  139. .go-btn, .join-btn {
  140. width: 100%;
  141. height: 88rpx;
  142. line-height: 88rpx;
  143. background: #F97316;
  144. color: #FFFFFF;
  145. font-size: 30rpx;
  146. font-weight: 600;
  147. border-radius: 44rpx;
  148. border: none;
  149. margin-top: 32rpx;
  150. }
  151. .go-btn:active, .join-btn:active {
  152. opacity: 0.85;
  153. }
  154. </style>