index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="plan-page">
  3. <LoadingSkeleton v-if="planLoading" :rows="3" />
  4. <ErrorState v-else-if="planError" message="行动计划加载失败" @retry="loadPlan" />
  5. <view v-else class="section-card">
  6. <text class="section-title">7天行动计划</text>
  7. <text class="card-desc">规划您未来7天的学习与实践目标</text>
  8. <view v-if="existingPlan" class="existing-plan">
  9. <text class="plan-status">✅ 已提交</text>
  10. <view class="plan-items">
  11. <view class="plan-item" v-for="(item, idx) in parsedItems" :key="idx">
  12. <text class="day-label">Day {{ idx + 1 }}</text>
  13. <text class="day-content">{{ item }}</text>
  14. </view>
  15. </view>
  16. <text class="plan-time" v-if="existingPlan.submittedAt">提交时间:{{ existingPlan.submittedAt }}</text>
  17. </view>
  18. <view v-else class="plan-form">
  19. <view class="day-input" v-for="day in 7" :key="day">
  20. <text class="day-label">Day {{ day }}</text>
  21. <input class="form-input" v-model="items[day - 1]" :placeholder="'第' + day + '天计划'" />
  22. </view>
  23. <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading">提交计划</button>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { submitPlan, getMyPlan } from '@/utils/api.js'
  30. import { guardPage } from '@/utils/guard.js'
  31. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  32. import ErrorState from '@/components/error-state.vue'
  33. export default {
  34. components: { LoadingSkeleton, ErrorState },
  35. data() {
  36. return {
  37. items: ['', '', '', '', '', '', ''],
  38. existingPlan: null,
  39. loading: false,
  40. planLoading: false,
  41. planError: false
  42. }
  43. },
  44. computed: {
  45. parsedItems() {
  46. if (!this.existingPlan || !this.existingPlan.items) return []
  47. try {
  48. return JSON.parse(this.existingPlan.items)
  49. } catch (e) {
  50. return [this.existingPlan.items]
  51. }
  52. }
  53. },
  54. onShow() {
  55. if (!guardPage()) return
  56. this.loadPlan()
  57. },
  58. methods: {
  59. loadPlan() {
  60. var self = this
  61. self.planLoading = true
  62. self.planError = false
  63. getMyPlan().then(function(resp) {
  64. if (resp.data) {
  65. self.existingPlan = resp.data
  66. }
  67. }).catch(function() {
  68. self.planError = true
  69. }).finally(function() {
  70. self.planLoading = false
  71. })
  72. },
  73. handleSubmit() {
  74. var filled = this.items.filter(function(i) { return i.trim() })
  75. if (filled.length === 0) {
  76. uni.showToast({ title: '请至少填写一天计划', icon: 'none' })
  77. return
  78. }
  79. if (this.loading) return
  80. this.loading = true
  81. var self = this
  82. submitPlan({ items: JSON.stringify(this.items) }).then(function() {
  83. uni.showToast({ title: '提交成功', icon: 'success' })
  84. self.loadPlan()
  85. }).catch(function(err) {
  86. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  87. }).finally(function() {
  88. self.loading = false
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style scoped>
  95. .plan-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
  96. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  97. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  98. .card-desc { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 32rpx; }
  99. .existing-plan { margin-top: 16rpx; }
  100. .plan-status { display: block; font-size: 28rpx; color: #0E8A4F; font-weight: 500; margin-bottom: 20rpx; }
  101. .plan-items { margin-bottom: 16rpx; }
  102. .plan-item { display: flex; padding: 16rpx 0; border-bottom: 1rpx solid #E3ECF4; }
  103. .day-label { width: 100rpx; font-size: 26rpx; color: #2E6FA8; font-weight: 600; flex-shrink: 0; }
  104. .day-content { flex: 1; font-size: 28rpx; color: #1E3A5F; }
  105. .plan-time { font-size: 24rpx; color: #6B7B8C; }
  106. .day-input { display: flex; align-items: center; margin-bottom: 20rpx; }
  107. .day-input .day-label { width: 100rpx; font-size: 26rpx; color: #2E6FA8; font-weight: 600; flex-shrink: 0; }
  108. .form-input { flex: 1; height: 72rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 16rpx; font-size: 28rpx; color: #1E3A5F; background: #F5FAFE; }
  109. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; margin-top: 24rpx; }
  110. .submit-btn:active { opacity: 0.85; }
  111. </style>