order-file-upload.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. fileType: {
  48. type: String,
  49. default: 'all',
  50. desc: '文件选择类型:all(所有)、image(图片)、video(视频)、audio(音频)、document(文档)等'
  51. },
  52. },
  53. data() {
  54. return {
  55. }
  56. },
  57. watch: {
  58. fileList: {
  59. handler(newVal) {
  60. this.uploadList = [...newVal];
  61. },
  62. immediate: true
  63. }
  64. },
  65. methods: {
  66. handleUploadSuccess(){
  67. uni.$u.toast("上传成功");
  68. },
  69. // 删除文件
  70. handleDelete(index) {
  71. uni.showModal({
  72. title: '提示',
  73. content: '确定要删除该文件吗?',
  74. success: (res) => {
  75. if (res.confirm) {
  76. this.uploadList.splice(index, 1);
  77. this.$emit('update:fileList', this.uploadList);
  78. this.$emit('change', {
  79. type: this.orderFileType,
  80. fileList: this.uploadList
  81. });
  82. }
  83. }
  84. });
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .order-file-upload {
  91. .upload-section {
  92. background: #fff;
  93. margin-bottom: 20rpx;
  94. border-radius: 16rpx;
  95. overflow: hidden;
  96. }
  97. .upload-title {
  98. display: flex;
  99. justify-content: space-between;
  100. align-items: center;
  101. padding: 30rpx 40rpx;
  102. border-bottom: 1rpx solid #f5f5f5;
  103. .title-text {
  104. font-size: 32rpx;
  105. font-weight: 500;
  106. color: #333;
  107. }
  108. .upload-btn {
  109. padding: 12rpx 24rpx;
  110. background: #007aff;
  111. color: #fff;
  112. border-radius: 8rpx;
  113. font-size: 28rpx;
  114. }
  115. }
  116. .file-list {
  117. padding: 20rpx 40rpx;
  118. }
  119. .file-item {
  120. display: flex;
  121. justify-content: space-between;
  122. align-items: center;
  123. padding: 20rpx 0;
  124. border-bottom: 1rpx solid #f5f5f5;
  125. &:last-child {
  126. border-bottom: none;
  127. }
  128. }
  129. .file-info {
  130. flex: 1;
  131. min-width: 0; // 防止flex子元素溢出
  132. .file-name {
  133. display: block;
  134. font-size: 30rpx;
  135. color: #333;
  136. margin-bottom: 8rpx;
  137. overflow: hidden;
  138. text-overflow: ellipsis;
  139. white-space: nowrap;
  140. max-width: 400rpx; // 设置最大宽度防止过长
  141. }
  142. .file-size {
  143. font-size: 26rpx;
  144. color: #999;
  145. }
  146. }
  147. .file-actions {
  148. .delete-btn {
  149. padding: 12rpx 24rpx;
  150. background: #ff4757;
  151. color: #fff;
  152. border-radius: 8rpx;
  153. font-size: 26rpx;
  154. }
  155. }
  156. .upload-tip {
  157. padding: 40rpx;
  158. text-align: center;
  159. .tip-text {
  160. font-size: 28rpx;
  161. color: #999;
  162. }
  163. }
  164. }
  165. </style>