diff --git a/.env.development b/.env.development index d4f9f1a..4adb53e 100644 --- a/.env.development +++ b/.env.development @@ -10,9 +10,10 @@ VITE_PUBLIC_PATH = / # 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题 # 可以有多个,注意多个不能换行,否则代理将会失效 #VITE_PROXY = [["/api","http://localhost:3000"],["/upload","http://localhost:3300/upload"]] -VITE_PROXY=[["/api","http://10.10.2.102:9500"]] +#VITE_PROXY=[["/api","http://10.10.2.102:9500"]] #VITE_PROXY=[["/api/system/generator/","http://127.0.0.1:8091/system/generator/"],["/api/system/file/","http://127.0.0.1:8091/system/file/"],["/api/system/oss/","http://127.0.0.1:8091/system/oss/"],["/api/sales/","http://127.0.0.1:8096","/sales/"],["/api/mdm/","http://127.0.0.1:8096","/mdm/"],["/api","http://10.10.2.102:9500"]] #VITE_PROXY=[["/api/sales/","http://127.0.0.1:8096","/sales/"],["/api/mdm/","http://127.0.0.1:8096","/mdm/"],["/api","http://10.10.2.102:9500"]] +VITE_PROXY=[["/api/system/file/","http://127.0.0.1:8091/system/file/"],["/api","http://10.10.2.102:9500"]] # 是否删除Console.log VITE_DROP_CONSOLE = false @@ -29,10 +30,10 @@ VITE_GLOB_API_URL=/api VITE_GLOB_REPORT_URL=http://localhost:8090/api # 文件上传接口 可选 -VITE_GLOB_UPLOAD_URL = /system/oss/upload +VITE_GLOB_UPLOAD_URL = /system/file/upload # 文件预览接口 可选 -VITE_GLOB_UPLOAD_PREVIEW = http://10.10.2.101:8012/onlinePreview?url= +VITE_GLOB_UPLOAD_PREVIEW = http://10.10.2.101:8012/preview/onlinePreview?url= #外部url地址 VITE_GLOB_OUT_LINK_URL = ['http://localhost:4100'] diff --git a/src/api/sys/upload.ts b/src/api/sys/upload.ts index 0a5bd6f..b3da2d2 100644 --- a/src/api/sys/upload.ts +++ b/src/api/sys/upload.ts @@ -19,16 +19,16 @@ export function uploadApi(params: UploadFileParams) { /** * @description: Upload interface */ -export function uploadMultiApi(params: UploadFileParams, folderid) { +export function uploadMultiApi(params: UploadFileParams,tableId:any,tableName?:any,columnName?:any) { return defHttp.uploadFile( { - url: '/system/oss/multi-upload?folderId=' + folderid, + url: '/system/file/multi-upload?tableName=' + tableName + '&columnName=' + columnName + '&tableId=' + tableId, }, params, ); } -export const uploadSrc = '/system/oss/upload'; +export const uploadSrc = '/system/file/upload'; // 上传二进制文件生成图片 export async function uploadBlobApi(blob, filename) { diff --git a/src/api/system/file/index.ts b/src/api/system/file/index.ts index f172df7..0be3d8c 100644 --- a/src/api/system/file/index.ts +++ b/src/api/system/file/index.ts @@ -2,28 +2,38 @@ import { defHttp } from '/@/utils/http/axios'; import { ErrorMessageMode } from '/#/axios'; import { FilePageListParams, FilePageListSearchModel, FilePageListResultModel, ZipFilesModel, FileModel } from './model'; + +import { useGlobSetting } from '/@/hooks/setting'; +const globSetting = useGlobSetting(); + +const urlPrefix = globSetting.apiUrl; + enum Api { File = '/system/file', Info = '/system/file/info', - InfoByDownloadUrl = '/system/file/info-byDownloadUrl', - List = '/system/file', + List = '/system/file/list', Page = '/system/file/page', - DeleteFile = '/system/file/delete-single', + DeleteFile = '/system/file/delete', ZipFiles = '/system/file/package-files', } -export async function getInfoByDownloadUrl(params: {id: string}, mode: ErrorMessageMode = 'modal') { - return defHttp.get( - { - url: Api.InfoByDownloadUrl, - params, - }, - { - errorMessageMode: mode, - }, - ); +export function parseDownloadUrl(url:string,th?:boolean,full?:boolean) { + // 空值防护:如果url为空,直接返回空字符串(避免拼接出错) + if (!url) return ''; + + // 判断url是否以/api开头(忽略首尾空格,兼容可能的空格场景) + const trimmedUrl = url.trim(); + if(urlPrefix!=undefined && trimmedUrl.startsWith(urlPrefix)){ + return trimmedUrl + (th ? '&th=true' : ''); + } + let resultUrl = urlPrefix + trimmedUrl + (th ? '&th=true' : ''); + if(full){ + return location.origin + resultUrl; + } + return resultUrl; } + /** * @description: 查询文件分页 */ @@ -48,7 +58,7 @@ export async function getFilePage( export async function deleteFile(ids: string[], mode: ErrorMessageMode = 'modal') { return defHttp.delete( { - url: Api.File, + url: Api.DeleteFile, data: ids, }, { @@ -61,15 +71,15 @@ export async function deleteFile(ids: string[], mode: ErrorMessageMode = 'modal' * @description: 删除单个文件 */ export async function deleteSingleFile(id: string, mode: ErrorMessageMode = 'modal') { - return defHttp.delete( - { - url: Api.DeleteFile, - data: id, - }, - { + return defHttp.delete( + { + url: Api.DeleteFile, + data: [id], + }, + { errorMessageMode: mode, }, - ); + ); } /** diff --git a/src/api/system/file/model/index.ts b/src/api/system/file/model/index.ts index 5543ac4..5fd49f5 100644 --- a/src/api/system/file/model/index.ts +++ b/src/api/system/file/model/index.ts @@ -2,7 +2,9 @@ import { BasicPageParams, BasicFetchResult } from '/@/api/model/baseModel'; export interface FilePageListParams { fileName?: string; //文件名 - folderId?: string; //文件夹Id + tableName?: string; //表名称 + columnName?: string; //属性名 + tableId?: string; //表主键 processId?: string; //流程Id } @@ -11,14 +13,17 @@ export interface FilePageListParams { */ export interface FilePageListModel { id: number; - folderId: number; - fileName: string; + tableName: string; + columnName: string; + tableId: number; + + fileOrg: string; fileUrl: string; fileSize: number; - fileSuffiex: any; fileType: string; - downloadCount: number; - remark: string; + filePath: string; + downloadCnt: number; + docDesc: string; } /** @@ -26,15 +31,18 @@ export interface FilePageListModel { */ export interface FileModel { id: number; - folderId: number; - fileName: string; + tableName: string; + columnName: string; + tableId: number; + + fileOrg: string; fileUrl: string; fileSize: number; - fileSuffiex: any; fileType: string; - downloadCount: number; - remark: string; - fileUrlFixed: string; //加签后的url + filePath: string; + downloadCnt: number; + docDesc: string; + } /** diff --git a/src/components/Designer/src/components/componentProperty/PropertyOption.vue b/src/components/Designer/src/components/componentProperty/PropertyOption.vue index 82f3c3c..fe742a2 100644 --- a/src/components/Designer/src/components/componentProperty/PropertyOption.vue +++ b/src/components/Designer/src/components/componentProperty/PropertyOption.vue @@ -1326,25 +1326,25 @@ // console.log(t('上传超时')); // }; // xhr.send(formData); - let folderId = data.value.options.defaultValue; + let tableId = data.value.options.defaultValue; uploadMultiApi( { name: 'file', file: [file] }, - folderId + tableId ).then((res) => { - data.value.options.defaultValue = res[0].folderId; + data.value.options.defaultValue = res[0].tableId; getImage(); }); }; async function getImage() { if (data.value.options.defaultValue) { - let fileList = await getFileList({ folderId: data.value.options.defaultValue }); + let fileList = await getFileList({ tableId: data.value.options.defaultValue }); if (fileList.length) { imageUrl.value = fileList[0].fileUrl; - data.value.options.defaultValue = fileList[0].folderId; + data.value.options.defaultValue = fileList[0].tableId; } } else { imageUrl.value = ''; diff --git a/src/components/Form/src/components/ErpUpload.vue b/src/components/Form/src/components/ErpUpload.vue index 494a168..0c3667f 100644 --- a/src/components/Form/src/components/ErpUpload.vue +++ b/src/components/Form/src/components/ErpUpload.vue @@ -38,6 +38,8 @@ const props = defineProps({ value: String, + tableName: String, + columnName: String, maxNumber: Number, accpet: String, name: String, @@ -67,9 +69,24 @@ const fileList = ref([]); const list = ref([]); const { notification } = useMessage(); - const folderId = ref(''); + const tableId = ref(''); + const tableName = ref(''); + const columnName = ref(''); + + const bindValues = (data:any)=>{ + if(data){ + tableId.value = data.tableId; + tableName.value = data.tableName; + columnName.value = data.columnName; + }else{ + tableId.value = ''; + tableName.value = ''; + columnName.value = ''; + } + } + const deleteFlag = ref(false); - const emit = defineEmits(['update:value', 'change', 'click']); + const emit = defineEmits(['update:value', 'change', 'click', 'update:tableName', 'update:columnName']); const loading = ref(false); const previewVisible = ref(false); @@ -80,18 +97,19 @@ () => props.value, async (val) => { if (val) { - fileList.value = await getFileList({ folderId: props.value }); + fileList.value = await getFileList({ tableName: props.tableName, columnName: props.columnName,tableId: props.value }); if (fileList.value.length) { fileList.value.forEach((x) => { - x.name = x.fileName; + x.name = x.fileOrg; x.thumbUrl = x.fileUrl; x.status = 'done'; //没有则不会展示下载按钮 }); - folderId.value = fileList.value[0].folderId; + bindValues(fileList.value[0]); } } if (!val) { fileList.value = []; + bindValues(undefined); } }, { @@ -113,14 +131,16 @@ name: 'file', file: arr }, - folderId.value + tableId.value, tableName.value, columnName.value ); - folderId.value = res[0].folderId; + bindValues(res[0]); fileList.value.forEach((x) => { x.status = 'done'; //没有则不会展示下载按钮 x.thumbUrl = x.fileUrl; }); - emit('update:value', folderId.value); + emit('update:value', tableId.value); + emit('update:tableName', tableName.value); + emit('update:columnName', columnName.value); emit('change'); loading.value = false; } catch (error) { @@ -155,26 +175,21 @@ } const handleRemove = async (info) => { const id = info.response ? info.response.data.id : info.id; - - const newFolderId = await deleteSingleFile(id); - - folderId.value = newFolderId; - - deleteFlag.value = true; - - const index = fileList.value.findIndex((x) => x.id === id); - fileList.value.splice(index, 1); - - fileList.value.forEach((x) => { - x.folderId = newFolderId; - }); - - emit('update:value', folderId.value); - emit('change'); - notification.success({ - message: 'Tip', - description: '删除成功!' - }); + const status = await deleteSingleFile(id); + if (status) { + deleteFlag.value = true; + const index = fileList.value.findIndex((x) => x.id === id); + fileList.value.splice(index, 1); + notification.success({ + message: 'Tip', + description: '删除成功!' + }); + }else{ + notification.error({ + message: 'Tip', + description: '删除失败!' + }); + } }; const handleDownload = (info) => { diff --git a/src/components/Form/src/components/Image.vue b/src/components/Form/src/components/Image.vue index 0b65afb..e35cb23 100644 --- a/src/components/Form/src/components/Image.vue +++ b/src/components/Form/src/components/Image.vue @@ -29,13 +29,21 @@ import { Upload } from 'ant-design-vue'; import { PlusOutlined } from '@ant-design/icons-vue'; import { useMessage } from '/@/hooks/web/useMessage'; - import { getFileList } from '/@/api/system/file'; + import { getFileList,parseDownloadUrl } from '/@/api/system/file'; import { uploadMultiApi } from '/@/api/sys/upload'; import { Icon } from '/@/components/Icon'; const props = defineProps({ value: String, + tableName: { + type: String, + default: '' + }, + columnName: { + type: String, + default: '' + }, name: String, disabled: Boolean, isUpload: Boolean @@ -44,9 +52,23 @@ const fileList = ref(''); const list = ref([]); const { notification } = useMessage(); - const folderId = ref(''); + const tableId = ref(''); + const tableName = ref(''); + const columnName = ref(''); + + const bindValues = (data:any)=>{ + if(data){ + tableId.value = data.tableId; + tableName.value = data.tableName; + columnName.value = data.columnName; + }else{ + tableId.value = ''; + tableName.value = ''; + columnName.value = ''; + } + } const deleteFlag = ref(false); - const emit = defineEmits(['update:value', 'change', 'click']); + const emit = defineEmits(['update:value', 'change', 'click', 'update:tableName', 'update:columnName']); const loading = ref(false); const visible = ref(false); const setVisible = (value): void => { @@ -57,14 +79,14 @@ () => props.value, async (val) => { if (val) { - let result = await getFileList({ folderId: props.value }); + let result = await getFileList({tableName: props.tableName, columnName: props.columnName,tableId: props.value}); if (result.length) { for (let i = 0; i < result.length; i++) { let x = result[i]; if (i > 0) break; - fileList.value = x.fileUrl; + fileList.value = parseDownloadUrl(x.fileUrl,false,true); } - folderId.value = result[0].folderId; + bindValues(result[0]); console.log(fileList.value, val, 'fileList.value'); } } @@ -91,21 +113,22 @@ name: 'file', file: arr }, - folderId.value + tableId.value, tableName.value, columnName.value ); - folderId.value = res[0].folderId; + bindValues(res[0]); if (res.length) { for (let i = 0; i < res.length; i++) { let x = res[i]; - if (i > 0) break; - fileList.value = x.fileUrl; + fileList.value = parseDownloadUrl(x.fileUrl,false,true); } - folderId.value = res[0].folderId; + bindValues(res[0]); console.log(fileList.value, 'fileList.value1111111'); } - emit('update:value', folderId.value); + emit('update:value', tableId.value); + emit('update:tableName', tableName.value); + emit('update:columnName', columnName.value); emit('change'); loading.value = false; } catch (error) { diff --git a/src/components/Form/src/components/InputUpload.vue b/src/components/Form/src/components/InputUpload.vue index 2ba907a..1446672 100644 --- a/src/components/Form/src/components/InputUpload.vue +++ b/src/components/Form/src/components/InputUpload.vue @@ -42,7 +42,7 @@ import { Upload } from 'ant-design-vue'; import { QuestionCircleFilled, CloseCircleFilled } from '@ant-design/icons-vue'; import { useMessage } from '/@/hooks/web/useMessage'; - import { deleteSingleFile, getFileList } from '/@/api/system/file'; + import { deleteSingleFile, getFileList, parseDownloadUrl } from '/@/api/system/file'; import { downloadByUrl } from '/@/utils/file/download'; import { uploadMultiApi } from '/@/api/sys/upload'; import { Icon } from '/@/components/Icon'; @@ -51,6 +51,14 @@ const { VITE_GLOB_UPLOAD_ALERT_TIP } = getAppEnvConfig(); const props = defineProps({ value: String, + tableName: { + type: String, + default: '' + }, + columnName: { + type: String, + default: '' + }, showTip: { type: Boolean, default: true }, placeholder: String, tipType: String, @@ -61,9 +69,24 @@ const fileList = ref([]); const list = ref([]); const { notification } = useMessage(); - const folderId = ref(''); + const tableId = ref(''); + const tableName = ref(''); + const columnName = ref(''); + + const bindValues = (data:any)=>{ + if(data){ + tableId.value = data.tableId; + tableName.value = data.tableName; + columnName.value = data.columnName; + }else{ + tableId.value = ''; + tableName.value = ''; + columnName.value = ''; + } + } + const deleteFlag = ref(false); - const emit = defineEmits(['update:value', 'change', 'click']); + const emit = defineEmits(['update:value', 'change', 'click', 'update:tableName', 'update:columnName']); const loading = ref(false); const name = ref(); const previewVisible = ref(false); @@ -74,16 +97,16 @@ () => props.value, async (val) => { if (val) { - fileList.value = await getFileList({ folderId: props.value }); + fileList.value = await getFileList({ tableName: props.tableName, columnName: props.columnName,tableId: props.value}); if (fileList.value.length) { fileList.value.forEach((x) => { - x.name = x.fileName; + x.name = x.fileOrg; x.url = x.fileUrl; x.thumbUrl = x.thUrl; x.status = 'done'; //没有则不会展示下载按钮 }); - folderId.value = fileList.value[0].folderId; - name.value = fileList.value[0].name + fileList.value[0].fileType; + bindValues(fileList.value[0]); + name.value = fileList.value[0].fileOrg; } } if (!val) { @@ -110,16 +133,18 @@ name: 'file', file: arr }, - folderId.value + tableId.value, tableName.value, columnName.value ); - folderId.value = res[0].folderId; + bindValues(res[0]); fileList.value.forEach((x) => { x.status = 'done'; //没有则不会展示下载按钮 x.url = x.fileUrl; x.thumbUrl = x.thUrl; }); - name.value = res[0].fileName + res[0].fileType; - emit('update:value', folderId.value); + name.value = res[0].fileOrg; + emit('update:value', tableId.value); + emit('update:tableName', tableName.value); + emit('update:columnName', columnName.value); emit('change'); loading.value = false; } catch (error) { @@ -152,40 +177,40 @@ const handleRemove = async (info) => { const id = info.response ? info.response.data.id : info.id; - const newFolderId = await deleteSingleFile(id); + const status = await deleteSingleFile(id); - folderId.value = newFolderId; - - deleteFlag.value = true; - - const index = fileList.value.findIndex((x) => x.id === id); - fileList.value.splice(index, 1); - - fileList.value.forEach((x) => { - x.folderId = newFolderId; - }); - - emit('update:value', folderId.value); - emit('change'); - notification.success({ - message: 'Tip', - description: '删除成功!' - }); + if (status) { + deleteFlag.value = true; + const index = fileList.value.findIndex((x) => x.id === id); + fileList.value.splice(index, 1); + notification.success({ + message: 'Tip', + description: '删除成功!' + }); + }else{ + notification.error({ + message: 'Tip', + description: '删除失败!' + }); + } }; const handleDownload = (info) => { - const url = info.response ? info.response.data.fileUrl : info.fileUrl; - const fileName = info.response ? info.response.data.fileName : info.fileName; + const url = parseDownloadUrl(info.response ? info.response.data.fileUrl : info.fileUrl); + const fileName = info.response ? info.response.data.fileOrg : info.fileOrg; downloadByUrl({ url, fileName }); }; const handlePreview = async (file) => { const fileUrl = file.response?.data?.fileUrl || file.fileUrl; - previewFile.value = getAppEnvConfig().VITE_GLOB_UPLOAD_PREVIEW + encodeURIComponent(Base64.encode(fileUrl.includes('http://') || fileUrl.includes('https://') ? fileUrl : getAppEnvConfig().VITE_GLOB_API_URL + fileUrl)); + const fileFullUrl = fileUrl.includes('http://') || fileUrl.includes('https://') ? fileUrl : location.origin + getAppEnvConfig().VITE_GLOB_API_URL + fileUrl; + previewFile.value = getAppEnvConfig().VITE_GLOB_UPLOAD_PREVIEW + encodeURIComponent(Base64.encode(fileFullUrl)); previewVisible.value = true; - previewTitle.value = file.name || file.fileName; + previewTitle.value = file.name || file.fileOrg; + + console.log(fileFullUrl); }; const handleCancel = () => { @@ -195,8 +220,8 @@ function handleClear() { name.value = ''; - folderId.value = ''; - emit('update:value', folderId.value); + tableId.value = ''; + emit('update:value', tableId.value); emit('change'); } diff --git a/src/components/Form/src/components/Upload.vue b/src/components/Form/src/components/Upload.vue index a225bd6..938eb74 100644 --- a/src/components/Form/src/components/Upload.vue +++ b/src/components/Form/src/components/Upload.vue @@ -69,9 +69,9 @@ 点击上传 - +