plan-list.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <text class="title">我的方案</text>
  5. <text class="subtitle">查看和管理已制定的训练方案</text>
  6. </view>
  7. <view class="action-bar">
  8. <button class="btn-primary" @click="goCreatePlan">+ 新建方案</button>
  9. </view>
  10. <!-- 加载状态 -->
  11. <view class="loading" v-if="loading">
  12. <text class="loading-text">加载中...</text>
  13. </view>
  14. <!-- 空状态 -->
  15. <view class="empty" v-else-if="plans.length === 0">
  16. <text class="empty-icon">📋</text>
  17. <text class="empty-title">暂无方案</text>
  18. <text class="empty-desc">点击上方按钮创建第一个训练方案</text>
  19. </view>
  20. <!-- 方案列表 -->
  21. <view class="plan-list" v-else>
  22. <view
  23. class="plan-card"
  24. v-for="plan in plans"
  25. :key="plan.id"
  26. @click="goDetail(plan.id)"
  27. >
  28. <view class="card-top">
  29. <text class="plan-title">{{ plan.title || '未命名方案' }}</text>
  30. <view class="plan-status" :class="'status-' + (plan.status || 0)">
  31. <text>{{ statusText(plan.status) }}</text>
  32. </view>
  33. </view>
  34. <text class="plan-desc" v-if="plan.description">{{ plan.description }}</text>
  35. <view class="card-meta">
  36. <text class="meta-item">成员:{{ plan.memberName || '--' }}</text>
  37. <text class="meta-item">创建时间:{{ formatTime(plan.createdAt) }}</text>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { getTrainingPlanList } from '@/utils/api.js'
  45. export default {
  46. data() {
  47. return {
  48. loading: false,
  49. plans: []
  50. }
  51. },
  52. onLoad() {
  53. this.loadPlans()
  54. this._onLoadFired = true
  55. },
  56. onShow() {
  57. if (this._onLoadFired) {
  58. this._onLoadFired = false
  59. } else {
  60. this.loadPlans()
  61. }
  62. },
  63. methods: {
  64. loadPlans() {
  65. this.loading = true
  66. var self = this
  67. getTrainingPlanList().then(function(res) {
  68. self.loading = false
  69. if (res && res.code === 200) {
  70. self.plans = res.data || []
  71. } else {
  72. uni.showToast({ title: (res && res.message) || '加载失败', icon: 'none' })
  73. self.plans = []
  74. }
  75. }).catch(function(err) {
  76. self.loading = false
  77. console.error('加载方案列表失败', err)
  78. uni.showToast({ title: '加载失败', icon: 'none' })
  79. self.plans = []
  80. })
  81. },
  82. goDetail(planId) {
  83. uni.navigateTo({ url: '/pages/teacher/plan-detail?planId=' + planId })
  84. },
  85. goCreatePlan() {
  86. uni.navigateTo({ url: '/pages/teacher/plan-create' })
  87. },
  88. statusText(status) {
  89. var map = { 0: '草稿', 1: '进行中', 2: '已完成', 3: '已取消' }
  90. return map[status] || '未知'
  91. },
  92. formatTime(t) {
  93. if (!t) return '-'
  94. // 项目统一时间格式:取前19位并把 ISO 的 T 换成空格,避免 toLocaleString 的浏览器差异
  95. return String(t).substring(0, 19).replace('T', ' ')
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped>
  101. .page {
  102. min-height: 100vh;
  103. background: #F5FAFE;
  104. padding-bottom: 30rpx;
  105. }
  106. .header {
  107. padding: 40rpx 30rpx 20rpx;
  108. }
  109. .title {
  110. font-size: 36rpx;
  111. font-weight: bold;
  112. color: #1F2D3D;
  113. display: block;
  114. }
  115. .subtitle {
  116. font-size: 26rpx;
  117. color: #8A94A6;
  118. margin-top: 8rpx;
  119. display: block;
  120. }
  121. .action-bar {
  122. padding: 0 30rpx 20rpx;
  123. }
  124. .btn-primary {
  125. width: 100%;
  126. background: #4A9BD7;
  127. color: #fff;
  128. font-size: 30rpx;
  129. font-weight: 600;
  130. padding: 24rpx 0;
  131. border-radius: 12rpx;
  132. border: none;
  133. }
  134. .loading, .empty {
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. padding: 100rpx 0;
  139. }
  140. .loading-text {
  141. font-size: 28rpx;
  142. color: #8A94A6;
  143. }
  144. .empty-icon {
  145. font-size: 80rpx;
  146. }
  147. .empty-title {
  148. font-size: 32rpx;
  149. font-weight: bold;
  150. color: #333;
  151. margin-top: 20rpx;
  152. }
  153. .empty-desc {
  154. font-size: 26rpx;
  155. color: #999;
  156. margin-top: 10rpx;
  157. text-align: center;
  158. }
  159. .plan-list {
  160. padding: 0 30rpx;
  161. }
  162. .plan-card {
  163. background: #fff;
  164. border-radius: 16rpx;
  165. padding: 30rpx;
  166. margin-bottom: 20rpx;
  167. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  168. }
  169. .plan-card:active {
  170. opacity: 0.8;
  171. }
  172. .card-top {
  173. display: flex;
  174. justify-content: space-between;
  175. align-items: center;
  176. }
  177. .plan-title {
  178. font-size: 30rpx;
  179. font-weight: bold;
  180. color: #333;
  181. flex: 1;
  182. }
  183. .plan-status {
  184. font-size: 22rpx;
  185. padding: 4rpx 16rpx;
  186. border-radius: 20rpx;
  187. }
  188. .status-0 { background: #FFF3E0; color: #F97316; }
  189. .status-1 { background: #E8F5E9; color: #4CAF50; }
  190. .status-2 { background: #E3F2FD; color: #2196F3; }
  191. .status-3 { background: #F5F5F5; color: #999; }
  192. .plan-desc {
  193. font-size: 26rpx;
  194. color: #666;
  195. margin-top: 12rpx;
  196. display: block;
  197. line-height: 1.5;
  198. }
  199. .card-meta {
  200. display: flex;
  201. flex-direction: column;
  202. margin-top: 16rpx;
  203. gap: 6rpx;
  204. }
  205. .meta-item {
  206. font-size: 24rpx;
  207. color: #bbb;
  208. }
  209. </style>