jinlin
2024-01-29 7a0c5479c363a10f573aa15a54dc8130eabd47ff
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<template>
  <div v-loading="loading" class="fa-card-a" shadow="never">
    <el-row :gutter="24">
      <el-col :span="12">
        <dataExportRecord ref="child"/>
      </el-col>
      <el-col :span="12">
        <el-form ref="ruleForm" :model="dataForm" :rules="rules"
                 @keyup.enter.native="table.query()">
          <el-form-item>
            <el-button class="form-title" type="text">本次导出信息</el-button>
          </el-form-item>
          <el-form-item label="导出时间范围" required label-width="150px">
            <el-col :span="12">
              <el-date-picker v-model="dateVals" :clearable="false" :editable="false" end-placeholder="结束日期"
                              range-separator="至" start-placeholder="开始日期"
                              type="daterange" value-format="yyyy-MM-dd" @change="pickerChange">
              </el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="是否导出附件" required label-width="150px">
            <el-col :span="12">
              <el-checkbox v-model="dataForm.exportFile"></el-checkbox>
            </el-col>
            <el-col :span="12">
              <!-- <zt-button type="export" :disabled="dis" @click="exportData">增量数据包</zt-button> -->
              <el-button :disabled="dis" icon="el-icon-download" type="primary" @click="exportData">增量数据包
              </el-button>
              <el-link id="d" :href="filePath" style="visibility:hidden" target="_blank" type="primary">下载
              </el-link>
            </el-col>
          </el-form-item>
 
          <!-- <el-form-item label="导出时间范围" required>
            <el-col :span="11">
              <el-form-item prop="gmtStart">
                <el-date-picker type="date" placeholder="选择日期" format="yyyy-MM-dd" v-model="dataForm.gmtStart" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="line" :span="2">至</el-col>
            <el-col :span="11">
              <el-form-item prop="gmtEnd">
                <el-date-picker type="date" placeholder="选择日期" format="yyyy-MM-dd" v-model="dataForm.gmtEnd" style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-form-item> -->
          <!--
                          <el-form-item label="导出目标区域" prop="target" label-width="150px">
                            <el-col :span="12">
                              <zt-select v-model="dataForm.target" :datas="cmplist" placeholder="请选择目标区域"></zt-select>
                            </el-col>
                          </el-form-item>
          -->
        </el-form>
        <el-progress style="padding: 20px" :percentage="dataForm.speed" :stroke-width="30"
                     :text-inside="true"></el-progress>
        <el-input v-model="dataForm.text" :autosize="{ minRows: 25, maxRows: 25}" readonly type="textarea">
        </el-input>
      </el-col>
    </el-row>
  </div>
</template>
<script>
  import Cookies from 'js-cookie'
  import qs from 'qs'
  import dataExportRecord from './data-export-record'
  import {guid} from '@/commonJS/common';
 
  export default {
    data() {
      return {
        localShip: 0,
        dataForm: {
          progressId: 0,
          exportFile: true,
          id: '',
          speed: 0,
          text: '',
          gmtStart: '',
          gmtEnd: '',
          target: 'jd',
          targetPid: ''
        },
        dateVals: [],
        start: 0,
        filePath: '',
        cmplist: [],
        dis: false,
        rules: {
          gmtStart: [
            {
              type: 'date',
              required: true,
              message: '请选择日期',
              trigger: 'change'
            }
          ],
          gmtEnd: [
            {
              type: 'date',
              required: true,
              message: '请选择日期',
              trigger: 'change'
            }
          ],
          target: [
            {
              required: true,
              message: '请选择导出目标区域',
              trigger: 'change'
            }
          ]
        },
        tarlist: [],
        loading: false
      }
    },
    components: {
      dataExportRecord
    },
    mounted() {
      // this.gettarget()
      this.defaultDate()
    },
    methods: {
      async exportData() {
 
        // this.loading = true
        /*        let sub = false
                this.$refs['ruleForm'].validate((valid) => {
                  if (valid) {
                    sub = true
                  } else {
                    return false
                  }
                })*/
        let sub = true
        if (sub) {
          this.dataForm.progressId = guid()
          this.dis = true
          this.dataForm.speed = 0
          this.start = 1
          this.timer = setInterval(this.getStroke, 1000)
          window.console.log(this.dataForm)
          let res = await this.$http.post(
            '/sys/data/export/record/exportData',
            this.dataForm
          )
          if (res.success) {
            clearInterval(this.timer)
            this.dataForm.speed = 100
            this.$refs.child.$refs.tableObj.query()
            this.loading = false
            this.dis = false
            window.console.log(res)
            if (res.data.fileName) {
              this.filePath = res.data.path + res.data.fileName
              this.download(res.data.fileName)
            } else {
              this.$tip.error('当前条件下没有可导出数据')
            }
          } else {
            clearInterval(this.timer)
            this.loading = false
            window.console.log(res.data)
            this.dis = false
          }
        }
      },
      async download(name) {
        var params = qs.stringify({
          token: Cookies.get('token'),
          resourcePath: this.filePath,
          fileName: name
        })
        let apiURL = `/sys/data/export/record/download`
        window.location.href = `${window.SITE_CONFIG['apiURL']}${apiURL}?${params}`
      },
      async gettarget() {
        let res = await this.$http.get('/sys/data/export/record/dict')
        if (res.success) {
          console.log(res.data, 'res.data gettarget')
          this.cmplist = res.data
        }
      },
      async getStroke() {
        if (this.start === 1 && this.dataForm.speed < 100) {
          let res = await this.$http.get(`/sys/common/stroke?progressId=${this.dataForm.progressId}`)
          if (res.success) {
            this.dataForm.speed = parseFloat(res.data.speed)
            this.dataForm.text = res.data.text
          } else {
            clearInterval(this.timer)
          }
        }
      },
      handleChange(value) {
        if (this.tarlist.length < 2) {
          this.dataForm.target = this.tarlist[0]
          this.dataForm.targetPid = this.tarlist[0]
        } else {
          this.dataForm.target = this.tarlist[1]
          this.dataForm.targetPid = this.tarlist[0]
        }
      }, // 设置默认日期
      defaultDate() {
        // 获取新的时间(2019.4.12)
        let date = new Date()
        // 字符串拼接,开始时间,结束时间
        let end = date.getFullYear().toString() + '-' + (date.getMonth() + 1).toString() + '-' + date.getDate().toString()
        // let beg = date.getFullYear().toString() + '-' + (date.getMonth() + 1).toString() + '-' + date.getDate().toString()
        // 获取7天前的日期
        date.setDate(date.getDate() - 7);
        // 格式化日期为字符串
        let beg = date.toISOString().split('T')[0];
        console.log(beg, '开始时间')
        this.dataForm.gmtStart = beg
        this.dataForm.gmtEnd = end
        this.dateVals = [beg, end] // 将值设置给插件绑定的数据
      },
      pickerChange() {
        this.dataForm.gmtStart = this.dateVals[0]
        this.dataForm.gmtEnd = this.dateVals[1]
      }
    },
    beforeDestroy() {
      clearInterval(this.timer)
    }
  }
</script>