ProgressPage.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div v-show="visible" class="main">
  3. <div class="center">
  4. <el-progress type="circle" :width="100" :stroke-width="5" color="#0F9900" :percentage="percentage"></el-progress>
  5. <p class="text">{{ text }}</p>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. //-----------------------------------------------------------------------------
  11. import Vue from 'vue';
  12. import Component from 'vue-class-component';
  13. import {sleep} from '../../../share/utils';
  14. const ruMessage = {
  15. 'start': ' ',
  16. 'finish': ' ',
  17. 'error': ' ',
  18. 'download': 'скачивание',
  19. 'decompress': 'распаковка',
  20. 'convert': 'конвертирование',
  21. 'loading': 'загрузка',
  22. 'parse': 'обработка',
  23. };
  24. export default @Component({
  25. })
  26. class ProgressPage extends Vue {
  27. text = '';
  28. totalSteps = 1;
  29. step = 1;
  30. progress = 0;
  31. visible = false;
  32. async show() {
  33. this.$el.style.width = this.$parent.$el.offsetWidth + 'px';
  34. this.$el.style.height = this.$parent.$el.offsetHeight + 'px';
  35. this.text = '';
  36. this.totalSteps = 1;
  37. this.step = 1;
  38. this.progress = 0;
  39. this.visible = true;
  40. await sleep(1);
  41. return true;
  42. }
  43. async hide() {
  44. await sleep(350);
  45. this.visible = false;
  46. return false;
  47. }
  48. setState(state) {
  49. if (state.state)
  50. this.text = (ruMessage[state.state] ? ruMessage[state.state] : state.state);
  51. this.step = (state.step ? state.step : this.step);
  52. this.totalSteps = (state.totalSteps > this.totalSteps ? state.totalSteps : this.totalSteps);
  53. this.progress = (state.progress ? state.progress : this.progress);
  54. }
  55. get percentage() {
  56. return Math.round(((this.step - 1)/this.totalSteps + this.progress/(100*this.totalSteps))*100);
  57. }
  58. }
  59. //-----------------------------------------------------------------------------
  60. </script>
  61. <style scoped>
  62. .main {
  63. display: flex;
  64. flex-direction: column;
  65. justify-content: center;
  66. align-items: center;
  67. z-index: 100;
  68. background-color: rgba(0, 0, 0, 0.8);
  69. position: absolute;
  70. }
  71. .center {
  72. display: flex;
  73. flex-direction: column;
  74. justify-content: flex-start;
  75. align-items: center;
  76. color: white;
  77. height: 300px;
  78. }
  79. .text {
  80. color: yellow;
  81. }
  82. </style>
  83. <style>
  84. .el-progress__text {
  85. color: lightgreen;
  86. }
  87. </style>