ArrivalAnalysis.vue
10.3 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<template>
<el-container>
<el-main>
<el-card style="background-color: #F5F7FA">
<!-- 搜素区域 -->
<div>
<el-row :gutter="24">
<el-col :span="5">
<el-input v-model="queryInfo.flightNo" prefix-icon="el-icon-search"
placeholder="请输入航班号" clearable style="width:220px">
</el-input>
</el-col>
<el-col :span="5">
<el-date-picker v-model="queryInfo.flightDate" type="date" value-format="yyyy-MM-dd"
placeholder="请选择航班日期"
style="width: 220px">
</el-date-picker>
</el-col>
<el-col :span="10">
<el-button type="primary" @click="getExitInfoList" style="width: 160px;"
icon="el-icon-search">
数据统计查询
</el-button>
<el-button :loading="downloadLoading" type="success" icon="el-icon-s-home"
style="width: 160px;"
:disabled="socketResponse.socketStatus!=='200'"
@click="downLoadExcel">导出 Excel
</el-button>
</el-col>
</el-row>
<!-- 显示区域 -->
<el-row :gutter="24" style="margin-top: 30px">
<el-col :span="11" style="margin-top: 10px">
<!-- <el-progress :text-inside="true" :stroke-width="15" :percentage="proportion"-->
<!-- :color="customColors"-->
<!-- style="width: 455px"></el-progress>-->
<el-input v-model="message" type="textarea"
:autosize="{ minRows: 6, maxRows: 10}"
style="width: 455px;height: 400px"
placeholder="获取数据进度" readonly>
</el-input>
</el-col>
<el-col :span="4" style="margin-left: 40px;margin-top: 20px">
<el-progress type="circle" :percentage="proportion"
:stroke-width="12"
:color="customColors"
:width="proportion>6?200:126">
</el-progress>
</el-col>
</el-row>
</div>
</el-card>
</el-main>
</el-container>
</template>
<script>
import {getArrivalDataAnalysis, createArrivalExcel, downArrivalExcel} from "../../api/arrival_data_analysis";
import ArrivalWebsocket from '@/utils/arrival_web_socket';
export default {
name: "ExitAnalysis",
data() {
return {
/**
* 出港业务统计列表
*/
exitInfoList: [],
resultStatus: '0',
message: '',
/**
* 返回结果
*/
socketResponse: {
socketMessage: '',
socketStatus: '',
socketDataList: [],
socketCurrentNum: 1,
socketTotalNum: 1,
},
/**
* 查询列表
*/
queryInfo: {
//航班号
flightNo: 'CV4481',
//航班日期
flightDate: '2019-06-11',
},
/* 列表加载 */
listLoading: false,
downloadLoading: false,
/**
* 百分比例
*/
proportion: 0,
/**
* 百分比例,颜色
*/
customColors: [
{color: '#6f7ad3', percentage: 20},
{color: '#f56c6c', percentage: 40},
{color: '#e6a23c', percentage: 60},
{color: '#5cb87a', percentage: 80},
{color: '#1989fa', percentage: 100},
],
/**
* 下载路径的参数
*/
fileName: "test.xls",
ipAddress: "",
url: "",
}
},
methods: {
/**
* 获取出港信息列表
*/
getExitInfoList() {
let _this = this;
if (_this.queryInfo.flightNo === '') {
if (_this.queryInfo.flightDate === '' || _this.queryInfo.flightDate === null) {
return _this.$message.warning('航班号与航班日期,不能同时为空');
}
}
_this.$message.success('开始获取统计数据');
getArrivalDataAnalysis(_this.queryInfo).catch(error => {
// _this.$message.info("即将结束!请您稍候");
});
},
/**
* 下载excel
*/
downLoadExcel() {
downArrivalExcel().then((response) => {
this.downloadLoading = true;
let res = response.data;
if (res.code !== '200') {
return this.$message.error('下载失败');
this.downloadLoading = false;
}
// console.log(res.msg)
//获取地址
this.ipAddress = res.msg;
this.url = this.ipAddress + this.fileName;
console.log(this.url)
// console.log(this.ipAddress)
this.down();
this.downloadLoading = false;
}).catch(error => {
this.downloadLoading = false;
console.log(error.toString())
this.$message.error(error.toString());
});
},
down() {
// 创建a标签
const link = document.createElement('a');
// download属性
link.setAttribute('download', 'excel.xls');
// href链接
link.setAttribute('href', this.url);
document.body.appendChild(link);
// 自执行点击事件
link.click()
},
/**
* 生成excel
*/
generateExcel() {
createArrivalExcel(this.socketResponse.socketDataList).then((response) => {
let res = response.data;
if (res.code !== '200') {
return this.$message.error('生成excel失败');
}
this.fileName = res.msg;
console.log(this.fileName)
this.$message.success("Excel准备就绪")
}).catch(error => {
this.$message.error(error.toString());
});
},
socket_onmessage: function (e) {
console.log("从websocket接收到新的消息-->>" + e.data);
//this.message = this.message + e.data + "\n";
let msgJson = JSON.parse(e.data);
this.message = this.message + this.dataFormat(new Date()) + " -> " + msgJson.message + "\n";
this.socketResponse = JSON.parse(e.data);
this.socketResponse.socketMessage = msgJson.message;
this.socketResponse.socketCurrentNum = msgJson.currentNum;
this.socketResponse.socketTotalNum = msgJson.totalNum;
console.log(this.socketMessage);
this.socketResponse.socketStatus = msgJson.status;
this.socketResponse.socketDataList = msgJson.data;
console.log(msgJson);
if (this.socketResponse.socketTotalNum !== null && this.socketResponse.socketTotalNum !== 0) {
this.proportion = this.toPercent(this.socketResponse.socketCurrentNum / this.socketResponse.socketTotalNum);
}
if (this.socketResponse.socketCurrentNum === this.socketResponse.socketTotalNum &&
this.socketResponse.socketTotalNum !== 0 && this.socketResponse.socketCurrentNum !== 0) {
this.generateExcel();
}
},
socket_onopen: function (e) {
console.log("websocket->>链接已链接");
},
/**
* 重写日期函数格式化日期
*/
dataFormat(time) {
return `${time.getFullYear()}-${time.getMonth() + 1 >= 10 ? (time.getMonth() + 1) : '0' + (time.getMonth() + 1)}-${time.getDate() >= 10 ? time.getDate() : '0' + time.getDate()} ${time.getHours() >= 10 ? time.getHours() : '0' + time.getHours()}:${time.getMinutes() >= 10 ? time.getMinutes() : '0' + time.getMinutes()}:${time.getSeconds() >= 10 ? time.getSeconds() : '0' + time.getSeconds()}`;
},
/**
* 将小数转换成百分比
* @param point
* @returns {string|number}
*/
toPercent(point) {
if (point == 0) {
return 0;
}
let str = Number(point * 100).toFixed();
// str+="%";
return parseInt(str);
}
},
created() {
ArrivalWebsocket.onopen = this.socket_onopen;
ArrivalWebsocket.onmessage = this.socket_onmessage;
ArrivalWebsocket.init();
},
destroyed() {
},
watch: {},
}
</script>
<style scoped>
</style>