Download.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div class="l-flex--col c-runtime">
  3. <div class="l-flex--row l-flex__none has-bottom-padding">
  4. <i class="l-flex__none c-runtime__icon download" />
  5. <span class="l-flex__fill c-runtime__title u-ellipsis">文件下载</span>
  6. <i
  7. v-if="count"
  8. class="l-flex__none c-runtime__list el-icon-s-operation u-pointer"
  9. @click="showDownload"
  10. />
  11. </div>
  12. <div class="l-flex__fill u-text-center">
  13. <div class="has-bottom-padding">当前已下载文件</div>
  14. <div class="u-color--black">
  15. <span class="large">{{ downloadCount }}</span> 个
  16. </div>
  17. </div>
  18. <div
  19. v-if="count !== downloadCount"
  20. class="l-flex__none u-color--error dark u-bold u-text-center"
  21. >
  22. 正在下载文件...
  23. </div>
  24. <el-dialog
  25. title="文件下载详情"
  26. :visible.sync="showProgress"
  27. custom-class="c-dialog"
  28. append-to-body
  29. >
  30. <download-progress @update="onUpdate" />
  31. </el-dialog>
  32. </div>
  33. </template>
  34. <script>
  35. import {
  36. addListener,
  37. removeListener
  38. } from '../monitor'
  39. import DownloadProgress from './DownloadProgress'
  40. export default {
  41. name: 'DeviceDownload',
  42. components: {
  43. DownloadProgress
  44. },
  45. data () {
  46. return {
  47. showProgress: false,
  48. count: 0,
  49. downloadCount: 0,
  50. loading: false
  51. }
  52. },
  53. created () {
  54. addListener('download', this.onUpdate)
  55. },
  56. beforeDestroy () {
  57. removeListener('download', this.onUpdate)
  58. },
  59. methods: {
  60. onUpdate (files) {
  61. this.count = files.length
  62. this.downloadCount = files.filter(({ complete, success }) => complete && success).length
  63. this.loading = files.some(({ complete }) => !complete)
  64. },
  65. showDownload () {
  66. this.showProgress = true
  67. }
  68. }
  69. }
  70. </script>