Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#1394 from luofann/fix_test_0910
Browse files Browse the repository at this point in the history
fix: 测试问题处理
  • Loading branch information
luofann authored Sep 10, 2024
2 parents 4e64978 + 0b2c28f commit efe6974
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
11 changes: 11 additions & 0 deletions frontend/pc/src/store/modules/apiRemote.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import ajax from "../../utils/ajax";
import { fileDownload } from "../../utils/util";

export default {
namespaced: true,
Expand Down Expand Up @@ -124,6 +125,16 @@ export default {
return res;
});
},
export_api({}, id) {
return ajax.get(`postman/remote_api/${id}/exports/`, {
transitional: {
forcedJSONParsing: false,
},
responseType: 'blob'
}).then((response) => {
fileDownload(response);
})
},
// http://dev.paas-poc.o.qcloud.com:8000/api/postman/remote_api/1/run_api/
run_remote_api({ commit, state, dispatch }, params) {
return ajax.post(`postman/remote_api/${params.id}/run_api/`, params).then((response) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/pc/src/utils/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ instance.interceptors.response.use(
};
}

if (response.request.responseURL.includes('/api/plugin_service/')) {
if (response.request.responseURL.includes('/api/plugin_service/') || response.headers['content-type'] === 'application/octet-stream; charset=utf-8') {
return response;
}

Expand Down
31 changes: 31 additions & 0 deletions frontend/pc/src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,34 @@ export function transCustomFormToTable (formStr) {

return tables;
}


export function fileDownload (res) {
let filename
const disposition = res.headers['content-disposition'].split(',')
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/
const matches = filenameRegex.exec(disposition)
if (matches !== null && matches[1]) {
filename = decodeURIComponent(matches[1].replace(/(^utf-8)|['"]/g, ''))
}
const blob = new Blob([res.data], { type: 'text/plain;charset=UTF-8' })
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// hack old IE
window.navigator.msSaveBlob(blob, filename)
} else {
const eleLink = document.createElement('a')
const blobURL = window.URL.createObjectURL(blob)
eleLink.style.display = 'none'
eleLink.href = blobURL
eleLink.setAttribute('download', filename)

// hack HTML5 download attribute
if (typeof eleLink.download === 'undefined') {
eleLink.setAttribute('target', '_blank')
}
document.body.appendChild(eleLink)
eleLink.click()
document.body.removeChild(eleLink)
window.URL.revokeObjectURL(blobURL)
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
}
},
exportFlow(item) {
window.open(`${window.SITE_URL}api/postman/remote_api/${item.id}/exports/`);
this.$store.dispatch('apiRemote/export_api', item.id);
},
async handleBeforeClose() {
if (this.isFormChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@
if (isDraft) {
return;
}
if (this.step === 2) {
this.$parent.backTab();
return;
}
// if (this.step === 2) {
// this.$parent.backTab();
// return;
// }
const stepIndex = type === 'previous' ? this.step - 1 : this.step + 1;
const temp = {
id: stepIndex + 1,
Expand Down
1 change: 1 addition & 0 deletions frontend/pc/src/views/ticket/ticketListMixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ const ticketListMixins = {
handleSearch(params) {
this.lastSearchParams = params;
this.searchToggle = true;
this.pagination.current = 1;
this.getTicketList();
},
deteleSearchResult(type, index) {
Expand Down

0 comments on commit efe6974

Please sign in to comment.