| | |
| | | <el-table-column label="操作" width="180" align="center" fixed="right"> |
| | | <template slot-scope="scope"> |
| | | <el-button type="text" size="small" @click="showDetail(scope.row)">详情</el-button> |
| | | <el-button type="text" size="small" v-if="scope.row.status === 2 && !scope.row.apkPath" |
| | | <el-button type="text" size="small" v-if="scope.row.status === 2 && scope.row.apkPath" |
| | | @click="downloadApk(scope.row)" :loading="scope.row.downloading">下载</el-button> |
| | | <el-button type="text" size="small" style="color: #67c23a;" |
| | | v-if="scope.row.status === 2 && scope.row.apkPath" |
| | |
| | | downloadApk(row) { |
| | | this.$set(row, 'downloading', true); |
| | | $.ajax({ |
| | | url: baseUrl + '/apkBuildTask/download/' + row.id + '/auth', |
| | | url: baseUrl + '/apkBuildTask/downloadFile/' + row.id + '/auth', |
| | | headers: this.getHeaders(), |
| | | method: 'POST', |
| | | success: (res) => { |
| | | method: 'GET', |
| | | xhrFields: { responseType: 'blob' }, |
| | | success: (data, status, xhr) => { |
| | | this.$set(row, 'downloading', false); |
| | | if (res.code === 200) { |
| | | this.$message.success('APK下载完成: ' + res.data.apkPath); |
| | | this.loadData(); |
| | | } else { |
| | | this.$message.error(res.msg || '下载失败'); |
| | | const contentType = xhr.getResponseHeader('Content-Type') || ''; |
| | | if (contentType.indexOf('application/json') !== -1) { |
| | | const reader = new FileReader(); |
| | | reader.onload = () => { |
| | | try { |
| | | const res = JSON.parse(reader.result); |
| | | this.$message.error(res.msg || '下载失败'); |
| | | } catch (e) { |
| | | this.$message.error('下载失败'); |
| | | } |
| | | }; |
| | | reader.readAsText(data); |
| | | return; |
| | | } |
| | | const disposition = xhr.getResponseHeader('Content-Disposition') || ''; |
| | | const fileNameMatch = disposition.match(/filename="?([^"]+)"?/); |
| | | let fileName = fileNameMatch ? decodeURIComponent(fileNameMatch[1]) : ''; |
| | | if (!fileName) { |
| | | fileName = (row.projectName ? row.projectName : row.id) + '.apk'; |
| | | } |
| | | const blob = new Blob([data], { type: contentType || 'application/octet-stream' }); |
| | | const link = document.createElement('a'); |
| | | link.href = URL.createObjectURL(blob); |
| | | link.download = fileName; |
| | | document.body.appendChild(link); |
| | | link.click(); |
| | | document.body.removeChild(link); |
| | | URL.revokeObjectURL(link.href); |
| | | this.$message.success('APK已开始下载'); |
| | | }, |
| | | error: () => { |
| | | error: (xhr) => { |
| | | this.$set(row, 'downloading', false); |
| | | this.$message.error('请求失败'); |
| | | if (xhr && xhr.response) { |
| | | const reader = new FileReader(); |
| | | reader.onload = () => { |
| | | try { |
| | | const res = JSON.parse(reader.result); |
| | | this.$message.error(res.msg || '下载失败'); |
| | | } catch (e) { |
| | | this.$message.error('请求失败'); |
| | | } |
| | | }; |
| | | reader.readAsText(xhr.response); |
| | | } else { |
| | | this.$message.error('请求失败'); |
| | | } |
| | | } |
| | | }); |
| | | }, |