SyncChannelProgress.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div id="SyncChannelProgress" v-loading="isLoging">
  3. <el-dialog
  4. width="240px"
  5. top="13%"
  6. :append-to-body="true"
  7. :close-on-click-modal="false"
  8. :visible.sync="showDialog"
  9. :destroy-on-close="true"
  10. :show-close="true"
  11. @close="close()"
  12. style="text-align: center">
  13. <el-progress type="circle" :percentage="percentage" :status="syncStatus"></el-progress>
  14. <div style="text-align: center">
  15. {{msg}}
  16. </div>
  17. </el-dialog>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. name: "SyncChannelProgress",
  23. computed: {},
  24. props: ['platformId'],
  25. created() {},
  26. data() {
  27. return {
  28. syncStatus: null,
  29. percentage: 0,
  30. total: 0,
  31. current: 0,
  32. showDialog: false,
  33. isLoging: false,
  34. syncFlag: false,
  35. deviceId: null,
  36. timmer: null,
  37. msg: "正在同步",
  38. };
  39. },
  40. methods: {
  41. openDialog: function (deviceId) {
  42. console.log("deviceId: " + deviceId)
  43. this.deviceId = deviceId;
  44. this.showDialog = true;
  45. this.msg = "";
  46. this.percentage= 0;
  47. this.total= 0;
  48. this.current= 0;
  49. this.syncFlag= false;
  50. this.syncStatus = null;
  51. this.getProgress()
  52. },
  53. getProgress(){
  54. this.$axios({
  55. method: 'get',
  56. url:`/api/device/query/${this.deviceId}/sync_status/`,
  57. }).then((res) => {
  58. if (res.data.code === 0) {
  59. if (!this.syncFlag) {
  60. this.syncFlag = true;
  61. }
  62. if (res.data.data != null) {
  63. if (res.data.syncIng) {
  64. if (res.data.data.total == 0) {
  65. if (res.data.data.errorMsg !== null ){
  66. this.msg = res.data.data.errorMsg;
  67. this.syncStatus = "exception"
  68. }else {
  69. this.msg = `等待同步中`;
  70. this.timmer = setTimeout(this.getProgress, 300)
  71. }
  72. }else {
  73. if (res.data.data.total == res.data.data.current) {
  74. this.syncStatus = "success"
  75. this.percentage = 100;
  76. this.msg = '同步成功';
  77. }else {
  78. if (res.data.data.errorMsg !== null ){
  79. this.msg = res.data.data.errorMsg;
  80. this.syncStatus = "exception"
  81. }else {
  82. this.total = res.data.data.total;
  83. this.current = res.data.data.current;
  84. this.percentage = Math.floor(Number(res.data.data.current)/Number(res.data.data.total)* 10000)/100;
  85. this.msg = `同步中...[${res.data.data.current}/${res.data.data.total}]`;
  86. this.timmer = setTimeout(this.getProgress, 300)
  87. }
  88. }
  89. }
  90. }else {
  91. this.syncStatus = "success"
  92. this.percentage = 100;
  93. this.msg = '同步成功';
  94. }
  95. }
  96. }else {
  97. if (this.syncFlag) {
  98. this.syncStatus = "success"
  99. this.percentage = 100;
  100. this.msg = '同步成功';
  101. }else {
  102. this.syncStatus = "error"
  103. this.msg = res.data.msg;
  104. }
  105. }
  106. }).catch((error) =>{
  107. console.log(error);
  108. this.syncStatus = "error"
  109. this.msg = error.response.data.msg;
  110. });
  111. },
  112. close: function (){
  113. window.clearTimeout(this.timmer)
  114. }
  115. },
  116. };
  117. </script>