order-file-upload.vue 3.5 KB

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