Browse Source

feat(ui-kit): 8 代表页五态体系接入(骨架/错误/空态同槽位)

首页、课程列表、课程详情、报名表单、成果上传、工作台、待办、我的 8 页按 ui-kit 代表页原型接入 LoadingSkeleton/ErrorState/EmptyState,补齐 loading/error/empty 同槽位状态与重试;空态 CTA 仅重新加载/返回列表/返回首页
liaoxg 20 hours ago
parent
commit
a4eda930ef

+ 29 - 3
train-frontend/pages/checkin/index.vue

@@ -1,5 +1,9 @@
 <template>
   <view class="checkin-page">
+    <!-- 加载骨架 / 错误态 -->
+    <LoadingSkeleton v-if="loading" :rows="3" />
+    <ErrorState v-else-if="error" message="待办状态加载失败" @retry="loadStatus" />
+    <template v-else>
     <view class="section-card">
       <text class="section-title">装机打卡</text>
       <view v-if="checkinDone" class="status-badge done">✓ 已完成 (+10分)</view>
@@ -57,14 +61,18 @@
         </view>
       </view>
     </view>
+    </template>
   </view>
 </template>
 
 <script>
 import { checkin, getCheckinStatus, prepCheck, getPrepCheckStatus, uploadFile } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.js'
+import LoadingSkeleton from '@/components/loading-skeleton.vue'
+import ErrorState from '@/components/error-state.vue'
 
 export default {
+  components: { LoadingSkeleton, ErrorState },
   data() {
     return {
       checkinDone: false,
@@ -78,7 +86,9 @@ export default {
         hasNone: false,
         useSample: 0
       },
-      prepLoading: false
+      prepLoading: false,
+      loading: true,
+      error: false
     }
   },
 onShow() {
@@ -88,12 +98,28 @@ onShow() {
   methods: {
     loadStatus() {
       var self = this
+      self.loading = true
+      self.error = false
+      var failed = 0
+      var finish = function() {
+        self.loading = false
+      }
       getCheckinStatus().then(function(resp) {
         self.checkinDone = resp.data === true
-      }).catch(function() {})
+        finish()
+      }).catch(function() {
+        failed = failed + 1
+        finish()
+        if (failed >= 2) self.error = true
+      })
       getPrepCheckStatus().then(function(resp) {
         self.prepDone = resp.data !== null && resp.data !== undefined
-      }).catch(function() {})
+        finish()
+      }).catch(function() {
+        failed = failed + 1
+        finish()
+        if (failed >= 2) self.error = true
+      })
     },
     chooseCheckinImage() {
       var self = this

+ 38 - 2
train-frontend/pages/course/detail.vue

@@ -1,5 +1,20 @@
 <template>
   <view class="course-detail-page">
+    <!-- 加载骨架 -->
+    <LoadingSkeleton v-if="loading" :rows="4" />
+    <!-- 错误态 -->
+    <ErrorState v-else-if="error" message="课程详情加载失败" @retry="loadAll" />
+    <!-- 空态 -->
+    <EmptyState
+      v-else-if="!course.id"
+      icon="🔍"
+      title="课程不存在或已下架"
+      desc="请返回课程列表重新选择"
+      action-text="返回课程列表"
+      @action="goBackCourse"
+    />
+    <!-- 正常态:课程内容 -->
+    <template v-else>
     <!-- 课程介绍 -->
     <view class="course-head">
       <text class="course-level">{{ course.level || 'L' }}</text>
@@ -122,6 +137,7 @@
       <button class="share-bar-btn" @click="copyShareLink">复制分享链接</button>
       <!-- #endif -->
     </view>
+    </template>
   </view>
 </template>
 
@@ -131,8 +147,12 @@ import { formatDateTime } from '@/utils/format.js'
 import { requireLogin } from '@/utils/guard.js'
 import { loadInviteCode, getInviteCode, buildSharePath } from '@/utils/share.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 {
       course: {},
@@ -142,7 +162,9 @@ export default {
       enrollment: null,
       progress: { done: 0, total: 0, items: [] },
       modules: [],
-      enterLoading: false
+      enterLoading: false,
+      loading: true,
+      error: false
     }
   },
   computed: {
@@ -260,6 +282,8 @@ export default {
     },
     loadAll() {
       var self = this
+      self.loading = true
+      self.error = false
       getMyCourse(self.courseId).then(function(resp) {
         var d = resp.data || {}
         var c = d.course || {}
@@ -268,7 +292,11 @@ export default {
         self.classTime = d.classTime || ''
         self.classPlace = d.classPlace || ''
         self.enrollment = d.enrollment || null
-      }).catch(function() {})
+      }).catch(function() {
+        self.error = true
+      }).finally(function() {
+        self.loading = false
+      })
       
       // 获取模块列表
       if (self.courseId) {
@@ -297,6 +325,14 @@ export default {
         uni.navigateTo({ url: g.url })
       }
     },
+    goBackCourse() {
+      var pages = getCurrentPages()
+      if (pages.length > 1) {
+        uni.navigateBack()
+      } else {
+        uni.redirectTo({ url: '/pages/course/index' })
+      }
+    },
     applyEnter() {
       var self = this
       if (!requireLogin()) return

+ 24 - 4
train-frontend/pages/course/index.vue

@@ -17,8 +17,22 @@
       </button>
     </view>
 
-    <view class="section-title">全部课程</view>
-    <view class="course-list">
+    <!-- 加载骨架 -->
+    <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 class="course-list">
+      <view class="section-title">全部课程</view>
       <view class="course-card" v-for="(c, idx) in courses" :key="idx">
         <view class="course-head">
           <text class="course-level">{{ c.level }}</text>
@@ -42,12 +56,17 @@
 import { getCourseList, enterCourse } from '@/utils/api.js'
 import { formatDateTime } from '@/utils/format.js'
 import { requireLogin } 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 {
       courses: [],
-      loading: false
+      loading: false,
+      error: false
     }
   },
   computed: {
@@ -72,10 +91,11 @@ export default {
       // 未登录也可浏览课程信息(后端 /api/course/list 已放行,我的状态为 none)
       var self = this
       self.loading = true
+      self.error = false
       getCourseList().then(function(resp) {
         self.courses = resp.data || []
       }).catch(function() {
-        uni.showToast({ title: '获取课程列表失败', icon: 'none' })
+        self.error = true
       }).finally(function() {
         self.loading = false
       })

+ 23 - 6
train-frontend/pages/enroll/form.vue

@@ -1,6 +1,15 @@
 <template>
   <view class="form-page">
-    <view class="section-card">
+    <!-- 参数错误空态:课程信息缺失,不可提交 -->
+    <EmptyState
+      v-if="invalid"
+      icon="🔍"
+      title="报名信息不完整"
+      desc="未获取到报名课程,请返回课程列表重新选择"
+      action-text="返回列表"
+      @action="goBackList"
+    />
+    <view v-else class="section-card">
       <text class="section-title">报名信息</text>
       <text class="card-desc">填写联系方式与准备情况,缴费后由助教分配班次</text>
 
@@ -58,8 +67,10 @@
 import { createEnrollment } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.js'
 import { captureInviteCode, getPendingInviteCode, consumeInviteCode } from '@/utils/invite.js'
+import EmptyState from '@/components/empty-state.vue'
 
 export default {
+  components: { EmptyState },
   data() {
     return {
       form: {
@@ -73,7 +84,8 @@ export default {
       },
       courseName: '',
       dataReadyList: [],
-      loading: false
+      loading: false,
+      invalid: false
     }
   },
   onLoad(options) {
@@ -86,13 +98,18 @@ export default {
     this.form.name = options && options.name ? decodeURIComponent(options.name) : ''
     this.form.phone = options && options.phone ? decodeURIComponent(options.phone) : ''
     if (!this.form.courseId) {
-      uni.showToast({ title: '参数错误', icon: 'none' })
-      setTimeout(function() {
-        uni.navigateBack({ delta: 1 })
-      }, 1500)
+      this.invalid = true
     }
   },
   methods: {
+    goBackList() {
+      var pages = getCurrentPages()
+      if (pages.length > 1) {
+        uni.navigateBack()
+      } else {
+        uni.redirectTo({ url: '/pages/course/index' })
+      }
+    },
     onLaptopChange(e) {
       this.form.bringLaptop = e.detail.value ? 1 : 0
     },

+ 30 - 5
train-frontend/pages/index/index.vue

@@ -58,9 +58,13 @@
       <text class="growth-guide-text">登录后查看我的成长档案</text>
     </view>
 
+    <!-- 加载骨架 / 错误态(登录后数据区块) -->
+    <LoadingSkeleton v-if="isLoggedIn && homeLoading" :rows="3" />
+    <ErrorState v-else-if="isLoggedIn && homeError" message="首页数据加载失败" @retry="loadInfo" />
+
     <!-- 平台动态 -->
     <view class="section-title">平台动态</view>
-    <view class="dynamic-list" v-if="dynamics.length">
+    <view class="dynamic-list" v-if="!homeLoading && !homeError && dynamics.length">
       <view class="dynamic-item" v-for="(d, idx) in dynamics" :key="idx" @click="goDynamic(d)">
         <text class="dynamic-tag" :class="d.tagClass">{{ d.tag }}</text>
         <view class="dynamic-main">
@@ -88,7 +92,7 @@
 
     <!-- 沙龙 -->
     <view class="section-title">沙龙</view>
-    <view class="course-mini-list">
+    <view class="course-mini-list" v-if="!homeLoading && !homeError">
       <view class="course-mini-card" v-for="(s, idx) in salonNews" :key="idx" @click="goSalon(s)">
         <view class="course-mini-head">
           <text class="course-mini-level">{{ mapTheme(s.theme) }}</text>
@@ -105,7 +109,7 @@
 
     <!-- 最近课程 -->
     <view class="section-title">最近课程</view>
-    <view class="course-mini-list">
+    <view class="course-mini-list" v-if="!homeLoading && !homeError">
       <view class="course-mini-card" v-for="(c, idx) in recentCourses" :key="idx" @click="goToCourse(c)">
         <view class="course-mini-head">
           <text class="course-mini-level">{{ c.level || 'L' }}</text>
@@ -159,8 +163,11 @@ import { wechatLogin, wechatPhoneLogin, getCourseList, getMyEnrollments, getMyBa
 import { formatDateTime } from '@/utils/format.js'
 import { loadInviteCode, getInviteCode, buildSharePath } from '@/utils/share.js'
 import { captureInviteCode } from '@/utils/invite.js'
+import LoadingSkeleton from '@/components/loading-skeleton.vue'
+import ErrorState from '@/components/error-state.vue'
 
 export default {
+  components: { LoadingSkeleton, ErrorState },
   data() {
     return {
       myClasses: [],
@@ -171,6 +178,9 @@ export default {
       salonNews: [],
       dynamics: [],
       recentCourses: [],
+      homeLoading: false,
+      homePending: 0,
+      homeError: false,
       aiTips: [
         { icon: '💡', text: '提示词三要素:角色 + 任务 + 要求,描述越具体,AI 越懂你。' },
         { icon: '🤖', text: '把 AI 当成一起上课的学伴,先问「怎么做」,再问「为什么」。' },
@@ -279,11 +289,18 @@ export default {
     loadInfo() {
       if (!this.isLoggedIn) return
       var self = this
+      this.homeLoading = true
+      this.homeError = false
+      this.homePending = 2
       this.loadClasses()
       this.loadGrowth()
       this.loadCourses()
       this.loadSalons()
     },
+    homeTick() {
+      this.homePending = this.homePending - 1
+      if (this.homePending <= 0) this.homeLoading = false
+    },
     loadClasses() {
       var self = this
       getMyEnrollments().then(function(resp) {
@@ -329,14 +346,22 @@ export default {
         })
         self.recentCourses = sorted.slice(0, 3)
         self.buildDynamics()
-      }).catch(function() {})
+      }).catch(function() {
+        self.homeError = true
+      }).finally(function() {
+        self.homeTick()
+      })
     },
     loadSalons() {
       var self = this
       getSalonList().then(function(resp) {
         self.salonNews = resp.data || []
         self.buildDynamics()
-      }).catch(function() {})
+      }).catch(function() {
+        self.homeError = true
+      }).finally(function() {
+        self.homeTick()
+      })
     },
     buildDynamics() {
       // 平台动态 = 进行中/未开始课程(最多 3 条);沙龙已独立成区块,避免重复

+ 22 - 5
train-frontend/pages/mine/index.vue

@@ -25,7 +25,8 @@
 
     <view class="section-card">
       <text class="section-title">🎓 完课证书</text>
-      <view v-if="certLoading" class="empty-text">加载中...</view>
+      <LoadingSkeleton v-if="certLoading" :rows="2" />
+      <ErrorState v-else-if="certError" message="证书信息加载失败" @retry="loadCert" />
        <view v-else-if="cert.eligible && cert.certNo" class="cert-ok">
          <text class="cert-no">{{ cert.certNo }}</text>
          <text class="cert-tip">恭喜完成离场验收全部 6 项!</text>
@@ -63,8 +64,10 @@
     <view class="section-card">
       <text class="section-title">🎟️ 卡券核销</text>
 
-      <view v-if="coupons.length === 0" class="empty-text">暂无卡券</view>
-      <view class="coupon-list">
+      <LoadingSkeleton v-if="couponLoading" :rows="2" />
+      <ErrorState v-else-if="couponError" message="卡券加载失败" @retry="loadCoupons" />
+      <EmptyState v-else-if="coupons.length === 0" icon="🎫" title="暂无卡券" desc="获取到的卡券会展示在这里" />
+      <view v-else class="coupon-list">
         <view class="coupon-item" v-for="(c, idx) in coupons" :key="idx">
           <view class="coupon-info">
             <text class="coupon-code">{{ c.code }}</text>
@@ -126,14 +129,20 @@
 import { getMyCert, getMyCoupons, redeemCoupon, verifyCert, getMyBadges } from '@/utils/api.js'
 import { jumpToCfc } from '@/utils/sso.js'
 import IdentityGateCard from '@/components/IdentityGateCard.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: { IdentityGateCard },
+  components: { IdentityGateCard, LoadingSkeleton, ErrorState, EmptyState },
   data() {
     return {
       certLoading: true,
+      certError: false,
       cert: {},
       coupons: [],
+      couponLoading: false,
+      couponError: false,
       redeemingId: 0,
       verifyInput: '',
       verifyResult: null,
@@ -225,19 +234,27 @@ export default {
     loadCert() {
       var self = this
       self.certLoading = true
+      self.certError = false
       getMyCert().then(function(resp) {
         self.cert = resp.data || {}
       }).catch(function() {
         self.cert = {}
+        self.certError = true
       }).finally(function() {
         self.certLoading = false
       })
     },
     loadCoupons() {
       var self = this
+      self.couponLoading = true
+      self.couponError = false
       getMyCoupons().then(function(resp) {
         self.coupons = resp.data || []
-      }).catch(function() {})
+      }).catch(function() {
+        self.couponError = true
+      }).finally(function() {
+        self.couponLoading = false
+      })
     },
     copyCertNo() {
       var certNo = this.cert.certNo || ''

+ 24 - 8
train-frontend/pages/upload/index.vue

@@ -28,13 +28,17 @@
 
     <view class="section-card">
       <text class="section-title">我的上传记录</text>
-      <view v-if="submissions.length === 0" class="empty-text">暂无记录</view>
-      <view class="sub-item" v-for="(s, idx) in submissions" :key="idx">
-        <view class="sub-header">
-          <text class="sub-type">{{ bookLabel(s.bookType) }} · {{ s.type === 'deep' ? '深度分析' : '教学成果' }}</text>
-          <text class="sub-status">{{ s.status }}</text>
+      <LoadingSkeleton v-if="listLoading" :rows="2" />
+      <ErrorState v-else-if="listError" message="上传记录加载失败" @retry="loadSubmissions" />
+      <EmptyState v-else-if="submissions.length === 0" icon="📭" title="暂无上传记录" desc="上传的成果会展示在这里" />
+      <view v-else>
+        <view class="sub-item" v-for="(s, idx) in submissions" :key="idx">
+          <view class="sub-header">
+            <text class="sub-type">{{ bookLabel(s.bookType) }} · {{ s.type === 'deep' ? '深度分析' : '教学成果' }}</text>
+            <text class="sub-status">{{ s.status }}</text>
+          </view>
+          <image v-if="s.image" :src="s.image" class="sub-thumb" mode="aspectFill" />
         </view>
-        <image v-if="s.image" :src="s.image" class="sub-thumb" mode="aspectFill" />
       </view>
     </view>
   </view>
@@ -43,8 +47,12 @@
 <script>
 import { uploadSubmission, getMySubmissions, uploadFile } 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 {
       bookTypes: [
@@ -60,7 +68,9 @@ export default {
       },
       uploadImage: '',
       loading: false,
-      submissions: []
+      submissions: [],
+      listLoading: false,
+      listError: false
     }
   },
   computed: {
@@ -75,9 +85,15 @@ onShow() {
   methods: {
     loadSubmissions() {
       var self = this
+      self.listLoading = true
+      self.listError = false
       getMySubmissions().then(function(resp) {
         self.submissions = resp.data || []
-      }).catch(function() {})
+      }).catch(function() {
+        self.listError = true
+      }).finally(function() {
+        self.listLoading = false
+      })
     },
     onBookTypeChange(e) {
       this.uploadForm.bookType = this.bookTypes[e.detail.value].value

+ 22 - 2
train-frontend/pages/work/index.vue

@@ -13,6 +13,10 @@
       </view>
     </view>
 
+    <!-- 加载骨架 / 错误态 -->
+    <LoadingSkeleton v-if="loading" :rows="4" />
+    <ErrorState v-else-if="error" message="工单数据加载失败" @retry="reload" />
+    <template v-else>
     <!-- 今日上门 -->
     <view class="group">
       <view class="group-head">
@@ -120,13 +124,17 @@
     <view class="footer-tip">
       <text class="footer-text">有疑问请联系机构对接人</text>
     </view>
+    </template>
   </view>
 </template>
 
 <script>
 import { getMyServiceOrders, getServiceEarnings, acceptServiceOrder } from '@/utils/api.js'
+import LoadingSkeleton from '@/components/loading-skeleton.vue'
+import ErrorState from '@/components/error-state.vue'
 
 export default {
+  components: { LoadingSkeleton, ErrorState },
   data() {
     return {
       todayList: [],
@@ -135,7 +143,9 @@ export default {
       doneList: [],
       totalIncome: 0,
       monthIncome: 0,
-      pendingIncome: 0
+      pendingIncome: 0,
+      loading: true,
+      error: false
     }
   },
   computed: {
@@ -153,8 +163,14 @@ export default {
     this.loadOrders()
     this.loadEarnings()
   },
+  reload() {
+    this.loadOrders()
+    this.loadEarnings()
+  },
   methods: {
     loadOrders() {
+      this.loading = true
+      this.error = false
       getMyServiceOrders().then(res => {
         if (!res || !res.data) return
         const groups = res.data
@@ -162,7 +178,11 @@ export default {
         this.pendingList = this.pickGroup(groups, 'pending')
         this.doingList = this.pickGroup(groups, 'doing')
         this.doneList = this.pickGroup(groups, 'done')
-      }).catch(() => {})
+      }).catch(() => {
+        this.error = true
+      }).finally(() => {
+        this.loading = false
+      })
     },
     loadEarnings() {
       getServiceEarnings().then(res => {