tijiao
This commit is contained in:
@@ -161,6 +161,7 @@ interface FileItem {
|
|||||||
name?: string;
|
name?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
uid?: number;
|
uid?: number;
|
||||||
|
id?: string; // 文件ID
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UploadFileItem {
|
interface UploadFileItem {
|
||||||
@@ -270,14 +271,74 @@ const handleBeforeUpload = (file: File) => {
|
|||||||
// 上传成功回调
|
// 上传成功回调
|
||||||
function handleUploadSuccess(res: any, file: any) {
|
function handleUploadSuccess(res: any, file: any) {
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
|
// 调试:打印完整的响应数据
|
||||||
|
console.log('上传成功响应数据:', res);
|
||||||
|
console.log('res.data:', res.data);
|
||||||
|
|
||||||
|
// 获取文件ID - 尝试多种可能的字段名
|
||||||
|
let fileId = res.data?.id || res.data?.fileId || res.data?.file_id || null;
|
||||||
|
let fileUrl = res.data?.url || res.data?.fileUrl || '';
|
||||||
|
|
||||||
|
// 如果fileId不存在,尝试从fileName中提取(fileName可能是ID)
|
||||||
|
if (!fileId && res.data?.fileName) {
|
||||||
|
const fileName = res.data.fileName;
|
||||||
|
// 检查fileName是否是32位十六进制字符串(文件ID格式)
|
||||||
|
if (/^[a-f0-9]{32}$/i.test(fileName)) {
|
||||||
|
fileId = fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果fileId仍然不存在,尝试从URL中提取
|
||||||
|
if (!fileId && fileUrl) {
|
||||||
|
try {
|
||||||
|
const urlObj = new URL(fileUrl, window.location.origin);
|
||||||
|
fileId = urlObj.searchParams.get('id');
|
||||||
|
// 如果URL参数中没有id,检查路径中是否有32位十六进制字符串
|
||||||
|
if (!fileId) {
|
||||||
|
const pathParts = urlObj.pathname.split('/').filter(p => p);
|
||||||
|
const lastPart = pathParts[pathParts.length - 1];
|
||||||
|
if (lastPart && /^[a-f0-9]{32}$/i.test(lastPart)) {
|
||||||
|
fileId = lastPart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// URL解析失败,忽略
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果仍然没有fileId,尝试从整个res.data中查找可能的ID字段
|
||||||
|
if (!fileId && res.data) {
|
||||||
|
// 遍历res.data的所有属性,查找32位十六进制字符串
|
||||||
|
for (const key in res.data) {
|
||||||
|
const value = res.data[key];
|
||||||
|
if (typeof value === 'string' && /^[a-f0-9]{32}$/i.test(value)) {
|
||||||
|
fileId = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('提取的文件ID:', fileId);
|
||||||
|
|
||||||
|
// 构建URL,如果存在id则添加到URL参数中(用于兼容性)
|
||||||
|
if (fileId && fileUrl) {
|
||||||
|
// 如果URL中已经有参数,使用&,否则使用?
|
||||||
|
fileUrl = fileUrl.includes('?') ? `${fileUrl}&id=${fileId}` : `${fileUrl}?id=${fileId}`;
|
||||||
|
}
|
||||||
|
fileUrl = `${fileUrl}&originalFileName=${file.name}`;
|
||||||
|
|
||||||
uploadList.value.push({
|
uploadList.value.push({
|
||||||
name: file.name,
|
name: file.name,
|
||||||
url: `${res.data?.url}&originalFileName=${file.name}`,
|
url: fileUrl,
|
||||||
fileUrl: res.data?.fileName,
|
fileUrl: res.data?.fileName,
|
||||||
fileSize: file.size,
|
fileSize: file.size,
|
||||||
fileName: file.name,
|
fileName: file.name,
|
||||||
fileType: file.raw.type,
|
fileType: file.raw.type,
|
||||||
|
id: fileId, // 保存文件ID(优先使用)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('保存的文件对象:', uploadList.value[uploadList.value.length - 1]);
|
||||||
|
|
||||||
uploadedSuccessfully();
|
uploadedSuccessfully();
|
||||||
} else {
|
} else {
|
||||||
number.value--;
|
number.value--;
|
||||||
@@ -319,12 +380,21 @@ const handleExceed = () => {
|
|||||||
* @param separator 分隔符,默认为逗号。
|
* @param separator 分隔符,默认为逗号。
|
||||||
* @returns {string} 返回转换后的字符串。
|
* @returns {string} 返回转换后的字符串。
|
||||||
*/
|
*/
|
||||||
|
/**
|
||||||
|
* 将对象数组转为字符串,以逗号分隔。
|
||||||
|
* 如果文件有id,优先使用id,否则使用url。
|
||||||
|
* @param list 待转换的对象数组。
|
||||||
|
* @param separator 分隔符,默认为逗号。
|
||||||
|
* @returns {string} 返回转换后的字符串(ID或URL,用逗号分隔)。
|
||||||
|
*/
|
||||||
const listToString = (list: FileItem[], separator = ','): string => {
|
const listToString = (list: FileItem[], separator = ','): string => {
|
||||||
let strs = '';
|
let strs = '';
|
||||||
separator = separator || ',';
|
separator = separator || ',';
|
||||||
for (let i in list) {
|
for (let i in list) {
|
||||||
if (list[i].url) {
|
// 优先使用id,如果没有id则使用url
|
||||||
strs += list[i].url + separator;
|
const value = list[i].id || list[i].url;
|
||||||
|
if (value) {
|
||||||
|
strs += value + separator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strs !== '' ? strs.substr(0, strs.length - 1) : '';
|
return strs !== '' ? strs.substr(0, strs.length - 1) : '';
|
||||||
@@ -347,7 +417,28 @@ watch(
|
|||||||
// 然后将数组转为对象数组
|
// 然后将数组转为对象数组
|
||||||
fileList.value = list.map((item: any) => {
|
fileList.value = list.map((item: any) => {
|
||||||
if (typeof item === 'string') {
|
if (typeof item === 'string') {
|
||||||
item = { name: other.getQueryString(item, 'originalFileName') || other.getQueryString(item, 'fileName'), url: item };
|
// 检查是否是32位十六进制字符串(文件ID格式)
|
||||||
|
const isId = /^[a-f0-9]{32}$/i.test(item.trim());
|
||||||
|
if (isId) {
|
||||||
|
// 如果是ID格式,直接使用
|
||||||
|
item = { id: item.trim(), name: '', url: '' };
|
||||||
|
} else {
|
||||||
|
// 如果是URL,尝试从URL中提取id
|
||||||
|
try {
|
||||||
|
const urlObj = new URL(item, window.location.origin);
|
||||||
|
const id = urlObj.searchParams.get('id');
|
||||||
|
item = {
|
||||||
|
name: other.getQueryString(item, 'originalFileName') || other.getQueryString(item, 'fileName'),
|
||||||
|
url: item,
|
||||||
|
id: id || undefined
|
||||||
|
};
|
||||||
|
} catch {
|
||||||
|
item = {
|
||||||
|
name: other.getQueryString(item, 'originalFileName') || other.getQueryString(item, 'fileName'),
|
||||||
|
url: item
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
item.uid = item.uid || new Date().getTime() + temp++;
|
item.uid = item.uid || new Date().getTime() + temp++;
|
||||||
return item as FileItem;
|
return item as FileItem;
|
||||||
|
|||||||
@@ -211,6 +211,28 @@
|
|||||||
upload-file-url="/purchase/purchasingfiles/upload" />
|
upload-file-url="/purchase/purchasingfiles/upload" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<!-- 询价 -->
|
||||||
|
<el-form-item
|
||||||
|
v-if="isInquiryPurchaseType"
|
||||||
|
label="询价模板"
|
||||||
|
prop="inquiryTemplate"
|
||||||
|
class="mb20">
|
||||||
|
<el-button
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
icon="Download"
|
||||||
|
@click="downloadTemplate('inquiry')"
|
||||||
|
class="mb10">
|
||||||
|
下载《部门采购询价模版》模版
|
||||||
|
</el-button>
|
||||||
|
<upload-file
|
||||||
|
v-model="dataForm.inquiryTemplate"
|
||||||
|
:limit="5"
|
||||||
|
:file-type="['doc', 'docx', 'pdf']"
|
||||||
|
:data="{ fileType: FILE_TYPE_MAP.inquiryTemplate }"
|
||||||
|
upload-file-url="/purchase/purchasingfiles/upload" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<!-- 委托采购中心 -->
|
<!-- 委托采购中心 -->
|
||||||
<template v-if="isPurchaseType(PURCHASE_TYPE_IDS.ENTRUST_CENTER)">
|
<template v-if="isPurchaseType(PURCHASE_TYPE_IDS.ENTRUST_CENTER)">
|
||||||
<el-form-item label="委托采购中心方式" prop="entrustCenterType" class="mb20">
|
<el-form-item label="委托采购中心方式" prop="entrustCenterType" class="mb20">
|
||||||
@@ -776,6 +798,7 @@ const dataForm = reactive({
|
|||||||
businessNegotiationTable: '',
|
businessNegotiationTable: '',
|
||||||
marketPurchaseMinutes: '',
|
marketPurchaseMinutes: '',
|
||||||
onlineMallMaterials: '',
|
onlineMallMaterials: '',
|
||||||
|
inquiryTemplate: '', // 询价模板
|
||||||
entrustCenterType: '',
|
entrustCenterType: '',
|
||||||
hasSupplier: '',
|
hasSupplier: '',
|
||||||
suppliers: '', // 供应商名称(逗号或分号分隔)
|
suppliers: '', // 供应商名称(逗号或分号分隔)
|
||||||
@@ -835,6 +858,7 @@ const PURCHASE_TYPE_IDS = {
|
|||||||
const FILE_TYPE_MAP: Record<string, string> = {
|
const FILE_TYPE_MAP: Record<string, string> = {
|
||||||
businessNegotiationTable: '10', // 商务洽谈纪要
|
businessNegotiationTable: '10', // 商务洽谈纪要
|
||||||
marketPurchaseMinutes: '20', // 市场采购纪要
|
marketPurchaseMinutes: '20', // 市场采购纪要
|
||||||
|
inquiryTemplate: '20', // 询价模板(归类到市场采购纪要)
|
||||||
onlineMallMaterials: '30', // 网上商城采购相关材料
|
onlineMallMaterials: '30', // 网上商城采购相关材料
|
||||||
feasibilityReport: '40', // 可行性论证报告
|
feasibilityReport: '40', // 可行性论证报告
|
||||||
meetingMinutes: '50', // 会议记录
|
meetingMinutes: '50', // 会议记录
|
||||||
@@ -871,6 +895,17 @@ const isPurchaseType = (purchaseTypeId: string) => {
|
|||||||
return dataForm.purchaseType === purchaseTypeId;
|
return dataForm.purchaseType === purchaseTypeId;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 辅助函数:判断当前采购方式是否为"询价"(通过 label 匹配)
|
||||||
|
const isInquiryPurchaseType = computed(() => {
|
||||||
|
if (!dataForm.purchaseType) return false;
|
||||||
|
const item = purchaseTypeDeptList.value.find(item => item.value === dataForm.purchaseType);
|
||||||
|
if (item) {
|
||||||
|
const label = item.label || item.dictLabel || item.name || '';
|
||||||
|
return label.includes('询价');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
// 辅助函数:判断特殊情况是否为指定类型(通过 id 或 value 匹配)
|
// 辅助函数:判断特殊情况是否为指定类型(通过 id 或 value 匹配)
|
||||||
const isSpecialType = (specialIdOrValue: string) => {
|
const isSpecialType = (specialIdOrValue: string) => {
|
||||||
if (!dataForm.isSpecial) return false;
|
if (!dataForm.isSpecial) return false;
|
||||||
@@ -1085,6 +1120,7 @@ const downloadTemplate = async (type: string) => {
|
|||||||
const templateMap: Record<string, { fileName: string, displayName: string }> = {
|
const templateMap: Record<string, { fileName: string, displayName: string }> = {
|
||||||
'business_negotiation': { fileName: '商务洽谈表.xlsx', displayName: '商务洽谈表.xlsx' },
|
'business_negotiation': { fileName: '商务洽谈表.xlsx', displayName: '商务洽谈表.xlsx' },
|
||||||
'market_purchase_minutes': { fileName: '市场采购纪要.xlsx', displayName: '市场采购纪要.xlsx' },
|
'market_purchase_minutes': { fileName: '市场采购纪要.xlsx', displayName: '市场采购纪要.xlsx' },
|
||||||
|
'inquiry': { fileName: '部门采购询价模版.docx', displayName: '部门采购询价模版.docx' },
|
||||||
'direct_select': { fileName: '服务商城项目需求模板(直选).doc', displayName: '服务商城项目需求模板(直选).doc' },
|
'direct_select': { fileName: '服务商城项目需求模板(直选).doc', displayName: '服务商城项目需求模板(直选).doc' },
|
||||||
'public_select': { fileName: '服务商城项目需求模板(公开比选).doc', displayName: '服务商城项目需求模板(公开比选).doc' },
|
'public_select': { fileName: '服务商城项目需求模板(公开比选).doc', displayName: '服务商城项目需求模板(公开比选).doc' },
|
||||||
'invite_select': { fileName: '服务商城项目需求模板(邀请比选).doc', displayName: '服务商城项目需求模板(邀请比选).doc' },
|
'invite_select': { fileName: '服务商城项目需求模板(邀请比选).doc', displayName: '服务商城项目需求模板(邀请比选).doc' },
|
||||||
@@ -1437,50 +1473,52 @@ const handleSchoolLeaderChange = (value: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 处理文件ID字符串转数组
|
// 处理文件ID字符串转数组
|
||||||
// 从上传返回的URL中提取文件ID,拼成数组格式:["id1", "id2"]
|
// 从上传返回的URL或ID中提取文件ID,拼成数组格式:["id1", "id2"]
|
||||||
|
// 上传接口返回的id会保存在URL的id参数中,或者直接是32位十六进制字符串
|
||||||
const getFileIdsArray = (fileIds: string | string[]): string[] => {
|
const getFileIdsArray = (fileIds: string | string[]): string[] => {
|
||||||
if (!fileIds) return [];
|
if (!fileIds) return [];
|
||||||
if (Array.isArray(fileIds)) return fileIds;
|
if (Array.isArray(fileIds)) return fileIds;
|
||||||
|
|
||||||
const urls = fileIds.split(',').filter(url => url.trim());
|
const items = fileIds.split(',').filter(item => item.trim());
|
||||||
const ids: string[] = [];
|
const ids: string[] = [];
|
||||||
|
|
||||||
urls.forEach(url => {
|
items.forEach(item => {
|
||||||
|
const trimmed = item.trim();
|
||||||
|
// 首先检查是否是直接的ID格式(32位十六进制字符串)
|
||||||
|
if (/^[a-f0-9]{32}$/i.test(trimmed)) {
|
||||||
|
ids.push(trimmed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果不是ID格式,尝试从URL中提取id参数
|
||||||
try {
|
try {
|
||||||
// 尝试解析为URL
|
const urlObj = new URL(trimmed, window.location.origin);
|
||||||
const urlObj = new URL(url, window.location.origin);
|
|
||||||
// 优先从URL参数中获取id
|
// 优先从URL参数中获取id
|
||||||
let id = urlObj.searchParams.get('id');
|
let id = urlObj.searchParams.get('id');
|
||||||
|
|
||||||
// 如果没有id参数,尝试从路径中提取(可能是直接的文件ID)
|
// 如果没有id参数,尝试从路径中提取(可能是直接的文件ID)
|
||||||
if (!id) {
|
if (!id) {
|
||||||
const pathParts = urlObj.pathname.split('/').filter(p => p);
|
const pathParts = urlObj.pathname.split('/').filter(p => p);
|
||||||
// 检查最后一个路径段是否是32位十六进制字符串(文件ID格式)
|
|
||||||
const lastPart = pathParts[pathParts.length - 1];
|
const lastPart = pathParts[pathParts.length - 1];
|
||||||
if (lastPart && /^[a-f0-9]{32}$/i.test(lastPart)) {
|
if (lastPart && /^[a-f0-9]{32}$/i.test(lastPart)) {
|
||||||
id = lastPart;
|
id = lastPart;
|
||||||
} else if (lastPart) {
|
|
||||||
id = lastPart;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
ids.push(id);
|
ids.push(id);
|
||||||
} else {
|
} else {
|
||||||
// 如果URL解析失败,检查原始字符串是否是ID格式
|
// 如果无法提取ID,使用原始字符串(可能是URL)
|
||||||
if (/^[a-f0-9]{32}$/i.test(url.trim())) {
|
// 但这种情况不应该发生,因为上传接口应该返回id
|
||||||
ids.push(url.trim());
|
console.warn('无法从URL中提取文件ID:', trimmed);
|
||||||
} else {
|
ids.push(trimmed);
|
||||||
ids.push(url);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// URL解析失败,检查是否是直接的ID格式(32位十六进制)
|
// URL解析失败,如果原始字符串是ID格式则使用,否则忽略
|
||||||
if (/^[a-f0-9]{32}$/i.test(url.trim())) {
|
if (/^[a-f0-9]{32}$/i.test(trimmed)) {
|
||||||
ids.push(url.trim());
|
ids.push(trimmed);
|
||||||
} else {
|
} else {
|
||||||
// 否则直接使用原始字符串
|
console.warn('无法解析文件标识:', trimmed);
|
||||||
ids.push(url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1506,7 +1544,7 @@ const handleSubmit = async () => {
|
|||||||
|
|
||||||
// 处理所有文件字段
|
// 处理所有文件字段
|
||||||
const fileFields = [
|
const fileFields = [
|
||||||
'businessNegotiationTable', 'marketPurchaseMinutes', 'onlineMallMaterials',
|
'businessNegotiationTable', 'marketPurchaseMinutes', 'onlineMallMaterials', 'inquiryTemplate',
|
||||||
'serviceDirectSelect', 'servicePublicSelect', 'purchaseRequirementTemplate',
|
'serviceDirectSelect', 'servicePublicSelect', 'purchaseRequirementTemplate',
|
||||||
'serviceInviteSelect', 'servicePublicSelectAuto', 'purchaseRequirement',
|
'serviceInviteSelect', 'servicePublicSelectAuto', 'purchaseRequirement',
|
||||||
'meetingMinutes', 'feasibilityReport', 'meetingMinutesUrgent',
|
'meetingMinutes', 'feasibilityReport', 'meetingMinutesUrgent',
|
||||||
@@ -1515,11 +1553,27 @@ const handleSubmit = async () => {
|
|||||||
'servicePublicSelectSchoolAuto', 'otherMaterials'
|
'servicePublicSelectSchoolAuto', 'otherMaterials'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// 收集所有文件ID到一个数组中
|
||||||
|
const allFileIds: string[] = [];
|
||||||
|
|
||||||
fileFields.forEach(field => {
|
fileFields.forEach(field => {
|
||||||
if (submitData[field]) {
|
if (submitData[field]) {
|
||||||
submitData[field] = getFileIdsArray(submitData[field]);
|
const ids = getFileIdsArray(submitData[field]);
|
||||||
|
console.log(`字段 ${field} 的文件ID:`, ids);
|
||||||
|
// 将文件字段转换为ID数组
|
||||||
|
submitData[field] = ids;
|
||||||
|
// 同时收集到总数组中
|
||||||
|
allFileIds.push(...ids);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 添加fileIds字段,包含所有文件ID
|
||||||
|
if (allFileIds.length > 0) {
|
||||||
|
submitData.fileIds = allFileIds;
|
||||||
|
console.log('所有文件ID:', allFileIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('提交数据:', submitData);
|
||||||
|
|
||||||
await addObj(submitData);
|
await addObj(submitData);
|
||||||
useMessage().success('提交成功');
|
useMessage().success('提交成功');
|
||||||
|
|||||||
Reference in New Issue
Block a user