pretty-uploadFile.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view>
  3. <!-- 上传文件 begin -->
  4. <view class="display_flex">
  5. <view class="img_list" v-for="(item,index) in fileList" :key="index">
  6. <image class="img_item" :src="item.url" @click="preview(item.url)" mode="aspectFill" v-if="item.book == 'img'"></image>
  7. <view class="upload" @click="prePdf(item.id)" v-else>
  8. <text class="iconfont iconpdf" style="color:#FF6969;font-size:44px"></text>
  9. </view>
  10. <view class="iconfont deleteicon iconshanchu2" @click.stop="delteFile(index)"></view>
  11. </view>
  12. <view class="upload img_list" @click="upload('img')">
  13. <view class="iconfont iconziyuan" style="font-size:20px;"></view>
  14. 上传照片
  15. </view>
  16. <view class="upload img_list" @click="upload('file')">
  17. <view class="iconfont iconshangchuanwenjian fileicon"></view>
  18. 上传文件
  19. </view>
  20. </view>
  21. <!-- 上传文件 end -->
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. get,
  27. post
  28. } from './utils/request.js'
  29. import {
  30. uploadImage,
  31. uploadPdf
  32. } from './utils/uploadimage.js'
  33. import {
  34. previepdf
  35. } from './utils/openpdf.js'
  36. export default {
  37. name: 'upload',
  38. model: {
  39. prop: "showPop",
  40. event: "change"
  41. },
  42. props: {
  43. limitnumber: {
  44. type: Number,
  45. default: 10
  46. },
  47. },
  48. data() {
  49. return {
  50. fileList: []
  51. }
  52. },
  53. methods: {
  54. /**
  55. * @description 上传文件
  56. */
  57. upload(book) {
  58. if (this.fileList.length == this.$props.limitnumber) {
  59. uni.showToast({
  60. title: '文件上传已上限',
  61. icon: 'none'
  62. })
  63. return
  64. }
  65. if (book == 'img') {
  66. uploadImage().then(res => {
  67. this.fileList.push({
  68. url: res.imageurl,
  69. id: res.uploadId,
  70. book: 'img'
  71. })
  72. this.$emit('upload',this.fileList)
  73. })
  74. } else {
  75. uploadPdf().then(res => {
  76. this.fileList.push({
  77. id: res.uploadId,
  78. book: 'file'
  79. })
  80. })
  81. this.$emit('upload',this.fileList)
  82. }
  83. },
  84. /**
  85. * @description 预览图片
  86. */
  87. preview(url) {
  88. uni.previewImage({
  89. urls: [url],
  90. current: url
  91. })
  92. },
  93. /**
  94. * @description 预览pdf
  95. */
  96. prePdf(e) {
  97. let id = `/api/v1/consumer/download/${e}` // 下载pdf文件的借口地址
  98. previepdf(id)
  99. },
  100. /**
  101. * @description 删除上传的文件
  102. */
  103. delteFile(index) {
  104. this.fileList.splice(index, 1)
  105. this.$emit('upload',this.fileList)
  106. },
  107. }
  108. }
  109. </script>
  110. <style>
  111. @import "./pretty-uploadFile.css";
  112. .display_flex {
  113. display: flex;
  114. flex-wrap: wrap;
  115. width: 100%;
  116. }
  117. .fileicon {
  118. font-size: 25px;
  119. }
  120. /* 上传图片 */
  121. .img_list {
  122. width: 70px;
  123. height: 70px;
  124. border-radius: 5px;
  125. margin: 10px 5px;
  126. position: relative;
  127. }
  128. .img>image {
  129. width: 70px;
  130. height: 70px;
  131. border-radius: 5px;
  132. }
  133. .img_item {
  134. width: 70px;
  135. height: 70px;
  136. border-radius: 5px;
  137. }
  138. .upload {
  139. height: 70px;
  140. width: 70px;
  141. background-color: #f7f7f7;
  142. border: 1px dashed rgb(224, 223, 223);
  143. display: flex;
  144. flex-direction: column;
  145. justify-content: center;
  146. align-items: center;
  147. font-size: 14px;
  148. color: #aaa;
  149. word-break: break-all;
  150. overflow: hidden;
  151. }
  152. .deleteicon {
  153. position: absolute;
  154. font-size: 20px;
  155. color: #F93313;
  156. top: -10px;
  157. right: -6px;
  158. background-color: #fff;
  159. border-radius: 50%;
  160. }
  161. </style>