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/.env.production b/.env.production index 98cc140..de84268 100644 --- a/.env.production +++ b/.env.production @@ -25,7 +25,7 @@ VITE_GLOB_REQUEST_TIMEOUT=600000 # 文件上传地址 可以由nginx做转发或者直接写实际地址 -VITE_GLOB_UPLOAD_URL = /system/oss/upload +VITE_GLOB_UPLOAD_URL = /system/file/upload # 文件预览接口 可选 VITE_GLOB_UPLOAD_PREVIEW = /preview/onlinePreview?url= @@ -42,7 +42,7 @@ VITE_GLOB_API_URL_PREFIX = # 打包是否开启pwa功能 VITE_USE_PWA = false #租户开关 -# VITE_GLOB_TENANT_ENABLED = true +VITE_GLOB_TENANT_ENABLED = true #登录时是否需要输入租户码 # VITE_GLOB_TENANT_INPUT_REQUIRED = true 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..c0a2385 100644 --- a/src/api/system/file/index.ts +++ b/src/api/system/file/index.ts @@ -2,20 +2,49 @@ import { defHttp } from '/@/utils/http/axios'; import { ErrorMessageMode } from '/#/axios'; import { FilePageListParams, FilePageListSearchModel, FilePageListResultModel, ZipFilesModel, FileModel } from './model'; +import { Base64 } from 'js-base64'; +import { getAppEnvConfig } from '/@/utils/env'; + +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 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; +} + +export function parsePreviewUrl(fileName: string, fileUrl: string) { + let fileFullUrl = fileUrl.includes('http://') || fileUrl.includes('https://') ? fileUrl : location.origin + getAppEnvConfig().VITE_GLOB_API_URL + fileUrl; + fileFullUrl+="&fullfilename="+fileName; + return getAppEnvConfig().VITE_GLOB_UPLOAD_PREVIEW + encodeURIComponent(Base64.encode(fileFullUrl)); +} + export async function getInfoByDownloadUrl(params: {id: string}, mode: ErrorMessageMode = 'modal') { return defHttp.get( { - url: Api.InfoByDownloadUrl, + url: Api.Info, params, }, { @@ -24,6 +53,7 @@ export async function getInfoByDownloadUrl(params: {id: string}, mode: ErrorMess ); } + /** * @description: 查询文件分页 */ @@ -48,7 +78,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 +91,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, }, - ); + ); } /** @@ -110,3 +140,6 @@ export async function getAppToken(params, mode: ErrorMessageMode = 'modal') { }, ); } + + + 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..bebe5de 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,32 +69,53 @@ 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); const previewImage = ref(''); const previewTitle = ref(''); - watch( - () => props.value, - async (val) => { - if (val) { - fileList.value = await getFileList({ folderId: props.value }); + + const refreshList = async (val:any) => { + if (val) { + 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); } + }; + + watch( + () => props.value, + async (val) => { + await refreshList(val); }, { immediate: true @@ -113,15 +136,21 @@ name: 'file', file: arr }, - folderId.value + tableId.value, tableName.value, columnName.value ); - folderId.value = res[0].folderId; + let tableIdValue = tableId.value; + 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'); + if(tableIdValue==tableId.value){ + await refreshList(tableId.value); + } loading.value = false; } catch (error) { loading.value = false; @@ -155,26 +184,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) => { @@ -185,7 +209,7 @@ const handlePreview = async (file) => { previewImage.value = file.response?.data?.fileUrl || file.fileUrl; previewVisible.value = true; - previewTitle.value = file.name || file.fileName; + previewTitle.value = file.name || file.fileOrg; }; const handleCancel = () => { diff --git a/src/components/Form/src/components/Image.vue b/src/components/Form/src/components/Image.vue index 0b65afb..290f75d 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,33 +52,51 @@ 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 => { visible.value = value; }; - watch( - () => props.value, - async (val) => { + const refreshList = async (val:any) => { 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'); } } if (!val) { fileList.value = ''; } + }; + + watch( + () => props.value, + async (val) => { + await refreshList(val); }, { immediate: true @@ -91,22 +117,27 @@ name: 'file', file: arr }, - folderId.value + tableId.value, tableName.value, columnName.value ); - folderId.value = res[0].folderId; + const tableIdValue = tableId.value; + 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'); + if(tableIdValue==tableId.value){ + await refreshList(tableId.value); + } loading.value = false; } catch (error) { console.error(error); diff --git a/src/components/Form/src/components/InputUpload.vue b/src/components/Form/src/components/InputUpload.vue index 2ba907a..0b6a938 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,35 +69,53 @@ 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); const previewFile = ref(''); const previewTitle = ref(''); + const refreshList = async (val:any) => { + if (val) { + fileList.value = await getFileList({ tableName: props.tableName, columnName: props.columnName,tableId: props.value}); + if (fileList.value.length) { + fileList.value.forEach((x) => { + x.name = x.fileOrg; + x.url = x.fileUrl; + x.thumbUrl = x.thUrl; + x.status = 'done'; //没有则不会展示下载按钮 + }); + bindValues(fileList.value[0]); + name.value = fileList.value[0].fileOrg; + } + } else { + fileList.value = []; + name.value = ''; + } + }; + watch( () => props.value, async (val) => { - if (val) { - fileList.value = await getFileList({ folderId: props.value }); - if (fileList.value.length) { - fileList.value.forEach((x) => { - x.name = x.fileName; - 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; - } - } - if (!val) { - fileList.value = []; - name.value = ''; - } + await refreshList(val); }, { immediate: true @@ -110,17 +136,21 @@ name: 'file', file: arr }, - folderId.value + tableId.value, tableName.value, columnName.value ); - folderId.value = res[0].folderId; + const tableIdValue = tableId.value; + 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'); + if(tableIdValue==tableId.value) await refreshList(tableId.value); loading.value = false; } catch (error) { console.error(error); @@ -152,40 +182,46 @@ 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); + emit('update:value', tableId.value); + emit('update:tableName', tableName.value); + emit('update:columnName', columnName.value); + emit('change'); + 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 fileName = file.response?.data?.fileOrg || file.fileOrg; + let fileFullUrl = fileUrl.includes('http://') || fileUrl.includes('https://') ? fileUrl : location.origin + getAppEnvConfig().VITE_GLOB_API_URL + fileUrl; + fileFullUrl+="&fullfilename="+fileName; + 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 +231,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 dc338df..c823c4a 100644 --- a/src/components/Form/src/components/Upload.vue +++ b/src/components/Form/src/components/Upload.vue @@ -110,7 +110,7 @@ import { Upload } from 'ant-design-vue'; import { UploadOutlined, PlusOutlined, DownloadOutlined, DeleteOutlined, EditOutlined, PaperClipOutlined } from '@ant-design/icons-vue'; import { useMessage } from '/@/hooks/web/useMessage'; - import { deleteSingleFile, getAppToken, getFileList, getOnlineEditUrl, getZipFiles } from '/@/api/system/file'; + import { deleteFile, getAppToken, getFileList, getZipFiles,parseDownloadUrl,parsePreviewUrl} from '/@/api/system/file'; import { downloadByUrl } from '/@/utils/file/download'; import { uploadMultiApi } from '/@/api/sys/upload'; import Icon from '/@/components/Icon/index'; @@ -119,13 +119,24 @@ import WebOfficeSDK from '/@/assets/libs/open-jssdk-v0.1.3.es.js'; import { getToken } from '/@/utils/auth'; import { useRoute } from 'vue-router'; +import { methodOf } from 'lodash-es'; const route = useRoute(); const { VITE_GLOB_UPLOAD_ALERT_TIP } = getAppEnvConfig(); const { createSuccessModal } = useMessage(); + + const props = defineProps({ value: String, + tableName: { + type: String, + default: '' + }, + columnName: { + type: String, + default: '' + }, maxNumber: Number, accept: String, name: String, @@ -156,9 +167,25 @@ const fileList = ref([]); const list = ref([]); const { notification } = useMessage(); - const folderId = ref(''); + const tableId = ref(''); + const tableName = ref(''); + const columnName = ref(''); + const removeIds = 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); @@ -166,26 +193,31 @@ const previewFile = ref(''); const previewTitle = ref(''); - watch( - () => props.value, - async (val) => { - if (val) { - fileList.value = await getFileList({ folderId: props.value }); + const refreshList = async (val:any) => { + if (val) { + let _list = await getFileList({ tableName: props.tableName, columnName: props.columnName,tableId: props.value }); + fileList.value = _list.filter((o) => !removeIds.value.includes(o.id)); 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; + bindValues(fileList.value[0]); } } else { - folderId.value = ''; - } - if (!val) { - fileList.value = []; + bindValues(undefined); } + if (!val) { + fileList.value = []; + } + }; + + watch( + () => props.value, + async (val) => { + await refreshList(val); }, { immediate: true @@ -206,18 +238,24 @@ name: 'file', file: arr }, - folderId.value + tableId.value, tableName.value, columnName.value ); - folderId.value = res[0].folderId; + fileList.value.forEach((x) => { x.status = 'done'; //没有则不会展示下载按钮 x.url = x.fileUrl; x.thumbUrl = x.thUrl; x.fileSize = x.fileSize }); - - emit('update:value', folderId.value); + let tableIdValue = tableId.value; + bindValues(res[0]); + emit('update:value', tableId.value); + emit('update:tableName', tableName.value); + emit('update:columnName', columnName.value); emit('change'); + if(tableIdValue==tableId.value){ + await refreshList(tableId.value); + } loading.value = false; } catch (error) { console.error(error); @@ -255,34 +293,34 @@ } 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 deleteFile([id]); + if (status) { + removeIds.value.push(id); + deleteFlag.value = true; + const index = fileList.value.findIndex((x) => x.id === id); + fileList.value.splice(index, 1); + + emit('update:value', tableId.value); + emit('update:tableName', tableName.value); + emit('update:columnName', columnName.value); + emit('change'); + await refreshList(tableId.value); + 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 fileType = info.response ? info.response.data.fileType : info.fileType; - - downloadByUrl({ url, fileName: fileName + fileType }); + const url = parseDownloadUrl(info.response ? info.response.data.fileUrl : info.fileUrl); + const fileName = info.response ? info.response.data.fileOrg : info.fileOrg; + downloadByUrl({ url, fileName: fileName}); }; const handleCancelWps = () => { @@ -322,12 +360,13 @@ 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 fileName = file.name || file.fileOrg; + const previewUrl = parsePreviewUrl(fileName, fileUrl); + previewFile.value = parsePreviewUrl(fileName, fileUrl); previewVisible.value = true; - previewTitle.value = file.name || file.fileName; - - console.log(fileUrl.includes('http://') || fileUrl.includes('https://') ? fileUrl : getAppEnvConfig().VITE_GLOB_API_URL + fileUrl); + previewTitle.value = fileName; + console.log(previewUrl); }; const handleCancel = () => { @@ -377,7 +416,7 @@ createSuccessModal({ title: 'Tip', content: res.msg }); return; } else if (res.type === 'synced') { - downloadByUrl({ url: res.url, fileName: res.name || 'files.zip' }); + downloadByUrl({ url: parseDownloadUrl(res.url), fileName: res.name || 'files.zip' }); } } diff --git a/src/components/Form/src/components/UploadNew.vue b/src/components/Form/src/components/UploadNew.vue index 46e1615..d4ba47c 100644 --- a/src/components/Form/src/components/UploadNew.vue +++ b/src/components/Form/src/components/UploadNew.vue @@ -110,7 +110,7 @@ import { Upload } from 'ant-design-vue'; import { UploadOutlined, PlusOutlined, DownloadOutlined, DeleteOutlined, EditOutlined, PaperClipOutlined } from '@ant-design/icons-vue'; import { useMessage } from '/@/hooks/web/useMessage'; - import { deleteSingleFile, getAppToken, getFileList, getOnlineEditUrl, getZipFiles } from '/@/api/system/file'; + import { deleteSingleFile, getAppToken, getFileList, parseDownloadUrl, getZipFiles } from '/@/api/system/file'; import { downloadByUrl } from '/@/utils/file/download'; import { uploadMultiApi } from '/@/api/sys/upload'; import Icon from '/@/components/Icon/index'; @@ -126,6 +126,8 @@ const props = defineProps({ value: String, + tableName: String, + columnName: String, maxNumber: Number, accept: String, name: String, @@ -162,9 +164,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 previewVisible = ref(false); @@ -185,10 +201,10 @@ x.status = 'done'; //没有则不会展示下载按钮 x.fileType =x.fileType || ('.' + x.filePath.split('?')[0]?.split('.')?.pop()) }); - // folderId.value = fileList.value[0].folderId; } + bindValues(fileList.value[0]); } else { - folderId.value = ''; + bindValues(undefined); } if (!val) { fileList.value = []; @@ -202,7 +218,7 @@ () => 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; @@ -210,10 +226,10 @@ x.thumbUrl = x.thUrl; x.status = 'done'; //没有则不会展示下载按钮 }); - folderId.value = fileList.value[0].folderId; } + bindValues(fileList.value[0]); } else { - folderId.value = ''; + bindValues(undefined); } if (!val) { fileList.value = []; @@ -238,9 +254,8 @@ name: 'file', file: arr }, - folderId.value + tableId.value, tableName.value, columnName.value ); - // folderId.value = res[0].folderId; let fileArr = res||[] fileArr.forEach((x) => { x.status = 'done'; //没有则不会展示下载按钮 @@ -248,9 +263,12 @@ x.thumbUrl = x.thUrl; x.fileSize = x.fileSize }); + bindValues(res[0]); fileList.value = [...fileList.value, ...fileArr] - emit('update:value', folderId.value); - emit('change', fileList.value); + emit('update:value', tableId.value); + emit('update:tableName', tableName.value); + emit('update:columnName', columnName.value); + emit('change'); loading.value = false; } catch (error) { console.error(error); @@ -288,21 +306,9 @@ } 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('update:value', tableId.value); emit('change', fileList.value); notification.success({ message: 'Tip', @@ -312,12 +318,9 @@ const handleDownload = (info) => { console.log(info, 434) - - const url = info.response ? info.response.data.fileUrl : (info.presignedUrl || info.fileUrl); - const fileName = info.response ? info.response.data.fileName : (info.fileOrg || info.fileName); - const fileType = info.response ? info.response.data.fileType : info.fileType; - - downloadByUrl({ url, fileName: fileName + fileType }); + const url = parseDownloadUrl(info.response ? info.response.data.fileUrl : (info.presignedUrl || info.fileUrl)); + const fileName = info.response ? info.response.data.fileOrg : info.fileOrg; + downloadByUrl({ url, fileName: fileName }); }; const handleCancelWps = () => { @@ -356,16 +359,15 @@ }; const handlePreview = async (file) => { - const fileUrl = file.presignedUrl|| file.response?.data?.fileUrl || file.fileUrl; - console.log(fileUrl, 'fileUrl', file) - window.open(fileUrl) + // const fileUrl = file.presignedUrl|| file.response?.data?.fileUrl || file.fileUrl; + // console.log(fileUrl, 'fileUrl', file) + // window.open(fileUrl) - // previewFile.value = getAppEnvConfig().VITE_GLOB_UPLOAD_PREVIEW + encodeURIComponent(Base64.encode(fileUrl.includes('http://') || fileUrl.includes('https://') ? fileUrl : getAppEnvConfig().VITE_GLOB_API_URL + fileUrl)); - - // previewVisible.value = true; - // previewTitle.value = file.name || file.fileName; - // console.log(previewFile.value, 99) - // console.log(fileUrl.includes('http://') || fileUrl.includes('https://') ? fileUrl : getAppEnvConfig().VITE_GLOB_API_URL + fileUrl); + const fileUrl = file.presignedUrl|| file.response?.data?.fileUrl || file.fileUrl; + const fileName = file.response?.data?.fileOrg || file.fileOrg; + let fileFullUrl = fileUrl.includes('http://') || fileUrl.includes('https://') ? fileUrl : location.origin + getAppEnvConfig().VITE_GLOB_API_URL + fileUrl; + fileFullUrl+="&fullfilename="+fileName; + previewFile.value = getAppEnvConfig().VITE_GLOB_UPLOAD_PREVIEW + encodeURIComponent(Base64.encode(fileFullUrl)); }; const handleCancel = () => { diff --git a/src/components/Upload/src/BasicUpload.vue b/src/components/Upload/src/BasicUpload.vue index 52311e4..ff4e6aa 100644 --- a/src/components/Upload/src/BasicUpload.vue +++ b/src/components/Upload/src/BasicUpload.vue @@ -20,7 +20,7 @@ - + @@ -56,7 +56,7 @@ const fileList = ref([]); const fileNameList = ref([]); - const folderId = computed(() => props.value); + const tableId = computed(() => props.value); const showPreview = computed(() => { const { emptyHidePreview } = props; if (!emptyHidePreview) return true; @@ -73,9 +73,9 @@ async (value) => { //如果没有传入参数 默认不再请求文件列表 if (value && value.length > 0) { - const list = await getFileList({ folderId: value }); + const list = await getFileList({ tableId: value }); fileList.value = list.map((item) => item.fileUrl); - fileNameList.value = list.map((item) => item.fileName); + fileNameList.value = list.map((item) => item.fileOName); } else { fileList.value = []; } @@ -122,7 +122,7 @@ bindValue, handleDelete, handlePreviewDelete, - folderId, + tableId, t }; } diff --git a/src/components/Upload/src/UploadModal.vue b/src/components/Upload/src/UploadModal.vue index 564a09f..7677027 100644 --- a/src/components/Upload/src/UploadModal.vue +++ b/src/components/Upload/src/UploadModal.vue @@ -173,7 +173,7 @@ { data: { ...(props.uploadParams || {}), - folderId + tableId: props.folderId, }, file: item.file, name: props.name, diff --git a/src/layouts/default/header/components/notify/index.vue b/src/layouts/default/header/components/notify/index.vue index 9124cff..47fd531 100644 --- a/src/layouts/default/header/components/notify/index.vue +++ b/src/layouts/default/header/components/notify/index.vue @@ -161,7 +161,7 @@ import { getOaMessage, getOaNews, setOaRead, setSingleRead, setWorkReadAll, getScheduleMsg, setScheduleRead, setScheduleReadAll } from '/@/api/system/login'; import { queryLoginUserNotices, setSystemNoticeRead } from '/@/api/system/systemNotice/index'; - import { getInfoByDownloadUrl } from '/@/api/system/file'; + import { getInfoByDownloadUrl,parseDownloadUrl } from '/@/api/system/file'; import { Empty } from 'ant-design-vue'; import ApprovalProcess from '/@/views/workflow/task/components/ApprovalProcess.vue'; @@ -356,8 +356,8 @@ record.paramsJson = record.paramsJson ? JSON.parse(record.paramsJson) : {}; let fileId = record.paramsJson.id || []; getInfoByDownloadUrl({ id: fileId }).then((res) => { - let fileUrl = res.fileUrlFixed || res.fileUrl; - downloadByUrl({ url: fileUrl, fileName: res.fileName + res.fileType || 'files.zip' }); + let fileUrl = parseDownloadUrl(res.fileUrl); + downloadByUrl({ url: res.fileUrl, fileName: res.fileOrg || 'files.zip' }); }); return; } diff --git a/src/utils/file/download.ts b/src/utils/file/download.ts index 7ea91b2..87d31b5 100644 --- a/src/utils/file/download.ts +++ b/src/utils/file/download.ts @@ -1,5 +1,6 @@ import { openWindow } from '..'; import { dataURLtoBlob, urlToBase64 } from './base64Conver'; +import { defHttp } from '/@/utils/http/axios'; /** * Download online pictures @@ -71,7 +72,6 @@ export function downloadByUrl({ let fileUrl = window.URL.createObjectURL(x.response); const isChrome = window.navigator.userAgent.toLowerCase().indexOf('chrome') > -1; const isSafari = window.navigator.userAgent.toLowerCase().indexOf('safari') > -1; - if (/(iP)/g.test(window.navigator.userAgent)) { console.error('Your browser does not support download!'); return false; diff --git a/src/utils/http/axios/index.ts b/src/utils/http/axios/index.ts index 3910cbf..7fcf91d 100644 --- a/src/utils/http/axios/index.ts +++ b/src/utils/http/axios/index.ts @@ -26,7 +26,6 @@ import useGlobalFlag from '/@/hooks/core/useGlobalFlag'; import { useLockStore } from '/@/store/modules/lock'; - const globSetting = useGlobSetting(); const urlPrefix = globSetting.urlPrefix; const { createMessage, createErrorModal } = useMessage(); diff --git a/src/views/erp/customer/components/AttachmentModal.vue b/src/views/erp/customer/components/AttachmentModal.vue index 282af98..8d82916 100644 --- a/src/views/erp/customer/components/AttachmentModal.vue +++ b/src/views/erp/customer/components/AttachmentModal.vue @@ -25,7 +25,7 @@ height: '300px' } }); - imgList.value = await getFileList({ folderId: data.filePath }); + imgList.value = await getFileList({ tableId: data.filePath }); });