datacenterUpload.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <div class="datacenter-upload">
  3. <el-upload :action="action" name="uploadFile" ref="upload" :headers="headers" :on-success="successFile"
  4. :before-upload="beforeUpload" :on-error="errorUpload" :show-file-list="false" :on-progress="progress">
  5. <div class="bim-update-button">
  6. <i class="el-icon-plus"></i>
  7. </div>
  8. </el-upload>
  9. </div>
  10. </template>
  11. <script>
  12. import config from '@/config';
  13. import {
  14. getToken
  15. } from '@/uitls/auth';
  16. export default {
  17. props: ['parentId'],
  18. data() {
  19. return {
  20. action: '',
  21. headers: {}
  22. };
  23. },
  24. created() {
  25. this.action = config.baseURL + '/file/filenode/' + this.parentId;
  26. this.headers.token = getToken();
  27. },
  28. methods: {
  29. beforeUpload() {
  30. this.$loading();
  31. },
  32. progress(e) {
  33. let percent = e.percent >= 100 ? 99 : parseInt(e.percent)
  34. this.$loading({
  35. percent: (percent + '%')
  36. });
  37. },
  38. reloadUpload() {
  39. this.$refs['upload'].$children[0].$refs.input.click();
  40. },
  41. errorUpload() {
  42. this.$loading.close();
  43. this.$message.error('上传失败');
  44. },
  45. successFile(data) {
  46. this.$message.success('上传成功');
  47. this.$emit('reload');
  48. this.$loading.close();
  49. },
  50. },
  51. watch: {
  52. parentId() {
  53. this.action = config.baseURL + '/file/filenode/' + this.parentId;
  54. }
  55. },
  56. };
  57. </script>
  58. <style lang="scss">
  59. .datacenter-upload {}
  60. </style>