index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="upload-page">
  3. <view class="section-card">
  4. <text class="section-title">成果上传</text>
  5. <view class="form-item">
  6. <text class="form-label">账本类型</text>
  7. <picker :range="bookTypes" range-key="label" @change="onBookTypeChange">
  8. <view class="picker-display">{{ selectedBookType.label }} ▼</view>
  9. </picker>
  10. </view>
  11. <view class="form-item">
  12. <text class="form-label">上传类型</text>
  13. <radio-group @change="onTypeChange">
  14. <label class="radio-item"><radio value="deep" :checked="uploadForm.type === 'deep'" color="#2E6FA8" />深度分析</label>
  15. <label class="radio-item"><radio value="taught" :checked="uploadForm.type === 'taught'" color="#2E6FA8" />教学成果</label>
  16. </radio-group>
  17. </view>
  18. <view class="form-item">
  19. <label class="check-item">
  20. <checkbox :checked="uploadForm.desensitized" @tap="uploadForm.desensitized = !uploadForm.desensitized" color="#2E6FA8" />
  21. <text>我已确认数据已脱敏处理</text>
  22. </label>
  23. </view>
  24. <button class="upload-btn" @click="chooseImage">选择截图</button>
  25. <image v-if="uploadImage" :src="uploadImage" class="preview-img" mode="aspectFit" />
  26. <button class="submit-btn" @click="handleUpload" :loading="loading" :disabled="!uploadForm.desensitized || !uploadImage || loading">提交</button>
  27. </view>
  28. <view class="section-card">
  29. <text class="section-title">我的上传记录</text>
  30. <LoadingSkeleton v-if="listLoading" :rows="2" />
  31. <ErrorState v-else-if="listError" message="上传记录加载失败" @retry="loadSubmissions" />
  32. <EmptyState v-else-if="submissions.length === 0" icon="📭" title="暂无上传记录" desc="上传的成果会展示在这里" />
  33. <view v-else>
  34. <view class="sub-item" v-for="(s, idx) in submissions" :key="idx">
  35. <view class="sub-header">
  36. <text class="sub-type">{{ bookLabel(s.bookType) }} · {{ s.type === 'deep' ? '深度分析' : '教学成果' }}</text>
  37. <text class="sub-status">{{ s.status }}</text>
  38. </view>
  39. <image v-if="s.image" :src="s.image" class="sub-thumb" mode="aspectFill" />
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import { uploadSubmission, getMySubmissions, uploadFile } from '@/utils/api.js'
  47. import { guardPage } from '@/utils/guard.js'
  48. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  49. import ErrorState from '@/components/error-state.vue'
  50. import EmptyState from '@/components/empty-state.vue'
  51. export default {
  52. components: { LoadingSkeleton, ErrorState, EmptyState },
  53. data() {
  54. return {
  55. bookTypes: [
  56. { value: 'wealth', label: '财富账' },
  57. { value: 'health', label: '健康账' },
  58. { value: 'growth', label: '成长账' }
  59. ],
  60. uploadForm: {
  61. bookType: 'wealth',
  62. type: 'deep',
  63. desensitized: false,
  64. sampleFlag: 0
  65. },
  66. uploadImage: '',
  67. loading: false,
  68. submissions: [],
  69. listLoading: false,
  70. listError: false
  71. }
  72. },
  73. computed: {
  74. selectedBookType() {
  75. return this.bookTypes.find(b => b.value === this.uploadForm.bookType) || this.bookTypes[0]
  76. }
  77. },
  78. onShow() {
  79. if (!guardPage()) return
  80. this.loadSubmissions()
  81. },
  82. methods: {
  83. loadSubmissions() {
  84. var self = this
  85. self.listLoading = true
  86. self.listError = false
  87. getMySubmissions().then(function(resp) {
  88. self.submissions = resp.data || []
  89. }).catch(function() {
  90. self.listError = true
  91. }).finally(function() {
  92. self.listLoading = false
  93. })
  94. },
  95. onBookTypeChange(e) {
  96. this.uploadForm.bookType = this.bookTypes[e.detail.value].value
  97. },
  98. onTypeChange(e) {
  99. this.uploadForm.type = e.detail.value
  100. },
  101. chooseImage() {
  102. var self = this
  103. uni.chooseImage({
  104. count: 1,
  105. sizeType: ['compressed'],
  106. sourceType: ['album', 'camera'],
  107. success: function(res) {
  108. self.uploadImage = res.tempFilePaths[0]
  109. }
  110. })
  111. },
  112. handleUpload() {
  113. if (!this.uploadForm.desensitized) {
  114. uni.showToast({ title: '请先确认已脱敏', icon: 'none' })
  115. return
  116. }
  117. if (!this.uploadImage || this.loading) return
  118. this.loading = true
  119. var self = this
  120. uploadFile(this.uploadImage).then(function(resp) {
  121. var url = resp.data.url
  122. return uploadSubmission({
  123. bookType: self.uploadForm.bookType,
  124. type: self.uploadForm.type,
  125. image: url,
  126. files: null,
  127. sampleFlag: 0,
  128. desensitized: 1
  129. })
  130. }).then(function() {
  131. uni.showToast({ title: '上传成功', icon: 'success' })
  132. self.uploadImage = ''
  133. self.loadSubmissions()
  134. }).catch(function(err) {
  135. uni.showToast({ title: (err && err.message) || '上传失败', icon: 'none' })
  136. }).finally(function() {
  137. self.loading = false
  138. })
  139. },
  140. bookLabel(type) {
  141. var map = { wealth: '财富账', health: '健康账', growth: '成长账' }
  142. return map[type] || type
  143. }
  144. }
  145. }
  146. </script>
  147. <style scoped>
  148. .upload-page { min-height: 100vh; background: #F5FAFE; padding: 24rpx 32rpx; }
  149. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; }
  150. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 24rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  151. .form-item { margin-bottom: 24rpx; }
  152. .form-label { display: block; font-size: 28rpx; color: #1E3A5F; font-weight: 500; margin-bottom: 12rpx; }
  153. .picker-display { height: 72rpx; line-height: 72rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 20rpx; font-size: 28rpx; color: #1E3A5F; background: #F5FAFE; }
  154. .radio-item, .check-item { display: flex; align-items: center; font-size: 28rpx; color: #1E3A5F; margin-bottom: 12rpx; }
  155. .upload-btn { width: 100%; height: 72rpx; line-height: 72rpx; background: #E8F3FC; color: #2E6FA8; font-size: 28rpx; border: 2rpx dashed #2E6FA8; border-radius: 8rpx; margin-bottom: 16rpx; }
  156. .preview-img { width: 100%; height: 300rpx; border-radius: 8rpx; margin-bottom: 16rpx; }
  157. .submit-btn { width: 100%; height: 80rpx; line-height: 80rpx; background: #2E6FA8; color: #FFF; font-size: 28rpx; font-weight: 500; border-radius: 40rpx; border: none; }
  158. .submit-btn:active { opacity: 0.85; }
  159. .empty-text { font-size: 26rpx; color: #6B7B8C; text-align: center; padding: 24rpx 0; }
  160. .sub-item { border-bottom: 1rpx solid #E3ECF4; padding: 20rpx 0; }
  161. .sub-header { display: flex; justify-content: space-between; align-items: center; }
  162. .sub-type { font-size: 28rpx; color: #1E3A5F; font-weight: 500; }
  163. .sub-status { font-size: 24rpx; color: #2E6FA8; }
  164. .sub-thumb { width: 120rpx; height: 120rpx; border-radius: 8rpx; margin-top: 12rpx; }
  165. </style>