大屏以及质量管理
This commit is contained in:
@ -1,14 +1,19 @@
|
||||
import $cache from '@/plugins/cache';
|
||||
// src/utils/request-go.ts
|
||||
import request from '@/utils/request';
|
||||
|
||||
const BASE_GO_URL = import.meta.env.VITE_APP_BASE_API_GO;
|
||||
|
||||
/**
|
||||
* 包装 request 请求,统一使用 Go 服务地址作为 baseURL
|
||||
* @param config 原始请求配置
|
||||
*/
|
||||
export default function requestGo(config: any) {
|
||||
|
||||
const BASE_GO_URL = import.meta.env.VITE_APP_BASE_API_GO;
|
||||
|
||||
interface RequestGo extends Function {
|
||||
(config: any): Promise<any>;
|
||||
download?: (url: string, params: any, filename: string) => void;
|
||||
}
|
||||
|
||||
const requestGo: RequestGo = (config: any) => {
|
||||
return request({
|
||||
baseURL: BASE_GO_URL,
|
||||
...config,
|
||||
@ -16,4 +21,30 @@ export default function requestGo(config: any) {
|
||||
'Authorization': `Bearer ${$cache.local.get('goToken') || ''}`
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
requestGo.download = function (url: string, params: any, filename: string) {
|
||||
return request({
|
||||
url,
|
||||
method: 'post',
|
||||
baseURL: BASE_GO_URL,
|
||||
data: params,
|
||||
headers: {
|
||||
'Authorization': `Bearer ${$cache.local.get('goToken') || ''}`
|
||||
},
|
||||
responseType: 'blob'
|
||||
}).then((response) => {
|
||||
// ✅ 只取 response.data
|
||||
const blob = new Blob([response.data]);
|
||||
const link = document.createElement('a');
|
||||
link.style.display = 'none';
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.setAttribute('download', filename);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(link.href);
|
||||
});
|
||||
};
|
||||
|
||||
export default requestGo;
|
||||
|
Reference in New Issue
Block a user