| | |
| | | |
| | | axios.post(uploadUrl, formData, { headers: uploadHeaders }) |
| | | .then(res => { |
| | | console.log('qweqweqweqw/////',res); |
| | | |
| | | try { |
| | | onSuccess(res.data); |
| | | } catch (e) { |
| | |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | export function getFullUrl(url) { |
| | | if (!url) return ''; |
| | | if (!url) return ""; |
| | | if (/^https?:\/\//.test(url)) return url; |
| | | return apiConfig.showImgUrl + url; |
| | | return getAllocateIp() + url; |
| | | } |
| | | |
| | | /** |
| | | * 通用文件下载方法 |
| | | * @param {string} url 文件的下载地址(支持相对和绝对路径) |
| | |
| | | if (!url) return; |
| | | // 处理相对路径 |
| | | const fullUrl = getFullUrl(url); |
| | | console.log('fullUrl fullUrl',fullUrl) |
| | | const a = document.createElement('a'); |
| | | a.href = fullUrl; |
| | | if (name) { |
| | |
| | | if (!url) return; |
| | | const fullUrl = getFullUrl(url); |
| | | window.open(fullUrl, '_blank'); |
| | | } |
| | | } |
| | | /** |
| | | * 判断文件是否为图片 |
| | | * @param {string} url 文件URL |
| | | * @returns {boolean} 是否为图片文件 |
| | | */ |
| | | export function isImageFile(url) { |
| | | if (!url) return false; |
| | | const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg']; |
| | | const lowerUrl = url.toLowerCase(); |
| | | return imageExtensions.some(ext => lowerUrl.includes(ext)); |
| | | } |
| | | |
| | | export function getAllocateIp() { |
| | | const userInfo = JSON.parse(sessionStorage.getItem("userInfo") || "{}"); |
| | | return userInfo.allocateIp ? 'http://'+userInfo.allocateIp +':11222/images/' : apiConfig.showImgUrl; |
| | | } |