import { uploadFile } from '@/api/system/oss'; import { VXETable, VxeColumnPropTypes } from 'vxe-table'; export const cmToPx = (cm: number, dpi = 96) => { return (cm * dpi) / 2.54; }; export const importFileGetUrl = async (types: string[] = ['xlsx', 'xls']) => { const { file } = await VXETable.readFile({ types }); const curPath = URL.createObjectURL(file); const formData = new FormData(); formData.append('file', file, file.name); const { data } = await uploadFile(formData); return data; }; export const importFileGetUrls = async (types: string[] = ['png', 'jpg']) => { const { files } = await VXETable.readFile({ types, multiple: true }); const promises = Array.from(files).map((file: File) => importFileGetUrlByFile(file)); return Promise.all(promises); }; // 传入file, file.name 利用formData上传,用 export const importFileGetUrlByFile = async (file: File) => { const formData = new FormData(); formData.append('file', file, file.name); return uploadFile(formData); }; export const filterBool = (val: string) => { if (val) { return +val ? '是' : '否'; } else { return '-'; } }; export const colNoData: VxeColumnPropTypes.Formatter = ({ cellValue }) => { if (cellValue) { return cellValue; } else { return '-'; } }; export const formatterfilterBool: VxeColumnPropTypes.Formatter = ({ cellValue }) => { if (cellValue) { return +cellValue ? '是' : '否'; } else { return '-'; } }; export const formatWarehouseRow = (warehouseInfo: any) => { if (warehouseInfo && warehouseInfo.length) { const strTem: string[] = []; for (let i = 0; i < warehouseInfo.length; i++) { const { warehouseName = '', shelvesName = '', warehouseSn = '', shelvesSn = '' } = warehouseInfo[i]; const strKf = warehouseName ? `${warehouseName}${warehouseSn ? '(' + warehouseSn + ')' : ''}` : ''; const strCk = shelvesName ? `${shelvesName}${shelvesSn ? '(' + shelvesSn + ')' : ''}` : ''; strTem.push(strKf + (strCk ? '/' + strCk : '')); } return strTem.toString(); } else { return '-'; } }; // 格式化产地 export const formatOrigin = (adcdCodeDesc: any, nationTypeDesc: any) => { if (nationTypeDesc === '中国大陆' || !nationTypeDesc) { return adcdCodeDesc || '-'; } else { return nationTypeDesc || '-'; } }; // 根据传入url获取文件后缀名,根据文件后缀名返回相应的图片icon export const getFileIconByUrl = (url: string) => { const fileExtension = url.substring(url.lastIndexOf('.') + 1).toLowerCase(); const iconMap: Record = { jpg: 'jpg', jpeg: 'jpg', png: 'png', gif: 'jpg', pdf: 'pdf', doc: 'doc', docx: 'doc', xls: 'xlsx', xlsx: 'xlsx', txt: 'txt', // 大写后缀映射 JPG: 'jpg', JPEG: 'jpg', PNG: 'png', GIF: 'jpg', PDF: 'pdf', DOC: 'doc', DOCX: 'doc', XLS: 'xlsx', XLSX: 'xlsx', TXT: 'txt' }; return `https://ta.zycpzs.cn/oss-file/smart-trace/szyy/images/file-type-sub/${iconMap[fileExtension]}.png`; // 默认图标 };