SyncChannelProgress.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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.data.syncIng) {
  64. if (res.data.data.total == 0) {
  65. this.msg = `等待同步中`;
  66. this.timmer = setTimeout(this.getProgress, 300)
  67. }else {
  68. this.total = res.data.data.total;
  69. this.current = res.data.data.current;
  70. this.percentage = Math.floor(Number(res.data.data.current)/Number(res.data.data.total)* 10000)/100;
  71. this.msg = `同步中...[${res.data.data.current}/${res.data.data.total}]`;
  72. this.timmer = setTimeout(this.getProgress, 300)
  73. }
  74. }else {
  75. if (res.data.data.errorMsg){
  76. this.msg = res.data.data.errorMsg;
  77. this.syncStatus = "exception"
  78. }else {
  79. this.syncStatus = "success"
  80. this.percentage = 100;
  81. this.msg = '同步成功';
  82. setTimeout(()=>{
  83. this.showDialog = false;
  84. }, 3000)
  85. }
  86. }
  87. }
  88. }else {
  89. if (this.syncFlag) {
  90. this.syncStatus = "success"
  91. this.percentage = 100;
  92. this.msg = '同步成功';
  93. }else {
  94. this.syncStatus = "error"
  95. this.msg = res.data.msg;
  96. }
  97. }
  98. }).catch((error) =>{
  99. console.log(error);
  100. this.syncStatus = "error"
  101. this.msg = error.response.data.msg;
  102. });
  103. },
  104. close: function (){
  105. window.clearTimeout(this.timmer)
  106. }
  107. },
  108. };
  109. </script>