UploadDrag.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. >
  15. <div class="plus-icon"><i class="el-icon-plus"></i></div>
  16. <div class="cn-tips">点击或拖拽图片到此上传</div>
  17. <div class="en-tips">Only png, jpg can be uploaded, and the size does not exceed 100MB</div>
  18. </el-upload>
  19. </div>
  20. </template>
  21. <script>
  22. import { getToken } from '@/utils/auth';
  23. export default {
  24. name: 'UploadAudio',
  25. props: {
  26. limit: {
  27. type: Number,
  28. default: 1,
  29. },
  30. itemIndex: {
  31. type: Number,
  32. default: null,
  33. },
  34. fileList: {
  35. type: Array,
  36. default: () => [],
  37. },
  38. disabled: {
  39. type: Boolean,
  40. default: false,
  41. },
  42. },
  43. data() {
  44. return {};
  45. },
  46. computed: {
  47. url() {
  48. let userInfor = JSON.parse(getToken());
  49. let SessionID = '';
  50. let UserCode = '';
  51. let UserType = '';
  52. if (userInfor) {
  53. UserCode = userInfor.user_code;
  54. UserType = userInfor.user_type;
  55. SessionID = userInfor.session_id;
  56. }
  57. return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&SecurityLevel=Mid"`;
  58. },
  59. },
  60. watch: {},
  61. methods: {
  62. beforeUpload(file) {
  63. // 可以用来限制文件大小
  64. if (file.size > 100 * 1024 * 1024) {
  65. this.$message.warning('上传图片大小不能超过100M');
  66. return false; // 必须返回false
  67. }
  68. },
  69. upload(file) {},
  70. handleExceed(files, fileList) {
  71. this.$message.warning(
  72. `当前限制选择 ${this.limit ? this.limit : 1} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
  73. files.length + fileList.length
  74. } 个文件`,
  75. );
  76. },
  77. handleSuccess(response, file, fileList) {
  78. if (response.status === 1) {
  79. this.$message.success('上传成功');
  80. this.$emit('changeFillId', response.file_info_list[0], fileList);
  81. }
  82. },
  83. onProgress(event, file, fileList) {
  84. let num = ((event.loaded / event.total) * 100) | 0; //百分比
  85. this.curPercentage = num;
  86. if (this.curPercentage == 100) {
  87. this.isShowJinDuTiao = false;
  88. this.curPercentage = 0;
  89. }
  90. },
  91. },
  92. };
  93. </script>
  94. <style lang="scss" scoped>
  95. .upload-wrapper {
  96. min-height: 224px;
  97. background-color: #f5f5f5;
  98. .plus-icon {
  99. margin: 50px auto 20px auto;
  100. color: #4e5969;
  101. }
  102. .cn-tips {
  103. font-size: 14px;
  104. font-weight: 400;
  105. line-height: 22px;
  106. color: #1d2129;
  107. }
  108. .en-tips {
  109. font-size: 12px;
  110. font-weight: 400;
  111. line-height: 20px;
  112. color: #86909c;
  113. }
  114. }
  115. </style>
  116. <style lang="scss">
  117. .upload-wrapper-drag {
  118. .el-upload {
  119. width: 100%;
  120. }
  121. .el-upload-dragger {
  122. border: none;
  123. background-color: transparent;
  124. width: 100%;
  125. }
  126. }
  127. </style>