Browse Source

feat(ui-kit): 资料/报名选择/我的报名/沙龙列表五态组件化

material、enroll/list、salon/list、salon/mine 的自绘「加载中/空态」文本统一替换为 LoadingSkeleton/ErrorState/EmptyState,补错误态与重试;空态 CTA 仅重新加载
liaoxg 1 day ago
parent
commit
39c369367f

+ 19 - 7
train-frontend/pages/enroll/list.vue

@@ -3,8 +3,9 @@
     <view class="section-card">
       <text class="section-title">选择课程</text>
       <text class="card-desc">填写联系方式与准备情况,缴费后由助教分配班次</text>
-      <view v-if="loading" class="empty-tip">加载中…</view>
-      <view v-else-if="courses.length === 0" class="empty-tip">暂无可报名课程</view>
+      <LoadingSkeleton v-if="loading" :rows="3" />
+      <ErrorState v-else-if="error" message="课程加载失败" @retry="loadCourses" />
+      <EmptyState v-else-if="courses.length === 0" icon="📚" title="暂无可报名课程" desc="新课程发布后可在此报名" action-text="重新加载" @action="loadCourses" />
       <view v-else>
         <view class="course-card" v-for="item in courses" :key="item.id">
           <view class="course-head">
@@ -38,8 +39,9 @@
 
     <view class="section-card">
       <text class="section-title">我的报名</text>
-      <view v-if="mineLoading" class="empty-tip">加载中…</view>
-      <view v-else-if="mineList.length === 0" class="empty-tip">暂无报名记录</view>
+      <LoadingSkeleton v-if="mineLoading" :rows="2" />
+      <ErrorState v-else-if="mineError" message="我的报名加载失败" @retry="loadMine" />
+      <EmptyState v-else-if="mineList.length === 0" icon="📭" title="暂无报名记录" desc="报名后会在此展示进度" />
       <view v-else>
         <view class="mine-item" v-for="item in mineList" :key="item.id">
           <view class="mine-head">
@@ -70,14 +72,20 @@ import { getCourseList, getMyEnrollments, cancelPayOrder, activateEnrollment } f
 import { fenToYuan, formatDateTime } from '@/utils/format.js'
 import { guardPage } from '@/utils/guard.js'
 import { captureInviteCode } from '@/utils/invite.js'
