GlobalProgress.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div v-show="showProgress" class="global-progress">
  3. <div class="progress">
  4. <div class="title">上传...</div>
  5. <el-progress :percentage="uploadInfo.progress" :show-text="false" />
  6. <div class="upload-info">
  7. <span>上传文件 {{ uploadInfo.loaded }}/{{ uploadInfo.total }}</span>
  8. <span :class="[{ success: complete }]">{{ uploadText }}</span>
  9. </div>
  10. <div class="footer">
  11. <el-button v-if="complete" type="primary" @click="uploadComplete">完成</el-button>
  12. <el-button v-else @click="cancelUpload">取消</el-button>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. import { mapState } from 'vuex';
  19. import { app } from '@/store/mutation-types';
  20. export default {
  21. name: 'GlobalProgress',
  22. data() {
  23. return {};
  24. },
  25. computed: {
  26. complete() {
  27. return this.uploadInfo.progress === 100;
  28. },
  29. uploadText() {
  30. if (this.complete) return '上传成功';
  31. return `${this.uploadInfo.progress}%`;
  32. },
  33. ...mapState({
  34. uploadInfo: (state) => state.app.uploadInfo,
  35. uploadController: (state) => state.app.uploadController,
  36. showProgress: (state) => state.app.showProgress,
  37. }),
  38. },
  39. methods: {
  40. cancelUpload() {
  41. this.$store.commit(`app/${app.SHOW_PROGRESS}`, false);
  42. this.$store.commit(`app/${app.RESET_UPLOAD_INFO}`);
  43. this.uploadController?.abort();
  44. },
  45. uploadComplete() {
  46. this.$store.commit(`app/${app.SHOW_PROGRESS}`, false);
  47. this.$store.commit(`app/${app.RESET_UPLOAD_INFO}`);
  48. },
  49. },
  50. };
  51. </script>
  52. <style lang="scss" scoped>
  53. .global-progress {
  54. position: fixed;
  55. inset: 0;
  56. z-index: 3001;
  57. display: flex;
  58. justify-content: center;
  59. color: #242634;
  60. background-color: hsla(0deg, 0%, 100%, 80%);
  61. transition: opacity 0.3s;
  62. .progress {
  63. display: flex;
  64. flex-direction: column;
  65. row-gap: 8px;
  66. width: 400px;
  67. height: 164px;
  68. padding: 24px;
  69. margin-top: 35vh;
  70. background-color: #fff;
  71. border-radius: 4px;
  72. box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 8%);
  73. .title {
  74. font-weight: bold;
  75. }
  76. .upload-info {
  77. display: flex;
  78. justify-content: space-between;
  79. font-size: 12px;
  80. :first-child {
  81. font-weight: bold;
  82. }
  83. span.success {
  84. color: #0fbc00;
  85. }
  86. }
  87. .footer {
  88. margin-top: 16px;
  89. text-align: center;
  90. }
  91. }
  92. }
  93. </style>