wente
2023-11-16 b341867731286e7ebfa1bc5fd8f699c780d232a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<template>
  <div shadow="never" class="fa-card-a">
    <div class="mod-sync-sysDataExportRecord}">
      <el-form :model="dataForm" @keyup.enter.native="table.query()">
        <el-form-item>
          <!-- <el-input v-model="dataForm.progressId"></el-input>-->
          <el-button type="text" class="form-title">导入数据包</el-button>
          <zt-uploader v-model="temp" :dataForm="dataForm" :limit="1"
                       :file-type="fileTypeArr" @recall="processData"
                       :onlyUploadFile="true" :accept="true" :file-size="0"/>
          <el-progress v-show="progressFlag" style="padding: 0px" :text-inside="true" :stroke-width="30"
                       :percentage="dataForm.speed"></el-progress>
          <br/>
          <el-input v-model="dataForm.text" :autosize="{ minRows: 27, maxRows: 27}" readonly type="textarea">
          </el-input>
        </el-form-item>
      </el-form>
      <el-dialog title="警告" :visible.sync="dialogVisible" width="30%">
        <span style="color:red">{{ dialogMsg }}</span>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
 
<script>
  import Cookies from 'js-cookie'
  import qs from 'qs'
  import {guid} from '@/commonJS/common';
 
  export default {
    data() {
      return {
        fileTypeArr: ['zip'],
        progressFlag: false,
        maxFileSize: 0,
        mark: false,
        temp: [],
        dataForm: {
          progressId: '2222',
          speed: 0,
          text: ''
        },
        apiURL: '',
        start: 0,
        dialogVisible: false,
        dialogMsg: '',
        fileList: []
      }
    },
    created() {
 
    },
    methods: {
      format(percentage) {
        return percentage < 100 ? '完成处理' : `已处理${percentage}%`;
      },
      async processData(uid) {
        this.progressFlag = true
        console.log(uid, 'uid')
        this.start = 1
        this.timer = setInterval(this.getStroke, 1000)
        this.dataForm.progressId = guid()
        this.dataForm.speed = 0
        this.dataForm.text = '正在处理'
        this.mark = true
 
        let formData = {
          uid: uid,
          progressId: this.dataForm.progressId
        }
        this.$http({
          url: "/sys/data/export/record/upload",
          method: "POST",
          data: formData
        }).then(rs => {
          this.$http.get(`/sys/common/stroke?progressId=${this.dataForm.progressId}`).then(res => {
            if (res.success) {
              console.log(this.dataForm.speed, 'this.dataForm.speed')
              this.dataForm.speed = 100
              this.dataForm.text = res.data.text
              this.progressFlag = false
            }
          })
          this.mark = false
          clearInterval(this.timers)
        });
      },
      async getStroke() {
        if (this.start === 1 && this.dataForm.speed < 100 && this.mark) {
          let res = await this.$http.get(`/sys/common/stroke?progressId=${this.dataForm.progressId}`)
          if (res.success) {
            console.log(this.dataForm.speed, 'this.dataForm.speed')
            this.dataForm.speed = parseFloat(res.data.speed)
            this.dataForm.text = res.data.text
          }
        } else {
          clearInterval(this.timer)
        }
      }
    },
    beforeDestroy() {
      clearInterval(this.timer)
    }
  }
</script>