HistorySearchTable.vue
6.68 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
<template>
<div class="history-table-wrap">
<el-table
v-if="tableData.length > 0"
ref="singleTable"
:data="tableData"
:header-cell-style="{ textAlign: 'center' ,height:'100%',lineHeight:'100%' }"
border
:height="tableHeightNum"
highlight-current-row
@current-change="handleCurrentChange"
style="width: 100%;text-align: center">
<el-table-column
type="index"
fixed
align="center"
width="100"
label="序号">
</el-table-column>
<el-table-column
property="name"
align="center"
label="名称">
</el-table-column>
<el-table-column
property="deviceId"
align="center"
label="设备">
</el-table-column>
<el-table-column
property="channelName"
align="center"
label="通道名称">
</el-table-column>
<el-table-column
align="center"
label="日期">
<template slot-scope="scope">
{{`${scope.row.startTime}-${scope.row.endTime}`}}
</template>
</el-table-column>
<el-table-column
property="status"
align="center"
label="状态">
<template slot-scope="scope">
<span v-if="scope.row.status===null ||scope.row.status === '0'"><el-tag>未上传</el-tag></span>
<span v-if="scope.row.status==='2'"><el-tag type="info">上传中</el-tag></span>
<span v-if="scope.row.status==='3'"><el-tag type="success">已上传</el-tag></span>
</template>
</el-table-column>
<el-table-column
fixed="right"
align="center"
label="操作">
<template slot-scope="scope">
<el-button icon="el-icon-video-play" size="small" style="border: none" @click="playHistoryVideo(scope.row)"></el-button>
<el-tooltip :disabled="!isChannelBusy(scope.row)" content="该通道正在上传或下载" placement="top">
<span>
<el-button
v-if="scope.row.status === '0'"
icon="el-icon-upload"
size="small"
style="border: none"
:disabled="isChannelBusy(scope.row)"
@click="uploadHistoryVideo(scope.row)"
/>
</span>
</el-tooltip>
<el-tooltip :disabled="!isChannelBusy(scope.row)" content="该通道正在上传或下载" placement="top">
<span>
<el-button
v-if="scope.row.status === '3'"
icon="el-icon-download"
:disabled="scope.row.disabled || isChannelBusy(scope.row)"
size="small"
style="border: none"
@click="downloadHistoryVideo(scope.row)">
{{ scope.row.disabled ? `${scope.row.countdown}s` : '' }}
</el-button>
</span>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<el-empty v-else style="width: 100%;height: 100%"></el-empty>
</div>
</template>
<script>
export default {
name: "historySearchTable",
components: {},
props: {
tableData: {
type: Array,
default: () => []
},
/** 像素高度;el-table 需要数值高度才能出现纵向滚动条 */
tableHeight: {
type: Number,
default: 400
},
busyChannelKeys: {
type: Array,
default: () => []
}
},
computed: {
tableHeightNum() {
const h = Number(this.tableHeight)
return h > 120 ? h : 400
}
},
data() {
return {
currentRow: null,
historyTimer: null,
countdown: 10,
disabled: false
};
},
methods: {
channelKey(row) {
if (!row || row.sim == null || row.channel == null) return ''
return String(row.sim) + '_' + String(row.channel)
},
isChannelBusy(row) {
const k = this.channelKey(row)
if (!k) return false
return this.busyChannelKeys.indexOf(k) >= 0
},
handleCurrentChange(val) {
this.currentRow = val;
},
setCurrent(row) {
this.$refs.singleTable.setCurrentRow(row);
},
playHistoryVideo(row){
this.$emit("playHistoryVideo", row);
},
uploadHistoryVideo(row){
if (this.isChannelBusy(row)) {
this.$message.warning('该通道正在上传或下载,请稍候')
return
}
this.$emit('uploadHistoryVideo', row);
},
downloadHistoryVideo(data){
if (data.disabled) return;
if (this.isChannelBusy(data)) {
this.$message.warning('该通道正在上传或下载,请稍候')
return
}
if (data.historyTimer){
this.$message.warning("点击太频繁,请稍后重试")
return;
}
const opKey = this.channelKey(data)
this.$emit('channel-operation', { key: opKey, busy: true })
data.disabled = true;
data.countdown = 10;
data.isCountingDown = true;
const timer = setInterval(() => {
if (data.countdown > 0) {
data.countdown--;
} else {
clearInterval(timer);
data.disabled = false;
data.countdown = 10;
data.isCountingDown = false;
}
}, 1000);
data.historyTimer = timer;
this.$axios({
url: `/api/jt1078/query/history/download/${data.name}`,
method: 'GET',
responseType: 'blob',
}).then((response) => {
const blob = new Blob([response.data], { type: 'application/octet-stream' });
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = data.name + ".mp4";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
clearInterval(timer);
data.disabled = false;
data.countdown = 10;
data.isCountingDown = false;
data.historyTimer = null;
this.$message.success(`${link.download} 下载成功`);
}).catch(error => {
clearInterval(timer);
data.disabled = false;
data.countdown = 10;
data.isCountingDown = false;
data.historyTimer = null;
this.$message.error(`${data.name} 下载失败`);
console.error("下载失败", error);
}).finally(() => {
this.$emit('channel-operation', { key: opKey, busy: false })
});
}
},
beforeDestroy() {
clearInterval(this.historyTimer)
},
};
</script>
<style scoped>
.history-table-wrap {
width: 100%;
height: 100%;
min-height: 0;
}
</style>