UploadDrag.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 = getToken()
  49. ? JSON.parse(getToken())
  50. : sessionStorage.getItem('GCLS_Token_Tc')
  51. ? JSON.parse(sessionStorage.getItem('GCLS_Token_Tc'))
  52. : null;
  53. let SessionID = '';
  54. let UserCode = '';
  55. let UserType = '';
  56. if (userInfor) {
  57. UserCode = userInfor.user_code;
  58. UserType = userInfor.user_type;
  59. SessionID = userInfor.session_id;
  60. }
  61. return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&SecurityLevel=Mid"`;
  62. },
  63. },
  64. watch: {},
  65. methods: {
  66. beforeUpload(file) {
  67. // 可以用来限制文件大小
  68. if (file.size > 100 * 1024 * 1024) {
  69. this.$message.warning('上传图片大小不能超过100M');
  70. return false; // 必须返回false
  71. }
  72. },
  73. upload(file) {},
  74. handleExceed(files, fileList) {
  75. this.$message.warning(
  76. `当前限制选择 ${this.limit ? this.limit : 1} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
  77. files.length + fileList.length
  78. } 个文件`,
  79. );
  80. },
  81. handleSuccess(response, file, fileList) {
  82. if (response.status === 1) {
  83. this.$message.success('上传成功');
  84. this.$emit('changeFillId', response.file_info_list[0], fileList);
  85. }
  86. },
  87. onProgress(event, file, fileList) {
  88. let num = ((event.loaded / event.total) * 100) | 0; //百分比
  89. this.curPercentage = num;
  90. if (this.curPercentage == 100) {
  91. this.isShowJinDuTiao = false;
  92. this.curPercentage = 0;
  93. }
  94. },
  95. },
  96. };
  97. </script>
  98. <style lang="scss" scoped>
  99. .upload-wrapper {
  100. min-height: 224px;
  101. background-color: #f5f5f5;
  102. .plus-icon {
  103. margin: 50px auto 20px auto;
  104. color: #4e5969;
  105. }
  106. .cn-tips {
  107. font-size: 14px;
  108. font-weight: 400;
  109. line-height: 22px;
  110. color: #1d2129;
  111. }
  112. .en-tips {
  113. font-size: 12px;
  114. font-weight: 400;
  115. line-height: 20px;
  116. color: #86909c;
  117. }
  118. }
  119. </style>
  120. <style lang="scss">
  121. .upload-wrapper-drag {
  122. .el-upload {
  123. width: 100%;
  124. }
  125. .el-upload-dragger {
  126. border: none;
  127. background-color: transparent;
  128. width: 100%;
  129. }
  130. }
  131. </style>