UploadDrag.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div class="upload-wrapper upload-wrapper-drag">
  3. <el-upload
  4. ref="upload"
  5. accept=".jpg,.png"
  6. drag
  7. :before-upload="beforeUpload"
  8. :action="url"
  9. :on-exceed="handleExceed"
  10. :limit="limit"
  11. :on-success="handleSuccess"
  12. :file-list="fileList"
  13. :disabled="disabled"
  14. :on-progress="uploadVideoProcess"
  15. >
  16. <div class="plus-icon"><i class="el-icon-plus"></i></div>
  17. <div class="cn-tips">点击或拖拽图片到此上传</div>
  18. <div class="en-tips">Only png, jpg can be uploaded, and the size does not exceed 100MB</div>
  19. </el-upload>
  20. <el-progress style="width: 100%" v-if="progressFlag" :percentage="loadProgress"></el-progress>
  21. </div>
  22. </template>
  23. <script>
  24. import { getToken } from '@/utils/auth';
  25. export default {
  26. name: 'UploadAudio',
  27. props: {
  28. limit: {
  29. type: Number,
  30. default: 1,
  31. },
  32. itemIndex: {
  33. type: Number,
  34. default: null,
  35. },
  36. fileList: {
  37. type: Array,
  38. default: () => [],
  39. },
  40. disabled: {
  41. type: Boolean,
  42. default: false,
  43. },
  44. },
  45. data() {
  46. return {
  47. loadProgress: 0, // 动态显示进度条
  48. progressFlag: false, // 关闭进度条
  49. };
  50. },
  51. computed: {
  52. url() {
  53. let userInfor = getToken()
  54. ? JSON.parse(getToken())
  55. : sessionStorage.getItem('GCLS_Token_Tc')
  56. ? JSON.parse(sessionStorage.getItem('GCLS_Token_Tc'))
  57. : null;
  58. let SessionID = '';
  59. let UserCode = '';
  60. let UserType = '';
  61. if (userInfor) {
  62. UserCode = userInfor.user_code;
  63. UserType = userInfor.user_type;
  64. SessionID = userInfor.session_id;
  65. }
  66. return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&SecurityLevel=Mid"`;
  67. },
  68. },
  69. watch: {},
  70. methods: {
  71. beforeUpload(file) {
  72. // 可以用来限制文件大小
  73. if (file.size > 100 * 1024 * 1024) {
  74. this.$message.warning('上传图片大小不能超过100M');
  75. return false; // 必须返回false
  76. }
  77. },
  78. upload(file) {},
  79. handleExceed(files, fileList) {
  80. this.$message.warning(
  81. `当前限制选择 ${this.limit ? this.limit : 1} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
  82. files.length + fileList.length
  83. } 个文件`,
  84. );
  85. },
  86. handleSuccess(response, file, fileList) {
  87. if (response.status === 1) {
  88. this.$message.success('上传成功');
  89. this.progressFlag = false;
  90. this.$emit('changeFillId', response.file_info_list[0], fileList);
  91. }
  92. },
  93. onProgress(event, file, fileList) {
  94. let num = ((event.loaded / event.total) * 100) | 0; //百分比
  95. this.curPercentage = num;
  96. if (this.curPercentage == 100) {
  97. this.isShowJinDuTiao = false;
  98. this.curPercentage = 0;
  99. }
  100. },
  101. uploadVideoProcess(event, file, fileList) {
  102. this.progressFlag = true; // 显示进度条
  103. this.loadProgress = parseInt(event.percent); // 动态获取文件上传进度
  104. // if (this.loadProgress >= 100) {
  105. // this.loadProgress = 100;
  106. // setTimeout(() => {
  107. // this.progressFlag = false;
  108. // }, 1000); // 一秒后关闭进度条
  109. // }
  110. },
  111. },
  112. };
  113. </script>
  114. <style lang="scss" scoped>
  115. .upload-wrapper {
  116. height: 294px;
  117. background-color: #f2f3f5;
  118. border-radius: 8px;
  119. overflow: hidden;
  120. .plus-icon {
  121. margin: 95px auto 20px auto;
  122. color: #4e5969;
  123. }
  124. .cn-tips {
  125. font-size: 14px;
  126. font-weight: 400;
  127. line-height: 22px;
  128. color: #1d2129;
  129. }
  130. .en-tips {
  131. font-size: 12px;
  132. font-weight: 400;
  133. line-height: 20px;
  134. color: #86909c;
  135. }
  136. .el-image {
  137. background: #f2f3f5;
  138. }
  139. }
  140. </style>
  141. <style lang="scss">
  142. .upload-wrapper-drag {
  143. .el-upload {
  144. width: 100%;
  145. height: 274px;
  146. }
  147. .el-upload-dragger {
  148. border: none;
  149. background-color: transparent;
  150. width: 100%;
  151. height: 100%;
  152. }
  153. }
  154. </style>