index.vue 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view class="material-page">
  3. <view class="section-card">
  4. <text class="section-title">课前资料包</text>
  5. <text class="card-desc">进班后可见本班次专属资料与通用资料</text>
  6. <LoadingSkeleton v-if="loading" :rows="2" />
  7. <ErrorState v-else-if="error" message="资料加载失败" @retry="loadMaterials" />
  8. <EmptyState v-else-if="list.length === 0" icon="📄" title="暂无课前资料" desc="请留意后续更新" />
  9. <view v-else class="material-list">
  10. <view class="material-item" v-for="(m, idx) in list" :key="idx">
  11. <text class="material-icon">📄</text>
  12. <view class="material-info">
  13. <text class="material-title">{{ m.title }}</text>
  14. <text class="material-badge" v-if="m.classId">班次专属</text>
  15. <text class="material-badge general" v-else>通用</text>
  16. </view>
  17. <text class="material-preview" @click="preview(m)">预览</text>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { getClassMaterials } from '@/utils/api.js'
  25. import { guardPage } from '@/utils/guard.js'
  26. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  27. import ErrorState from '@/components/error-state.vue'
  28. import EmptyState from '@/components/empty-state.vue'
  29. export default {
  30. components: { LoadingSkeleton, ErrorState, EmptyState },
  31. data() {
  32. return {
  33. list: [],
  34. loading: true,
  35. error: false
  36. }
  37. },
  38. onShow() {
  39. if (!guardPage()) return
  40. this.loadMaterials()
  41. },
  42. methods: {
  43. loadMaterials() {
  44. var self = this
  45. self.loading = true
  46. self.error = false
  47. getClassMaterials().then(function(resp) {
  48. self.list = resp.data || []
  49. }).catch(function() {
  50. self.error = true
  51. }).finally(function() {
  52. self.loading = false
  53. })
  54. },
  55. // 预览占位:test-mode 未接入文件服务,提示跳转后台配置的附件地址
  56. preview(m) {
  57. if (m.fileUrl) {
  58. uni.showToast({ title: '预览功能待接入,请用文件地址访问', icon: 'none' })
  59. } else {
  60. uni.showToast({ title: '该资料暂无附件', icon: 'none' })
  61. }
  62. }
  63. }
  64. }
  65. </script>
  66. <style scoped>
  67. .material-page { min-height: 100vh; background: #F5FAFE; padding: 24rpx 32rpx; }
  68. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
  69. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  70. .card-desc { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 28rpx; }
  71. .material-list { margin-top: 8rpx; }
  72. .material-item { display: flex; align-items: center; padding: 24rpx 0; border-bottom: 1rpx solid #E3ECF4; }
  73. .material-icon { font-size: 40rpx; margin-right: 16rpx; }
  74. .material-info { flex: 1; display: flex; flex-direction: column; }
  75. .material-title { font-size: 28rpx; font-weight: 500; color: #1E3A5F; }
  76. .material-badge { display: inline-block; align-self: flex-start; font-size: 20rpx; color: #2E6FA8; background: #E8F3FC; padding: 2rpx 12rpx; border-radius: 6rpx; margin-top: 8rpx; }
  77. .material-badge.general { color: #3B5A78; background: #E3ECF4; }
  78. .material-preview { font-size: 26rpx; color: #2E6FA8; margin-left: 16rpx; }
  79. .empty-text { font-size: 26rpx; color: #6B7B8C; text-align: center; padding: 40rpx 0; }
  80. </style>