增加客户照片上传的功能

This commit is contained in:
zhonghua.li
2026-05-02 19:03:59 +08:00
parent 836974fc31
commit c73a2535fb
2 changed files with 293 additions and 4 deletions

View File

@@ -89,6 +89,68 @@ export function updateCustomer(data) {
})
}
function isLikelyBackendOrProxyAsset(absoluteUrl) {
try {
const p = new URL(absoluteUrl).pathname || ''
return p.startsWith('/api/') || p.includes('/customerManagement')
} catch (e) {
return false
}
}
/**
* 按列表/详情中保存的地址拉取图片:相对路径或指向本系统接口的完整 URL 走 axios含 Token、业务头经 dev 代理);
* 其余完整 URL如公网图床、MinIO 外链)返回 { useDirect: true, url },由前端用 img 直链展示。
*/
export function loadCustomerPhotoForDisplay(storedUrl) {
if (storedUrl == null || String(storedUrl).trim() === '') {
return Promise.reject(new Error('EMPTY_URL'))
}
const raw = String(storedUrl).trim()
const isAbs = /^https?:\/\//i.test(raw)
if (isAbs && !isLikelyBackendOrProxyAsset(raw)) {
return Promise.resolve({ useDirect: true, url: raw })
}
let path = raw
if (isAbs) {
try {
const u = new URL(raw)
path = u.pathname + (u.search || '')
} catch (e) {
return Promise.reject(e)
}
}
if (!path.startsWith('/')) {
path = `/${path}`
}
if (path.startsWith('/api/')) {
path = path.slice(4)
}
return request({
url: path,
method: 'get',
responseType: 'blob',
timeout: 120000
}).then(blob => ({ useDirect: false, blob }))
}
/** 客户照片上传至 MinIOid 可选,有则作为 query 传入;成功时响应 data 中含 url */
export function uploadCustomerPhoto(customerId, file) {
const formData = new FormData()
formData.append('file', file)
const config = {
url: '/customerManagement/uploadPhoto',
method: 'post',
data: formData,
timeout: 120000
}
if (customerId != null && String(customerId).trim() !== '') {
config.params = { id: String(customerId).trim() }
}
return request(config)
}
// 获取客户统计信息
export function getCustomerStatistics() {
return request({