+import LoadingSkeleton from '@/components/loading-skeleton.vue'
+import ErrorState from '@/components/error-state.vue'
+import EmptyState from '@/components/empty-state.vue'
 
 export default {
+  components: { LoadingSkeleton, ErrorState, EmptyState },
   data() {
     return {
       courses: [],
       mineList: [],
       loading: false,
-      mineLoading: false
+      mineLoading: false,
+      error: false,
+      mineError: false
     }
   },
   onLoad(options) {
@@ -96,6 +104,7 @@ export default {
       var self = this
       var statusLabelMap = { draft: '未开放', active: '报名中', finished: '已结束' }
       self.loading = true
+      self.error = false
       getCourseList().then(function(resp) {
         var raw = resp.data || []
         self.courses = raw.map(function(item) {
@@ -108,7 +117,7 @@ export default {
           return item
         })
       }).catch(function() {
-        uni.showToast({ title: '加载课程失败', icon: 'none' })
+        self.error = true
       }).finally(function() {
         self.loading = false
       })
@@ -117,6 +126,7 @@ export default {
       var self = this
       var enrollLabelMap = { active: '学籍生效中', dormant: '学籍已休眠', none: '无学籍' }
       self.mineLoading = true
+      self.mineError = false
       getMyEnrollments().then(function(resp) {
         var raw = resp.data || []
         self.mineList = raw.map(function(item) {
@@ -128,7 +138,9 @@ export default {
           item.enrollmentStatusLabel = enrollLabelMap[st] || '未知'
           return item
         })
-      }).catch(function() {}).finally(function() {
+      }).catch(function() {
+        self.mineError = true
+      }).finally(function() {
         self.mineLoading = false
       })
     },

+ 13 - 6
train-frontend/pages/material/index.vue

@@ -4,10 +4,11 @@
       <text class="section-title">课前资料包</text>
       <text class="card-desc">进班后可见本班次专属资料与通用资料</text>
 
-      <view v-if="loading" class="empty-text">加载中…</view>
-      <view v-else-if="list.length === 0" class="empty-text">暂无课前资料,请留意后续更新</view>
+      <LoadingSkeleton v-if="loading" :rows="2" />
+      <ErrorState v-else-if="error" message="资料加载失败" @retry="loadMaterials" />
+      <EmptyState v-else-if="list.length === 0" icon="📄" title="暂无课前资料" desc="请留意后续更新" />
 
-      <view class="material-list">
+      <view v-else class="material-list">
         <view class="material-item" v-for="(m, idx) in list" :key="idx">
           <text class="material-icon">📄</text>
           <view class="material-info">
@@ -25,12 +26,17 @@
 <script>
 import { getClassMaterials } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.js'
+import LoadingSkeleton from '@/components/loading-skeleton.vue'
+import ErrorState from '@/components/error-state.vue'
+import EmptyState from '@/components/empty-state.vue'
 
 export default {
+  components: { LoadingSkeleton, ErrorState, EmptyState },
   data() {
     return {
       list: [],
-      loading: true
+      loading: true,
+      error: false
     }
   },
   onShow() {
@@ -41,10 +47,11 @@ export default {
     loadMaterials() {
       var self = this
       self.loading = true
+      self.error = false
       getClassMaterials().then(function(resp) {
         self.list = resp.data || []
-      }).catch(function(err) {
-        uni.showToast({ title: (err && err.message) || '获取资料失败', icon: 'none' })
+      }).catch(function() {
+        self.error = true
       }).finally(function() {
         self.loading = false
       })

+ 10 - 4
train-frontend/pages/salon/list.vue

@@ -9,8 +9,9 @@
         <text class="mine-link" @click="goMine">我的报名</text>
       </view>
       
-      <view v-if="loading" class="empty-tip">加载中…</view>
-      <view v-else-if="salons.length === 0" class="empty-tip">暂无活动沙龙</view>
+      <LoadingSkeleton v-if="loading" :rows="3" />
+      <ErrorState v-else-if="error" message="沙龙加载失败" @retry="loadSalons" />
+      <EmptyState v-else-if="salons.length === 0" icon="🎪" title="暂无活动沙龙" desc="新沙龙发布后会出现在这里" />
       <view v-else>
         <view
           class="salon-card"
@@ -97,13 +98,17 @@ import { guardPage } from '@/utils/guard.js'
 import { loadInviteCode, getInviteCode, buildSharePath, resolveAssetUrl } from '@/utils/share.js'
 import { captureInviteCode, getSceneParams } from '@/utils/invite.js'
 import SharePoster from '@/components/share-poster/share-poster.vue'
+import LoadingSkeleton from '@/components/loading-skeleton.vue'
+import ErrorState from '@/components/error-state.vue'
+import EmptyState from '@/components/empty-state.vue'
 
 export default {
-  components: { SharePoster },
+  components: { SharePoster, LoadingSkeleton, ErrorState, EmptyState },
   data() {
     return {
       salons: [],
       loading: false,
+      error: false,
       member: {},
       shareTarget: null,
       highlightSalonId: '',
@@ -179,13 +184,14 @@ export default {
     loadSalons() {
       var self = this
       self.loading = true
+      self.error = false
       getSalonList().then(function(resp) {
         self.salons = resp.data || []
         self.$nextTick(function() {
           self.scrollToHighlight()
         })
       }).catch(function() {
-        uni.showToast({ title: '加载沙龙失败', icon: 'none' })
+        self.error = true
       }).finally(function() {
         self.loading = false
       })

+ 10 - 3
train-frontend/pages/salon/mine.vue

@@ -4,8 +4,9 @@
       <text class="section-title">我的沙龙</text>
       <text class="card-desc">查看报名、现场签到与会后反馈</text>
 
-      <view v-if="loading" class="empty-tip">加载中…</view>
-      <view v-else-if="list.length === 0" class="empty-tip">暂无报名记录</view>
+      <LoadingSkeleton v-if="loading" :rows="3" />
+      <ErrorState v-else-if="error" message="报名记录加载失败" @retry="loadMine" />
+      <EmptyState v-else-if="list.length === 0" icon="📭" title="暂无报名记录" desc="报名沙龙后会在此展示" />
       <view v-else>
         <view class="salon-card" v-for="item in list" :key="item.enrollmentId">
           <view class="salon-head">
@@ -63,12 +64,17 @@
 <script>
 import { getMySalons, salonCheckin } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.js'
+import LoadingSkeleton from '@/components/loading-skeleton.vue'
+import ErrorState from '@/components/error-state.vue'
+import EmptyState from '@/components/empty-state.vue'
 
 export default {
+  components: { LoadingSkeleton, ErrorState, EmptyState },
   data() {
     return {
       list: [],
       loading: false,
+      error: false,
       checking: false,
       submitting: false,
       themeMap: {
@@ -122,10 +128,11 @@ export default {
     loadMine: function() {
       var self = this
       self.loading = true
+      self.error = false
       getMySalons().then(function(resp) {
         self.list = resp.data || []
       }).catch(function() {
-        uni.showToast({ title: '加载失败', icon: 'none' })
+        self.error = true
       }).finally(function() {
         self.loading = false
       })