update:文件下载接口修改,相关界面的统一适配修改

This commit is contained in:
2025-12-22 15:59:03 +08:00
parent 9af3e61651
commit e8bd34bc21
8 changed files with 91 additions and 44 deletions

View File

@@ -1,8 +1,8 @@
import { downloadFileById } from '@/utils/file';
import { get } from './index';
import { ElNotification, ElButton } from 'element-plus';
import { h } from 'vue';
const env = import.meta.env;
// 获取电脑机器码
export const getdeviceuuidApi = async () => {
@@ -17,8 +17,9 @@ export const execApi = async (params: any) => {
};
const openDownLoadFun = () => {
const downloadUrl = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${3190}`;
window.open(downloadUrl, '_blank');
// const downloadUrl = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${3190}`;
// window.open(downloadUrl, '_blank');
downloadFileById(3190);
};
const startFun = () => {

View File

@@ -1,4 +1,4 @@
import { download, get, post, upload } from '@/api/request';
import { download, get, getDownload, post, upload } from '@/api/request';
const env = import.meta.env;
const PREFIX = env.VITE_API_PREFIX_DATA;
@@ -198,3 +198,12 @@ export const downloadFileForEditApi = (params: any) => {
export const dataTreeListDirApi = (params: any) => {
return get(`${PREFIX}data/listDir?`, params);
};
/**
* 系统文件下载
* @param params
* @returns
*/
export const systemDataDownloadFileApi = (params: any) => {
return getDownload(`${PREFIX}data/downloadFile?fileId=${params.fileId}`);
};

View File

@@ -156,4 +156,31 @@ const download = (url: string, params = {}, filename = 'download') => {
});
};
export { get, post, upload, download };
const getDownload = (url: string, filename = 'download') => {
return service
.get(url, {
responseType: 'blob',
})
.then(async (res: any) => {
const xFileName = res.headers?.['x-file-name'];
let fileName = filename;
if (xFileName) {
fileName = xFileName;
}
const blob = new Blob([res.data]);
const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(link.href);
})
.catch(() => {
ElMessage.warning('下载失败');
});
};
export { get, post, upload, download, getDownload };

View File

@@ -28,7 +28,7 @@ const props = withDefaults(
idIndex?: any;
readonly?: boolean;
autoFormat?: boolean;
fileId: string,
fileId: string;
}>(),
{
readonly: false,
@@ -52,23 +52,26 @@ const isChange = ref<boolean>(false);
const initEditor = () => {
// 初始化编辑器确保dom已经渲染
editor.value = monaco.editor.create(document.getElementById('codeEditBox' + props.idIndex) as any, {
value: '', // 编辑器初始显示文字
// 语言支持自行查阅demo
language: '',
theme: 'vs-dark', // 官方自带三种主题vs, hc-black, or vs-dark
selectOnLineNumbers: true, // 显示行号
roundedSelection: false,
cursorStyle: 'line', // 光标样式
automaticLayout: true, // 自动布局
glyphMargin: true, // 字形边缘
useTabStops: false,
fontSize: 14, // 字体大小
quickSuggestionsDelay: 100, // 代码提示延时
autoIndent: 'full', // 自动布局
});
editor.value = monaco.editor.create(
document.getElementById('codeEditBox' + props.idIndex) as any,
{
value: '', // 编辑器初始显示文字
// 语言支持自行查阅demo
language: '',
theme: 'vs-dark', // 官方自带三种主题vs, hc-black, or vs-dark
selectOnLineNumbers: true, // 显示行号
roundedSelection: false,
cursorStyle: 'line', // 光标样式
automaticLayout: true, // 自动布局
glyphMargin: true, // 字形边缘
useTabStops: false,
fontSize: 14, // 字体大小
quickSuggestionsDelay: 100, // 代码提示延时
autoIndent: 'full', // 自动布局
}
);
// // 监听值的变化
editor.value.onDidChangeModelContent((event:any) => {
editor.value.onDidChangeModelContent((event: any) => {
console.log('123', 1234, event);
// editor.value.getAction('editor.action.formatDocument').run();
// 拿到变化后的值
@@ -87,7 +90,7 @@ const saveFile = async () => {
form.append('scriptFileId ', props.fileId);
form.append('fileName ', fileTitle.value);
form.append('updateFile ', new Blob([currentValue], { type: 'text/txt' }));
const res:any = await upload(`${PREFIX}data/updateScriptFile`, form);
const res: any = await upload(`${PREFIX}data/updateScriptFile`, form);
// const res = await fragmentUpload(
// false,
@@ -118,13 +121,12 @@ const fileTitle = ref<string>('');
// toRaw(editor.value).setValue(text.value);
// };
const getFile = async () => {
loading.value = true;
const baseRes:any = await getFileBaseInfoApi({ fileId: props.fileId });
const baseRes: any = await getFileBaseInfoApi({ fileId: props.fileId });
if (baseRes.code === 200) {
fileTitle.value = baseRes.data.originalName;
}
const res:any = await dataDownloadFileApi({ fileId: props.fileId });
const res: any = await dataDownloadFileApi({ fileId: props.fileId });
if (res) {
// 设置语言
// let fileSuffix = '';
@@ -141,7 +143,7 @@ const getFile = async () => {
// 填入内容时设置只读为false
toRaw(editor.value).updateOptions({ readonly: true });
// 设置内容
text.value = res as string;
text.value = JSON.stringify(res) as string;
toRaw(editor.value).setValue(text.value);
// 设置光标位置为第一行第一列
toRaw(editor.value).setPosition({ lineNumber: 1, column: 1 });
@@ -193,5 +195,4 @@ defineExpose({
});
</script>
<style lang="scss" scoped src="./index.scss">
</style>
<style lang="scss" scoped src="./index.scss"></style>

View File

@@ -45,7 +45,7 @@
import { ref, onMounted } from 'vue';
import BaseTable from '@/components/common/table/baseTable.vue';
import { getSimulationTaskFilesApi } from '@/api/data/data';
import { formatFileSize } from '@/utils/file';
import { downloadFileById, formatFileSize } from '@/utils/file';
import UploadFile from '@/components/common/uploadFile/index.vue';
import FilePreview from '@/components/common/filePreview/index.vue';
@@ -92,8 +92,10 @@ const actionList = ref([
title: '下载',
type: 'primary',
click: (row: any) => {
const downloadUrl = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${row.id}`;
window.open(downloadUrl, '_blank');
// const downloadUrl = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${row.id}`;
// window.open(downloadUrl, '_blank');
downloadFileById(row.id);
},
},
{

View File

@@ -43,7 +43,7 @@
import { ref, onMounted } from 'vue';
import BaseTable from '@/components/common/table/baseTable.vue';
import { getSimulationTaskFilesApi } from '@/api/data/data';
import { formatFileSize } from '@/utils/file';
import { downloadFileById, formatFileSize } from '@/utils/file';
import UploadFile from '@/components/common/uploadFile/index.vue';
import FilePreview from '@/components/common/filePreview/index.vue';
@@ -92,8 +92,11 @@ const actionList = ref([
title: '下载',
type: 'primary',
click: (row: any) => {
const downloadUrl = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${row.id}`;
window.open(downloadUrl, '_blank');
// const downloadUrl = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${row.id}`;
// window.open(downloadUrl, '_blank');
downloadFileById(row.id);
},
},
{

View File

@@ -1,4 +1,4 @@
import { getKKFileViewURLFromMinioApi } from '@/api/data/data';
import { getKKFileViewURLFromMinioApi, systemDataDownloadFileApi } from '@/api/data/data';
import { getFormConfigureApi } from '@/api/system/systemData';
import { ElMessage } from 'element-plus';
import * as XLSX from 'xlsx';
@@ -215,10 +215,12 @@ export const exportFile = (
* 根据文件id下载文件
* @param fileId
*/
export const downloadFileById = (fileId: number) => {
const link = document.createElement('a');
link.href = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${fileId}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
export const downloadFileById = async (fileId: number) => {
// const link = document.createElement('a');
// link.href = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${fileId}`;
// document.body.appendChild(link);
// link.click();
// document.body.removeChild(link);
await systemDataDownloadFileApi({ fileId });
};

View File

@@ -111,8 +111,10 @@ const queryRunDirFun = async (param: any) => {
const downLoadFileFun = async () => {
const ckeckData = baseTableRef.value.tableRef.getCheckboxRecords();
for (let i = 0; i < ckeckData.length; i++) {
const downloadUrl = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${ckeckData[i].id}`;
window.open(downloadUrl, '_blank');
// const downloadUrl = `${env.VITE_API_FILE_URL}/data/downloadFile?fileId=${ckeckData[i].id}`;
// window.open(downloadUrl, '_blank');
downloadFileById(ckeckData[i].id);
}
};