index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <view class="home-page">
  3. <view class="banner">
  4. <text class="banner-icon">🚀</text>
  5. <text class="banner-title">爱伴·AI之旅</text>
  6. <text class="banner-sub">{{ courseLabel }}</text>
  7. <button v-if="!isLoggedIn" class="login-entry-btn" @click="showLoginSheet">点击登录</button>
  8. </view>
  9. <view class="status-card">
  10. <view class="status-row">
  11. <text class="status-label">校友校验</text>
  12. <text :class="['status-value', verifyClass]">{{ verifyLabel }}</text>
  13. </view>
  14. <view class="status-row">
  15. <text class="status-label">班级</text>
  16. <text class="status-value">{{ classLabel }}</text>
  17. </view>
  18. <view class="status-row">
  19. <text class="status-label">小组</text>
  20. <text class="status-value">{{ groupLabel }}</text>
  21. </view>
  22. </view>
  23. <view class="section-title">功能导航</view>
  24. <view class="nav-grid">
  25. <view class="nav-item" @click="goTo('/pages/class/index')">
  26. <text class="nav-icon">🏫</text>
  27. <text class="nav-text">进班</text>
  28. </view>
  29. <view class="nav-item" @click="goTo('/pages/group/index')">
  30. <text class="nav-icon">👥</text>
  31. <text class="nav-text">小组</text>
  32. </view>
  33. <view class="nav-item" @click="goTo('/pages/assignment/index')">
  34. <text class="nav-icon">📋</text>
  35. <text class="nav-text">三本账</text>
  36. </view>
  37. <view class="nav-item" @click="switchToTab('/pages/checkin/index')">
  38. <text class="nav-icon">✅</text>
  39. <text class="nav-text">装机打卡</text>
  40. </view>
  41. <view class="nav-item" @click="goTo('/pages/upload/index')">
  42. <text class="nav-icon">📤</text>
  43. <text class="nav-text">成果上传</text>
  44. </view>
  45. <view class="nav-item" @click="goTo('/pages/teaching/index')">
  46. <text class="nav-icon">📝</text>
  47. <text class="nav-text">教学卡</text>
  48. </view>
  49. <view class="nav-item" @click="goTo('/pages/roadmap/index')">
  50. <text class="nav-icon">🎤</text>
  51. <text class="nav-text">路演材料</text>
  52. </view>
  53. <view class="nav-item" @click="switchToTab('/pages/vote/index')">
  54. <text class="nav-icon">🗳️</text>
  55. <text class="nav-text">投票</text>
  56. </view>
  57. <view class="nav-item" @click="goTo('/pages/scoreboard/index')">
  58. <text class="nav-icon">🏆</text>
  59. <text class="nav-text">积分榜</text>
  60. </view>
  61. <view class="nav-item" @click="goTo('/pages/plan/index')">
  62. <text class="nav-icon">📅</text>
  63. <text class="nav-text">行动计划</text>
  64. </view>
  65. <view class="nav-item" @click="goTo('/pages/survey/index')">
  66. <text class="nav-icon">📝</text>
  67. <text class="nav-text">兴趣调研</text>
  68. </view>
  69. <view class="nav-item" @click="goTo('/pages/verify/index')">
  70. <text class="nav-icon">🎓</text>
  71. <text class="nav-text">校友校验</text>
  72. </view>
  73. </view>
  74. <!-- Login Bottom Sheet -->
  75. <view class="login-sheet-mask" :class="{ 'sheet-open': loginSheetVisible }" @click="hideLoginSheet">
  76. <view class="login-sheet-panel" @click.stop>
  77. <view class="sheet-handle"></view>
  78. <view class="sheet-content">
  79. <view class="sheet-header">
  80. <text class="sheet-title">欢迎回来</text>
  81. <text class="sheet-sub">登录以解锁更多成长功能</text>
  82. </view>
  83. <button class="sheet-login-btn" @click="handleLogin" :loading="loginLoading" :disabled="loginLoading">
  84. 微信一键登录
  85. </button>
  86. <view class="sheet-footer">
  87. <text class="sheet-footer-text">登录即代表同意服务协议</text>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. </template>
  94. <script>
  95. import { getMyGroup, getClassInfo, wechatLogin, getMyCourse } from '@/utils/api.js'
  96. export default {
  97. data() {
  98. return {
  99. groupInfo: null,
  100. classInfo: null,
  101. courseName: '',
  102. loginSheetVisible: false,
  103. loginLoading: false
  104. }
  105. },
  106. computed: {
  107. isLoggedIn() {
  108. return this.$store.getters.isLoggedIn
  109. },
  110. courseLabel() {
  111. return this.courseName || 'L0 家立方-AI管家成长营'
  112. },
  113. verifyLabel() {
  114. var v = this.$store.state.alumniVerify
  115. if (v === 'accepted') return '✅ 已通过'
  116. if (v === 'pending') return '⏳ 待审核'
  117. return '❌ 未校验'
  118. },
  119. verifyClass() {
  120. var v = this.$store.state.alumniVerify
  121. return v === 'accepted' ? 'val-pass' : (v === 'pending' ? 'val-pending' : 'val-fail')
  122. },
  123. classLabel() {
  124. return this.classInfo ? this.classInfo.name : '未进班'
  125. },
  126. groupLabel() {
  127. return this.groupInfo ? this.groupInfo.name : '未入组'
  128. }
  129. },
  130. onShow() {
  131. this.loadInfo()
  132. },
  133. onLoad() {
  134. // 注册全局登录浮层触发事件(uni-app 页面生命周期 onLoad 早于 created 时机更稳)
  135. var self = this
  136. try {
  137. uni.$on('showLoginSheet', function() {
  138. self.showLoginSheet()
  139. })
  140. } catch (e) {
  141. console.error('[home] 注册 showLoginSheet 监听失败', e)
  142. }
  143. },
  144. onUnload() {
  145. try {
  146. uni.$off('showLoginSheet')
  147. } catch (e) {}
  148. },
  149. methods: {
  150. loadInfo() {
  151. if (!this.isLoggedIn) return
  152. var self = this
  153. if (this.$store.state.classId) {
  154. getClassInfo().then(function(resp) {
  155. self.classInfo = resp.data
  156. }).catch(function() {})
  157. }
  158. getMyGroup().then(function(resp) {
  159. self.groupInfo = resp.data
  160. }).catch(function() {})
  161. getMyCourse().then(function(resp) {
  162. var d = resp.data || {}
  163. var c = d.course
  164. if (c && c.name) {
  165. self.courseName = (c.level ? c.level + ' ' : '') + c.name
  166. }
  167. }).catch(function() {})
  168. },
  169. showLoginSheet() {
  170. this.loginSheetVisible = true
  171. },
  172. hideLoginSheet() {
  173. this.loginSheetVisible = false
  174. },
  175. handleLogin() {
  176. if (this.loginLoading) return
  177. this.loginLoading = true
  178. var self = this
  179. wx.login({
  180. success: function(res) {
  181. if (res.code) {
  182. wechatLogin(res.code).then(function(resp) {
  183. var data = resp.data
  184. self.$store.dispatch('login', data)
  185. uni.showToast({ title: '登录成功', icon: 'success' })
  186. self.hideLoginSheet()
  187. self.loadInfo()
  188. }).catch(function(err) {
  189. console.error('登录失败', err)
  190. }).finally(function() {
  191. self.loginLoading = false
  192. })
  193. } else {
  194. uni.showToast({ title: '微信登录失败', icon: 'none' })
  195. self.loginLoading = false
  196. }
  197. },
  198. fail: function() {
  199. uni.showToast({ title: '微信登录失败', icon: 'none' })
  200. self.loginLoading = false
  201. }
  202. })
  203. },
  204. goTo(url) {
  205. uni.navigateTo({ url: url })
  206. },
  207. switchToTab(url) {
  208. uni.switchTab({ url: url })
  209. }
  210. }
  211. }
  212. </script>
  213. <style scoped>
  214. .home-page { min-height: 100vh; background: #F5F5F5; padding: 0 32rpx 32rpx; }
  215. .banner { background: linear-gradient(135deg, #F97316, #EA580C); border-radius: 0 0 32rpx 32rpx; padding: 60rpx 32rpx 48rpx; text-align: center; margin: 0 -32rpx 24rpx; position: relative; }
  216. .banner-icon { font-size: 72rpx; display: block; margin-bottom: 16rpx; }
  217. .banner-title { display: block; font-size: 40rpx; font-weight: 700; color: #FFF; margin-bottom: 8rpx; }
  218. .banner-sub { display: block; font-size: 26rpx; color: rgba(255,255,255,0.85); margin-bottom: 24rpx; }
  219. .login-entry-btn {
  220. background: #FFF;
  221. color: #EA580C;
  222. font-size: 24rpx;
  223. font-weight: 600;
  224. border-radius: 100rpx;
  225. padding: 0 32rpx;
  226. height: 64rpx;
  227. line-height: 64rpx;
  228. margin: 0 auto;
  229. border: none;
  230. }
  231. .status-card { background: #FFF; border-radius: 16rpx; padding: 24rpx 32rpx; margin-bottom: 24rpx; }
  232. .status-row { display: flex; justify-content: space-between; padding: 14rpx 0; border-bottom: 1rpx solid #F1F5F9; }
  233. .status-row:last-child { border-bottom: none; }
  234. .status-label { font-size: 28rpx; color: #64748B; }
  235. .status-value { font-size: 28rpx; color: #1E293B; font-weight: 500; }
  236. .val-pass { color: #22C55E; }
  237. .val-pending { color: #FFB74D; }
  238. .val-fail { color: #EF5350; }
  239. .section-title { font-size: 30rpx; font-weight: 600; color: #1E293B; margin-bottom: 16rpx; border-left: 8rpx solid #F97316; padding-left: 16rpx; }
  240. .nav-grid { display: flex; flex-wrap: wrap; gap: 0; background: #FFF; border-radius: 16rpx; overflow: hidden; }
  241. .nav-item { width: 25%; display: flex; flex-direction: column; align-items: center; padding: 28rpx 0; }
  242. .nav-item:active { background: #F8FAFC; }
  243. .nav-icon { font-size: 44rpx; margin-bottom: 8rpx; }
  244. .nav-text { font-size: 24rpx; color: #1E293B; text-align: center; }
  245. /* Bottom Sheet Styles */
  246. .login-sheet-mask {
  247. position: fixed;
  248. top: 0;
  249. left: 0;
  250. right: 0;
  251. bottom: 0;
  252. background: rgba(0, 0, 0, 0.5);
  253. z-index: 100;
  254. display: flex;
  255. flex-direction: column;
  256. justify-content: flex-end;
  257. opacity: 0;
  258. visibility: hidden;
  259. pointer-events: none;
  260. transition: opacity 0.3s ease;
  261. }
  262. .login-sheet-mask.sheet-open {
  263. opacity: 1;
  264. visibility: visible;
  265. pointer-events: auto;
  266. }
  267. .login-sheet-panel {
  268. background: #FFF;
  269. border-radius: 32rpx 32rpx 0 0;
  270. padding-bottom: calc(constant(safe-area-inset-bottom) + 40rpx);
  271. width: 100%;
  272. transform: translateY(100%);
  273. transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
  274. }
  275. .login-sheet-mask.sheet-open .login-sheet-panel {
  276. transform: translateY(0);
  277. }
  278. .sheet-handle {
  279. width: 80rpx;
  280. height: 8rpx;
  281. background: #E2E8F0;
  282. border-radius: 4rpx;
  283. margin: 24rpx auto;
  284. }
  285. .sheet-content {
  286. padding: 0 60rpx 40rpx;
  287. display: flex;
  288. flex-direction: column;
  289. align-items: center;
  290. }
  291. .sheet-header {
  292. text-align: center;
  293. margin-bottom: 48rpx;
  294. }
  295. .sheet-title {
  296. display: block;
  297. font-size: 36rpx;
  298. font-weight: 700;
  299. color: #1E293B;
  300. margin-bottom: 12rpx;
  301. }
  302. .sheet-sub {
  303. display: block;
  304. font-size: 26rpx;
  305. color: #64748B;
  306. }
  307. .sheet-login-btn {
  308. width: 100%;
  309. height: 96rpx;
  310. line-height: 96rpx;
  311. background: linear-gradient(135deg, #F97316, #EA580C);
  312. color: #FFF;
  313. font-size: 32rpx;
  314. font-weight: 600;
  315. border-radius: 48rpx;
  316. border: none;
  317. margin-bottom: 32rpx;
  318. }
  319. .sheet-login-btn:active {
  320. opacity: 0.9;
  321. }
  322. .sheet-footer {
  323. text-align: center;
  324. }
  325. .sheet-footer-text {
  326. font-size: 22rpx;
  327. color: #94A3B8;
  328. }
  329. </style>