Browse Source

feat(ui-kit): 团报发起/行动计划/调研/沙龙表单反馈/分享资料与记录五态组件化

liaoxg 1 day ago
parent
commit
36c598d682

+ 31 - 3
train-frontend/pages/group-order/create.vue

@@ -1,6 +1,16 @@
 <template>
 <template>
   <view class="form-page">
   <view class="form-page">
-    <view class="section-card">
+    <LoadingSkeleton v-if="classLoading" :rows="4" />
+    <ErrorState v-else-if="classError" message="可报班次加载失败" @retry="loadClasses" />
+    <EmptyState
+      v-else-if="classes.length === 0"
+      icon="📭"
+      title="暂无可报班次"
+      desc="当前没有开放团体报名的班次,可联系机构确认"
+      action-text="返回"
+      @action="goBack"
+    />
+    <view v-else class="section-card">
       <text class="section-title">发起团报</text>
       <text class="section-title">发起团报</text>
       <text class="card-desc">选择班次并填写成员名单(含开票信息,可选)</text>
       <text class="card-desc">选择班次并填写成员名单(含开票信息,可选)</text>
 
 
@@ -65,8 +75,12 @@
 import { getEnrollClasses, createGroupOrder } from '@/utils/api.js'
 import { getEnrollClasses, createGroupOrder } from '@/utils/api.js'
 import { fenToYuan } from '@/utils/format.js'
 import { fenToYuan } from '@/utils/format.js'
 import { guardPage } from '@/utils/guard.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 {
 export default {
+  components: { LoadingSkeleton, ErrorState, EmptyState },
   data() {
   data() {
     return {
     return {
       classes: [],
       classes: [],
@@ -82,7 +96,9 @@ export default {
         invoicePhone: '',
         invoicePhone: '',
         invoiceType: '普票'
         invoiceType: '普票'
       },
       },
-      loading: false
+      loading: false,
+      classLoading: false,
+      classError: false
     }
     }
   },
   },
   onLoad() {
   onLoad() {
@@ -90,9 +106,19 @@ export default {
     this.loadClasses()
     this.loadClasses()
   },
   },
   methods: {
   methods: {
+    goBack() {
+      var pages = getCurrentPages()
+      if (pages.length > 1) {
+        uni.navigateBack()
+      } else {
+        uni.redirectTo({ url: '/pages/group-order/index' })
+      }
+    },
     fenToYuan: fenToYuan,
     fenToYuan: fenToYuan,
     loadClasses() {
     loadClasses() {
       var self = this
       var self = this
+      self.classLoading = true
+      self.classError = false
       getEnrollClasses().then(function(resp) {
       getEnrollClasses().then(function(resp) {
         self.classes = resp.data || []
         self.classes = resp.data || []
         var names = []
         var names = []
@@ -101,7 +127,9 @@ export default {
         }
         }
         self.classNames = names
         self.classNames = names
       }).catch(function() {
       }).catch(function() {
-        uni.showToast({ title: '加载班次失败', icon: 'none' })
+        self.classError = true
+      }).finally(function() {
+        self.classLoading = false
       })
       })
     },
     },
     onClassChange(e) {
     onClassChange(e) {

+ 16 - 3
train-frontend/pages/plan/index.vue

@@ -1,6 +1,8 @@
 <template>
 <template>
   <view class="plan-page">
   <view class="plan-page">
-    <view class="section-card">
+    <LoadingSkeleton v-if="planLoading" :rows="3" />
+    <ErrorState v-else-if="planError" message="行动计划加载失败" @retry="loadPlan" />
+    <view v-else class="section-card">
       <text class="section-title">7天行动计划</text>
       <text class="section-title">7天行动计划</text>
       <text class="card-desc">规划您未来7天的学习与实践目标</text>
       <text class="card-desc">规划您未来7天的学习与实践目标</text>
       <view v-if="existingPlan" class="existing-plan">
       <view v-if="existingPlan" class="existing-plan">
@@ -27,13 +29,18 @@
 <script>
 <script>
 import { submitPlan, getMyPlan } from '@/utils/api.js'
 import { submitPlan, getMyPlan } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.js'
 import { guardPage } from '@/utils/guard.js'
+import LoadingSkeleton from '@/components/loading-skeleton.vue'
+import ErrorState from '@/components/error-state.vue'
 
 
 export default {
 export default {
+  components: { LoadingSkeleton, ErrorState },
   data() {
   data() {
     return {
     return {
       items: ['', '', '', '', '', '', ''],
       items: ['', '', '', '', '', '', ''],
       existingPlan: null,
       existingPlan: null,
-      loading: false
+      loading: false,
+      planLoading: false,
+      planError: false
     }
     }
   },
   },
   computed: {
   computed: {
@@ -53,11 +60,17 @@ export default {
   methods: {
   methods: {
     loadPlan() {
     loadPlan() {
       var self = this
       var self = this
+      self.planLoading = true
+      self.planError = false
       getMyPlan().then(function(resp) {
       getMyPlan().then(function(resp) {
         if (resp.data) {
         if (resp.data) {
           self.existingPlan = resp.data
           self.existingPlan = resp.data
         }
         }
-      }).catch(function() {})
+      }).catch(function() {
+        self.planError = true
+      }).finally(function() {
+        self.planLoading = false
+      })
     },
     },
     handleSubmit() {
     handleSubmit() {
       var filled = this.items.filter(function(i) { return i.trim() })
       var filled = this.items.filter(function(i) { return i.trim() })

+ 22 - 6
train-frontend/pages/salon/feedback.vue

@@ -1,6 +1,14 @@
 <template>
 <template>
   <view class="feedback-page">
   <view class="feedback-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="section-title">沙龙反馈</text>
       <text class="card-desc">分享你对本次沙龙的感受与建议</text>
       <text class="card-desc">分享你对本次沙龙的感受与建议</text>
 
 
@@ -40,15 +48,18 @@
 <script>
 <script>
 import { salonFeedback } from '@/utils/api.js'
 import { salonFeedback } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.js'
 import { guardPage } from '@/utils/guard.js'
+import EmptyState from '@/components/empty-state.vue'
 
 
 export default {
 export default {
+  components: { EmptyState },
   data() {
   data() {
     return {
     return {
       salonId: '',
       salonId: '',
       salonTitle: '',
       salonTitle: '',
       rating: 5,
       rating: 5,
       comment: '',
       comment: '',
-      loading: false
+      loading: false,
+      invalid: false
     }
     }
   },
   },
   onLoad(options) {
   onLoad(options) {
@@ -56,10 +67,7 @@ export default {
     this.salonId = options && options.salonId ? options.salonId : ''
     this.salonId = options && options.salonId ? options.salonId : ''
     this.salonTitle = options && options.title ? decodeURIComponent(options.title) : ''
     this.salonTitle = options && options.title ? decodeURIComponent(options.title) : ''
     if (!this.salonId) {
     if (!this.salonId) {
-      uni.showToast({ title: '参数错误', icon: 'none' })
-      setTimeout(function() {
-        uni.navigateBack({ delta: 1 })
-      }, 1500)
+      this.invalid = true
     }
     }
   },
   },
   computed: {
   computed: {
@@ -69,6 +77,14 @@ export default {
     }
     }
   },
   },
   methods: {
   methods: {
+    goBackList() {
+      var pages = getCurrentPages()
+      if (pages.length > 1) {
+        uni.navigateBack()
+      } else {
+        uni.redirectTo({ url: '/pages/salon/list' })
+      }
+    },
     setRating: function(star) {
     setRating: function(star) {
       this.rating = star
       this.rating = star
     },
     },

+ 23 - 7
train-frontend/pages/salon/form.vue

@@ -1,6 +1,14 @@
 <template>
 <template>
   <view class="form-page">
   <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">{{ memberMode ? '会员免费报名' : '沙龙报名' }}</text>
       <text class="section-title">{{ memberMode ? '会员免费报名' : '沙龙报名' }}</text>
       <text class="card-desc">{{ memberMode ? '使用会员免费沙龙次数,报名成功即锁定名额' : '填写联系方式,完成支付后即可锁定名额' }}</text>
       <text class="card-desc">{{ memberMode ? '使用会员免费沙龙次数,报名成功即锁定名额' : '填写联系方式,完成支付后即可锁定名额' }}</text>
 
 
@@ -33,8 +41,10 @@
 import { createSalonEnroll, memberSalonRegister } from '@/utils/api.js'
 import { createSalonEnroll, memberSalonRegister } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.js'
 import { guardPage } from '@/utils/guard.js'
 import { captureInviteCode, getPendingInviteCode, consumeInviteCode } from '@/utils/invite.js'
 import { captureInviteCode, getPendingInviteCode, consumeInviteCode } from '@/utils/invite.js'
+import EmptyState from '@/components/empty-state.vue'
 
 
 export default {
 export default {
+  components: { EmptyState },
   data() {
   data() {
     return {
     return {
       form: {
       form: {
@@ -46,7 +56,8 @@ export default {
       salonTheme: '',
       salonTheme: '',
       salonTitle: '',
       salonTitle: '',
       memberMode: false,
       memberMode: false,
-      loading: false
+      loading: false,
+      invalid: false
     }
     }
   },
   },
   onLoad(options) {
   onLoad(options) {
@@ -60,15 +71,20 @@ export default {
     this.form.name = options && options.name ? decodeURIComponent(options.name) : ''
     this.form.name = options && options.name ? decodeURIComponent(options.name) : ''
     this.form.phone = options && options.phone ? decodeURIComponent(options.phone) : ''
     this.form.phone = options && options.phone ? decodeURIComponent(options.phone) : ''
     this.memberMode = options && options.member === '1'
     this.memberMode = options && options.member === '1'
-    
+
     if (!this.form.salonId) {
     if (!this.form.salonId) {
-      uni.showToast({ title: '参数错误', icon: 'none' })
-      setTimeout(function() {
-        uni.navigateBack({ delta: 1 })
-      }, 1500)
+      this.invalid = true
     }
     }
   },
   },
   methods: {
   methods: {
+    goBackList() {
+      var pages = getCurrentPages()
+      if (pages.length > 1) {
+        uni.navigateBack()
+      } else {
+        uni.redirectTo({ url: '/pages/salon/list' })
+      }
+    },
     handleSubmit() {
     handleSubmit() {
       var name = (this.form.name || '').trim()
       var name = (this.form.name || '').trim()
       var phone = (this.form.phone || '').trim()
       var phone = (this.form.phone || '').trim()

+ 53 - 19
train-frontend/pages/share/index.vue

@@ -1,22 +1,34 @@
 <template>
 <template>
   <view class="share-page">
   <view class="share-page">
-    <!-- 统一用 canvas 合成海报:品牌 + 资料编码 + 小程序码(生产由后端生成,test-mode 为占位框) -->
-    <view class="poster-card">
-      <canvas canvas-id="posterCanvas" id="posterCanvas" class="poster-canvas"></canvas>
-    </view>
+    <LoadingSkeleton v-if="loading" :rows="2" />
+    <ErrorState v-else-if="error" message="资料加载失败" @retry="loadPoster" />
+    <EmptyState
+      v-else-if="!inviteCode"
+      icon="📄"
+      title="暂无资料编码"
+      desc="分享资料生成后会在此展示"
+      action-text="返回"
+      @action="goBack"
+    />
+    <template v-else>
+      <!-- 统一用 canvas 合成海报:品牌 + 资料编码 + 小程序码(生产由后端生成,test-mode 为占位框) -->
+      <view class="poster-card">
+        <canvas canvas-id="posterCanvas" id="posterCanvas" class="poster-canvas"></canvas>
+      </view>
 
 
-    <view class="invite-row">
-      <text class="invite-label">资料编码</text>
-      <text class="invite-code">{{ inviteCode || '加载中…' }}</text>
-      <button class="copy-btn" @click="copyCode" :disabled="!inviteCode">复制</button>
-    </view>
+      <view class="invite-row">
+        <text class="invite-label">资料编码</text>
+        <text class="invite-code">{{ inviteCode }}</text>
+        <button class="copy-btn" @click="copyCode" :disabled="!inviteCode">复制</button>
+      </view>
 
 
-    <view class="invite-row share-text-row" v-if="shareText">
-      <text class="invite-label">分享文案</text>
-      <text class="share-text-preview" @click="copyShareText">点击复制分享文案 ›</text>
-    </view>
+      <view class="invite-row share-text-row" v-if="shareText">
+        <text class="invite-label">分享文案</text>
+        <text class="share-text-preview" @click="copyShareText">点击复制分享文案 ›</text>
+      </view>
 
 
-    <button class="save-btn" @click="savePoster" :loading="saving" :disabled="saving || !inviteCode">保存海报图片</button>
+      <button class="save-btn" @click="savePoster" :loading="saving" :disabled="saving || !inviteCode">保存海报图片</button>
+    </template>
   </view>
   </view>
 </template>
 </template>
 
 
@@ -24,6 +36,9 @@
 import { getMyPoster } from '@/utils/api.js'
 import { getMyPoster } from '@/utils/api.js'
 import { resolveAssetUrl } from '@/utils/share.js'
 import { resolveAssetUrl } from '@/utils/share.js'
 import { guardPage } from '@/utils/guard.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'
 
 
 var CANVAS_W = 300
 var CANVAS_W = 300
 var CANVAS_H = 450
 var CANVAS_H = 450
@@ -32,12 +47,15 @@ var QR_Y = 228
 var QR_SIZE = 130
 var QR_SIZE = 130
 
 
 export default {
 export default {
+  components: { LoadingSkeleton, ErrorState, EmptyState },
   data() {
   data() {
     return {
     return {
       inviteCode: '',
       inviteCode: '',
       posterUrl: '',
       posterUrl: '',
       shareText: '',
       shareText: '',
-      saving: false
+      saving: false,
+      loading: false,
+      error: false
     }
     }
   },
   },
   onLoad() {
   onLoad() {
@@ -45,24 +63,40 @@ export default {
     this.loadPoster()
     this.loadPoster()
   },
   },
   onReady() {
   onReady() {
-    // canvas 就绪后先绘制占位海报,邀请码/小程序码返回后再重绘
-    this.drawPoster()
+    // canvas 就绪后先绘制占位海报,邀请码/小程序码返回后再重绘(仅正常态可见时绘制)
+    if (!this.loading && this.inviteCode) {
+      this.drawPoster()
+    }
   },
   },
   methods: {
   methods: {
+    goBack() {
+      var pages = getCurrentPages()
+      if (pages.length > 1) {
+        uni.navigateBack()
+      } else {
+        uni.redirectTo({ url: '/pages/index/index' })
+      }
+    },
     loadPoster() {
     loadPoster() {
       var self = this
       var self = this
+      self.loading = true
+      self.error = false
       getMyPoster().then(function(resp) {
       getMyPoster().then(function(resp) {
         var data = resp.data || {}
         var data = resp.data || {}
         self.inviteCode = data.inviteCode || ''
         self.inviteCode = data.inviteCode || ''
         self.posterUrl = resolveAssetUrl(data.posterUrl || '')
         self.posterUrl = resolveAssetUrl(data.posterUrl || '')
         self.shareText = data.shareText || ''
         self.shareText = data.shareText || ''
+        self.loading = false
         if (self.inviteCode) {
         if (self.inviteCode) {
-          // 重新绘制带资料编码/小程序码的海报
+          // 重新绘制带资料编码/小程序码的海报(canvas 此时已渲染)
           setTimeout(function() {
           setTimeout(function() {
             self.drawPoster()
             self.drawPoster()
           }, 300)
           }, 300)
         }
         }
-      }).catch(function() {})
+      }).catch(function() {
+        self.loading = false
+        self.error = true
+      })
     },
     },
     drawPoster() {
     drawPoster() {
       var self = this
       var self = this

+ 45 - 24
train-frontend/pages/share/stats.vue

@@ -1,40 +1,56 @@
 <template>
 <template>
   <view class="stats-page">
   <view class="stats-page">
-    <view class="stat-card">
-      <view class="stat-row">
-        <view class="stat-item">
-          <text class="stat-num">{{ stats.invited }}</text>
-          <text class="stat-label">来源记录</text>
-        </view>
-        <view class="stat-item">
-          <text class="stat-num">{{ stats.paid }}</text>
-          <text class="stat-label">报名记录</text>
+    <LoadingSkeleton v-if="loading" :rows="2" />
+    <ErrorState v-else-if="error" message="记录加载失败" @retry="loadStats" />
+    <EmptyState
+      v-else-if="!stats.invited && !stats.paid"
+      icon="📄"
+      title="暂无来源记录"
+      desc="有分享来源记录后会在此展示"
+    />
+    <template v-else>
+      <view class="stat-card">
+        <view class="stat-row">
+          <view class="stat-item">
+            <text class="stat-num">{{ stats.invited }}</text>
+            <text class="stat-label">来源记录</text>
+          </view>
+          <view class="stat-item">
+            <text class="stat-num">{{ stats.paid }}</text>
+            <text class="stat-label">报名记录</text>
+          </view>
         </view>
         </view>
       </view>
       </view>
-    </view>
 
 
-    <view class="tip-card">
-      <text class="tip-title">记录说明</text>
-      <text class="tip-desc">1. 本页仅展示您的来源与报名记录</text>
-      <text class="tip-desc">2. 记录仅供本人查看</text>
-      <text class="tip-desc">3. 如对记录有疑问,请联系机构</text>
-    </view>
+      <view class="tip-card">
+        <text class="tip-title">记录说明</text>
+        <text class="tip-desc">1. 本页仅展示您的来源与报名记录</text>
+        <text class="tip-desc">2. 记录仅供本人查看</text>
+        <text class="tip-desc">3. 如对记录有疑问,请联系机构</text>
+      </view>
 
 
-    <view class="poster-link" @click="goPoster">
-      <text>查看分享资料</text>
-      <text class="arrow">›</text>
-    </view>
+      <view class="poster-link" @click="goPoster">
+        <text>查看分享资料</text>
+        <text class="arrow">›</text>
+      </view>
+    </template>
   </view>
   </view>
 </template>
 </template>
 
 
 <script>
 <script>
 import { getInviteStats } from '@/utils/api.js'
 import { getInviteStats } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.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 {
 export default {
+  components: { LoadingSkeleton, ErrorState, EmptyState },
   data() {
   data() {
     return {
     return {
-      stats: { invited: 0, paid: 0, rewards: 0 }
+      stats: { invited: 0, paid: 0 },
+      loading: false,
+      error: false
     }
     }
   },
   },
   onShow() {
   onShow() {
@@ -44,14 +60,19 @@ export default {
   methods: {
   methods: {
     loadStats() {
     loadStats() {
       var self = this
       var self = this
+      self.loading = true
+      self.error = false
       getInviteStats().then(function(resp) {
       getInviteStats().then(function(resp) {
         var data = resp.data || {}
         var data = resp.data || {}
         self.stats = {
         self.stats = {
           invited: data.invited || 0,
           invited: data.invited || 0,
-          paid: data.paid || 0,
-          rewards: data.rewards || 0
+          paid: data.paid || 0
         }
         }
-      }).catch(function() {})
+      }).catch(function() {
+        self.error = true
+      }).finally(function() {
+        self.loading = false
+      })
     },
     },
     goPoster() {
     goPoster() {
       uni.navigateBack({})
       uni.navigateBack({})

+ 17 - 3
train-frontend/pages/survey/index.vue

@@ -18,8 +18,10 @@
 
 
     <view class="section-card">
     <view class="section-card">
       <text class="section-title">我的卡券</text>
       <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-item" v-for="(c, idx) in coupons" :key="idx">
           <view class="coupon-type">{{ couponTypeLabel(c.type) }}</view>
           <view class="coupon-type">{{ couponTypeLabel(c.type) }}</view>
           <view class="coupon-info">
           <view class="coupon-info">
@@ -35,8 +37,12 @@
 <script>
 <script>
 import { submitSurvey, getMyCoupons } from '@/utils/api.js'
 import { submitSurvey, getMyCoupons } from '@/utils/api.js'
 import { guardPage } from '@/utils/guard.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 {
 export default {
+  components: { LoadingSkeleton, ErrorState, EmptyState },
   data() {
   data() {
     return {
     return {
       interests: [
       interests: [
@@ -47,6 +53,8 @@ export default {
       selected: '',
       selected: '',
       loading: false,
       loading: false,
       coupons: [],
       coupons: [],
+      couponLoading: false,
+      couponError: false,
       courseId: '',
       courseId: '',
       pageTitle: '测评兴趣调研',
       pageTitle: '测评兴趣调研',
       pageDesc: '选择您最感兴趣的领域,提交后有机会获得测评兑换卡'
       pageDesc: '选择您最感兴趣的领域,提交后有机会获得测评兑换卡'
@@ -66,9 +74,15 @@ export default {
   methods: {
   methods: {
     loadCoupons() {
     loadCoupons() {
       var self = this
       var self = this
+      self.couponLoading = true
+      self.couponError = false
       getMyCoupons().then(function(resp) {
       getMyCoupons().then(function(resp) {
         self.coupons = resp.data || []
         self.coupons = resp.data || []
-      }).catch(function() {})
+      }).catch(function() {
+        self.couponError = true
+      }).finally(function() {
+        self.couponLoading = false
+      })
     },
     },
     handleSubmit() {
     handleSubmit() {
       if (!this.selected || this.loading) return
       if (!this.selected || this.loading) return