Commit d312c36f by Sweet Zhang

对接文件上传

parent 99e7cc48
import request from '@/utils/request' import request from '@/utils/request'
// 修改上传图片方法,添加正确的请求配置 // 修改上传图片方法,添加正确的请求配置
export function uploadImage(data) { export function uploadImage(data) {
console.log('data', data) console.log('data', data)
...@@ -168,9 +167,9 @@ export function uploadMaterialList(data) { ...@@ -168,9 +167,9 @@ export function uploadMaterialList(data) {
}) })
} }
// 删除上传文件 // 删除上传文件
export function delUploadFile(fileBizId) { export function delUploadFile(fileBizId,projectBizId) {
return request({ return request({
url: `/oss/api/ossFile/del?fileBizId=${fileBizId}`, url: `/oss/api/ossFile/del?fileBizId=${fileBizId}&projectBizId=${projectBizId}`,
method: 'delete' method: 'delete'
}) })
} }
......
...@@ -132,6 +132,7 @@ const props = defineProps({ ...@@ -132,6 +132,7 @@ const props = defineProps({
tenantBizId: { type: String, required: true,default: '' }, tenantBizId: { type: String, required: true,default: '' },
projectBizId: { type: String, required: true, default: '' }, projectBizId: { type: String, required: true, default: '' },
objectBizId: { type: String, required: true, default: '' }, objectBizId: { type: String, required: true, default: '' },
projectType: { type: String, default: '' },
objectType: { type: String, default: '' }, objectType: { type: String, default: '' },
objectTableName: { type: String, default: '' }, objectTableName: { type: String, default: '' },
objectName: { type: String, default: '' }, objectName: { type: String, default: '' },
...@@ -303,7 +304,7 @@ const initOssClient = async () => { ...@@ -303,7 +304,7 @@ const initOssClient = async () => {
const data = res.data || res; const data = res.data || res;
const rawData = data.data || data; const rawData = data.data || data;
const { region, accessKeyId, accessKeySecret, stsToken, bucket, endpoint } = rawData; const { region, accessKeyId, accessKeySecret, stsToken, bucket, endpoint,filePrefix } = rawData;
if (!accessKeyId || !bucket) throw new Error('STS 凭证信息不完整'); if (!accessKeyId || !bucket) throw new Error('STS 凭证信息不完整');
...@@ -319,6 +320,7 @@ const initOssClient = async () => { ...@@ -319,6 +320,7 @@ const initOssClient = async () => {
endpoint: ossEndpoint, endpoint: ossEndpoint,
secure: true, secure: true,
timeout: 60000, timeout: 60000,
filePrefix
}); });
return ossClient.value; return ossClient.value;
} catch (error) { } catch (error) {
...@@ -335,8 +337,8 @@ const uploadSingleFile = async (item) => { ...@@ -335,8 +337,8 @@ const uploadSingleFile = async (item) => {
console.error('Invalid file object for upload:', file); console.error('Invalid file object for upload:', file);
throw new Error('文件对象无效,必须是 File 或 Blob 类型'); throw new Error('文件对象无效,必须是 File 或 Blob 类型');
} }
console.log(ossClient.value)
const objectName = `uploads/${props.projectBizId}/${Date.now()}_${item.uid}_${file.name}`; const objectName = `${ossClient.value.options.filePrefix}${props.projectBizId}${Date.now()}_${item.uid}_${file.name}`;
item.status = 'uploading'; item.status = 'uploading';
item.startTime = Date.now(); item.startTime = Date.now();
...@@ -360,8 +362,6 @@ const uploadSingleFile = async (item) => { ...@@ -360,8 +362,6 @@ const uploadSingleFile = async (item) => {
item.status = 'success'; item.status = 'success';
item.progress = 100; item.progress = 100;
item.speed = '-'; item.speed = '-';
// const endpoint = client.options.endpoint.replace(/^https?:\/\//, '');
const endpoint = client.options.endpoint.host; const endpoint = client.options.endpoint.host;
item.url = `https://${client.options.bucket}.${endpoint}/${objectName}`; item.url = `https://${client.options.bucket}.${endpoint}/${objectName}`;
...@@ -400,6 +400,7 @@ const startUpload = async () => { ...@@ -400,6 +400,7 @@ const startUpload = async () => {
tenantBizId: props.tenantBizId, tenantBizId: props.tenantBizId,
projectBizId: props.projectBizId, projectBizId: props.projectBizId,
objectBizId: props.objectBizId, objectBizId: props.objectBizId,
projectType:props.projectType,
objectType: props.objectType, objectType: props.objectType,
objectTableName: props.objectTableName, objectTableName: props.objectTableName,
objectName: props.objectName, objectName: props.objectName,
......
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
<div class="fileUploadBox"> <div class="fileUploadBox">
<el-upload <el-upload
:action="uploadImgUrl" :action="uploadImgUrl"
:data="{'projectBizId':userStore.projectInfo.projectBizId}"
:headers="headers" :headers="headers"
multiple multiple
:limit="limit" :limit="limit"
...@@ -138,6 +139,8 @@ import CardOne from '@/components/formCard/cardOne' ...@@ -138,6 +139,8 @@ import CardOne from '@/components/formCard/cardOne'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import { addFile, getAppointmentFile, delFile, editAppointmentFile } from '@/api/sign/appointment' import { addFile, getAppointmentFile, delFile, editAppointmentFile } from '@/api/sign/appointment'
import useDictStore from '@/store/modules/dict' import useDictStore from '@/store/modules/dict'
import useUserStore from '@/store/modules/user'
const userStore = useUserStore()
import { import {
uploadMaterialList, uploadMaterialList,
delUploadFile, delUploadFile,
...@@ -395,7 +398,7 @@ const uploadSuccess = (res, file, fileList) => { ...@@ -395,7 +398,7 @@ const uploadSuccess = (res, file, fileList) => {
// 删除已上传的文件(仅从列表移除,不调用后端删除) // 删除已上传的文件(仅从列表移除,不调用后端删除)
const removeUploadedFile = (file, index) => { const removeUploadedFile = (file, index) => {
try { try {
delUploadFile(file.fileBizId).then(response => { delUploadFile(file.fileBizId,userStore.projectInfo.projectBizId).then(response => {
uploadedFiles.value.splice(index, 1) uploadedFiles.value.splice(index, 1)
}) })
} catch (error) { } catch (error) {
......
...@@ -199,6 +199,7 @@ ...@@ -199,6 +199,7 @@
:project-biz-id="userStore.projectInfo.projectBizId" :project-biz-id="userStore.projectInfo.projectBizId"
:object-biz-id="props.policyBizId" :object-biz-id="props.policyBizId"
:object-type="'DOCUMENT'" :object-type="'DOCUMENT'"
:project-type="'pc'"
:upload-concurrency="3" :upload-concurrency="3"
ref="uploaderRef" ref="uploaderRef"
/> />
...@@ -1117,7 +1118,7 @@ const handleCancel = () => { ...@@ -1117,7 +1118,7 @@ const handleCancel = () => {
const deleteFile = (row)=>{ const deleteFile = (row)=>{
console.log(row) console.log(row)
const fileBizId = row.fileBizId || ''; const fileBizId = row.fileBizId || '';
delUploadFile(fileBizId).then(res=>{ delUploadFile(fileBizId,userStore.projectInfo.projectBizId).then(res=>{
console.log(res) console.log(res)
if(res.code===200){ if(res.code===200){
getAttachmentListDetail(props.policyBizId) getAttachmentListDetail(props.policyBizId)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment