提交角色界面修改
This commit is contained in:
1 parent
d45af45132
commit
2b5db607f6
8 files changed
+325
-31
No files matched your search
+40
-14
@@ -4,27 +4,27 @@ import errorCode from '@/utils/errorCode';
|
||||
import { blobValidate } from '@/utils/ruoyi';
|
||||
import { LoadingInstance } from 'element-plus/es/components/loading/src/loading.mjs';
|
||||
import { globalHeaders } from '@/utils/request';
|
||||
import { getFileDownloadUrl } from '@/api/system/file';
|
||||
|
||||
const baseURL = import.meta.env.VITE_APP_BASE_API;
|
||||
let downloadLoadingInstance: LoadingInstance;
|
||||
export default {
|
||||
async oss(ossId: string | number) {
|
||||
const url = baseURL + '/resource/oss/download/' + ossId;
|
||||
downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
|
||||
downloadLoadingInstance = ElLoading.service({ text: '正在获取文件访问链接,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
|
||||
try {
|
||||
const res = await axios({
|
||||
method: 'get',
|
||||
url: url,
|
||||
responseType: 'blob',
|
||||
headers: globalHeaders()
|
||||
});
|
||||
const isBlob = blobValidate(res.data);
|
||||
if (isBlob) {
|
||||
const blob = new Blob([res.data], { type: 'application/octet-stream' });
|
||||
FileSaver.saveAs(blob, decodeURIComponent(res.headers['download-filename'] as string));
|
||||
} else {
|
||||
this.printErrMsg(res.data);
|
||||
// 使用新的安全下载方法
|
||||
const { data: downloadUrl } = await getFileDownloadUrl(Number(ossId));
|
||||
|
||||
// 使用fetch下载文件
|
||||
const response = await fetch(downloadUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error('下载失败');
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const filename = response.headers.get('content-disposition')?.split('filename=')[1]?.replace(/"/g, '') || `file_${ossId}`;
|
||||
|
||||
FileSaver.saveAs(blob, decodeURIComponent(filename));
|
||||
downloadLoadingInstance.close();
|
||||
} catch (r) {
|
||||
console.error(r);
|
||||
@@ -32,6 +32,32 @@ export default {
|
||||
downloadLoadingInstance.close();
|
||||
}
|
||||
},
|
||||
|
||||
// 新增:安全下载文件方法
|
||||
async secureOss(ossId: string | number, fileName?: string) {
|
||||
downloadLoadingInstance = ElLoading.service({ text: '正在获取文件访问链接,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
|
||||
try {
|
||||
// 获取临时下载URL
|
||||
const { data: downloadUrl } = await getFileDownloadUrl(Number(ossId));
|
||||
|
||||
// 使用fetch下载文件
|
||||
const response = await fetch(downloadUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error('下载失败');
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const finalFileName = fileName || response.headers.get('content-disposition')?.split('filename=')[1]?.replace(/"/g, '') || `file_${ossId}`;
|
||||
|
||||
FileSaver.saveAs(blob, decodeURIComponent(finalFileName));
|
||||
downloadLoadingInstance.close();
|
||||
} catch (r) {
|
||||
console.error(r);
|
||||
ElMessage.error('下载文件出现错误,请联系管理员!');
|
||||
downloadLoadingInstance.close();
|
||||
}
|
||||
},
|
||||
|
||||
async zip(url: string, name: string) {
|
||||
url = baseURL + url;
|
||||
downloadLoadingInstance = ElLoading.service({ text: '正在下载数据,请稍候', background: 'rgba(0, 0, 0, 0.7)' });
|
||||
|
||||
Reference in new issue
Block a user