index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="roadmap-page">
  3. <view class="section-card">
  4. <text class="section-title">路演材料上传</text>
  5. <text class="card-desc">上传您小组的路演陈述材料</text>
  6. <view class="form-item">
  7. <text class="form-label">路演主题陈述</text>
  8. <textarea class="form-textarea" v-model="proposition" placeholder="请描述您小组的路演主题..." :maxlength="1000" />
  9. </view>
  10. <view class="form-item">
  11. <text class="form-label">附件材料</text>
  12. <button class="upload-btn" @click="chooseFile">选择文件/图片</button>
  13. <image v-if="fileUrl" :src="fileUrl" class="preview-img" mode="aspectFit" />
  14. <text v-if="fileName" class="file-name">{{ fileName }}</text>
  15. </view>
  16. <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading || !proposition">提交路演材料</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import { uploadRoadmap, uploadFile } from '@/utils/api.js'
  22. import { guardPage } from '@/utils/guard.js'
  23. export default {
  24. data() {
  25. return {
  26. proposition: '',
  27. fileUrl: '',
  28. fileName: '',
  29. filePath: '',
  30. loading: false
  31. }
  32. },
  33. onLoad() {
  34. if (!guardPage()) return
  35. },
  36. methods: {
  37. chooseFile() {
  38. var self = this
  39. uni.chooseImage({
  40. count: 1,
  41. sizeType: ['compressed'],
  42. sourceType: ['album', 'camera'],
  43. success: function(res) {
  44. self.filePath = res.tempFilePaths[0]
  45. self.fileName = res.tempFilePaths[0].split('/').pop()
  46. self.fileUrl = res.tempFilePaths[0]
  47. }
  48. })
  49. },
  50. handleSubmit() {
  51. if (!guardPage()) return
  52. if (!this.proposition.trim()) {
  53. uni.showToast({ title: '请输入路演主题', icon: 'none' })
  54. return
  55. }
  56. if (this.loading) return
  57. this.loading = true
  58. var self = this
  59. var doSubmit = function(files) {
  60. return uploadRoadmap({ proposition: self.proposition, files: files })
  61. }
  62. var p = this.filePath ? uploadFile(this.filePath).then(function(r) { return r.data.url }) : Promise.resolve(null)
  63. p.then(function(url) {
  64. return doSubmit(url)
  65. }).then(function() {
  66. uni.showToast({ title: '提交成功', icon: 'success' })
  67. setTimeout(function() { uni.navigateBack() }, 800)
  68. }).catch(function(err) {
  69. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  70. }).finally(function() {
  71. self.loading = false
  72. })
  73. }
  74. }
  75. }
  76. </script>
  77. <style scoped>
  78. .roadmap-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
  79. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  80. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 12rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  81. .card-desc { display: block; font-size: 26rpx; color: #3B5A78; margin-bottom: 32rpx; }
  82. .form-item { margin-bottom: 28rpx; }
  83. .form-label { display: block; font-size: 28rpx; color: #1E3A5F; font-weight: 500; margin-bottom: 12rpx; }
  84. .form-textarea { width: 100%; min-height: 240rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 20rpx; font-size: 28rpx; color: #1E3A5F; background: #F5FAFE; }
  85. .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; }
  86. .preview-img { width: 100%; height: 250rpx; border-radius: 8rpx; margin-bottom: 12rpx; }
  87. .file-name { font-size: 24rpx; color: #3B5A78; }
  88. .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: 16rpx; }
  89. .submit-btn:active { opacity: 0.85; }
  90. </style>