order-file-upload.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class="order-file-upload">
  3. <view class="upload-section">
  4. <view class="upload-title">
  5. <text class="title-text">{{title}}</text>
  6. <text class="upload-btn" @click="handleUpload">上传文件</text>
  7. </view>
  8. <view class="file-list" v-if="fileList.length > 0">
  9. <view class="file-item" v-for="(item, index) in fileList" :key="index">
  10. <view class="file-info">
  11. <text class="file-name">{{item.fileName}}</text>
  12. <text class="file-size">{{item.fileSize}}</text>
  13. </view>
  14. <view class="file-actions">
  15. <text class="delete-btn" @click="handleDelete(index)">删除</text>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="upload-tip" v-else>
  20. <text class="tip-text">{{tipText}}</text>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import upload from '../../mixins/upload';
  27. export default {
  28. name: 'OrderFileUpload',
  29. mixins : [upload],
  30. props: {
  31. title: {
  32. type: String,
  33. default: '文件上传'
  34. },
  35. orderFileType: {
  36. type: String,
  37. required: true
  38. },
  39. fileList: {
  40. type: Array,
  41. default: () => []
  42. },
  43. tipText: {
  44. type: String,
  45. default: '点击上传文件'
  46. },
  47. },
  48. data() {
  49. return {
  50. }
  51. },
  52. watch: {
  53. fileList: {
  54. handler(newVal) {
  55. this.uploadList = [...newVal];
  56. },
  57. immediate: true
  58. }
  59. },
  60. methods: {
  61. handleUploadSuccess(){
  62. uni.$u.toast("上传成功");
  63. },
  64. // 删除文件
  65. handleDelete(index) {
  66. uni.showModal({
  67. title: '提示',
  68. content: '确定要删除该文件吗?',
  69. success: (res) => {
  70. if (res.confirm) {
  71. this.uploadList.splice(index, 1);
  72. this.$emit('update:fileList', this.uploadList);
  73. this.$emit('change', {
  74. type: this.orderFileType,
  75. fileList: this.uploadList
  76. });
  77. }
  78. }
  79. });
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .order-file-upload {
  86. .upload-section {
  87. background: #fff;
  88. margin-bottom: 20rpx;
  89. border-radius: 16rpx;
  90. overflow: hidden;
  91. }
  92. .upload-title {
  93. display: flex;
  94. justify-content: space-between;
  95. align-items: center;
  96. padding: 30rpx 40rpx;
  97. border-bottom: 1rpx solid #f5f5f5;
  98. .title-text {
  99. font-size: 32rpx;
  100. font-weight: 500;
  101. color: #333;
  102. }
  103. .upload-btn {
  104. padding: 12rpx 24rpx;
  105. background: #007aff;
  106. color: #fff;
  107. border-radius: 8rpx;
  108. font-size: 28rpx;
  109. }
  110. }
  111. .file-list {
  112. padding: 20rpx 40rpx;
  113. }
  114. .file-item {
  115. display: flex;
  116. justify-content: space-between;
  117. align-items: center;
  118. padding: 20rpx 0;
  119. border-bottom: 1rpx solid #f5f5f5;
  120. &:last-child {
  121. border-bottom: none;
  122. }
  123. }
  124. .file-info {
  125. flex: 1;
  126. min-width: 0; // 防止flex子元素溢出
  127. .file-name {
  128. display: block;
  129. font-size: 30rpx;
  130. color: #333;
  131. margin-bottom: 8rpx;
  132. overflow: hidden;
  133. text-overflow: ellipsis;
  134. white-space: nowrap;
  135. max-width: 400rpx; // 设置最大宽度防止过长
  136. }
  137. .file-size {
  138. font-size: 26rpx;
  139. color: #999;
  140. }
  141. }
  142. .file-actions {
  143. .delete-btn {
  144. padding: 12rpx 24rpx;
  145. background: #ff4757;
  146. color: #fff;
  147. border-radius: 8rpx;
  148. font-size: 26rpx;
  149. }
  150. }
  151. .upload-tip {
  152. padding: 40rpx;
  153. text-align: center;
  154. .tip-text {
  155. font-size: 28rpx;
  156. color: #999;
  157. }
  158. }
  159. }
  160. </style>