客户图片预览
This commit is contained in:
@@ -89,50 +89,31 @@ 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 直链展示。
|
||||
* 预览客户照片(后端从 MinIO 拉流)。
|
||||
* 方式一:传 url(与 uploadPhoto 返回的 MinIO 访问 URL 一致)。
|
||||
* 方式二:传 id + photoType(front | side | life),由后端读库再拉 MinIO。
|
||||
* @param {{ url?: string, id?: string|number, photoType?: 'front'|'side'|'life' }}=} params
|
||||
*/
|
||||
export function loadCustomerPhotoForDisplay(storedUrl) {
|
||||
if (storedUrl == null || String(storedUrl).trim() === '') {
|
||||
return Promise.reject(new Error('EMPTY_URL'))
|
||||
export function previewCustomerPhoto(params) {
|
||||
const p = params && typeof params === 'object' ? params : {}
|
||||
const query = {}
|
||||
if (p.url != null && String(p.url).trim() !== '') {
|
||||
query.url = String(p.url).trim()
|
||||
}
|
||||
const raw = String(storedUrl).trim()
|
||||
const isAbs = /^https?:\/\//i.test(raw)
|
||||
if (isAbs && !isLikelyBackendOrProxyAsset(raw)) {
|
||||
return Promise.resolve({ useDirect: true, url: raw })
|
||||
if (p.id != null && String(p.id).trim() !== '') {
|
||||
query.id = String(p.id).trim()
|
||||
}
|
||||
|
||||
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)
|
||||
if (p.photoType != null && String(p.photoType).trim() !== '') {
|
||||
query.photoType = String(p.photoType).trim()
|
||||
}
|
||||
return request({
|
||||
url: path,
|
||||
url: '/customerManagement/previewPhoto',
|
||||
method: 'get',
|
||||
params: query,
|
||||
responseType: 'blob',
|
||||
timeout: 120000
|
||||
}).then(blob => ({ useDirect: false, blob }))
|
||||
})
|
||||
}
|
||||
|
||||
/** 客户照片上传至 MinIO;id 可选,有则作为 query 传入;成功时响应 data 中含 url */
|
||||
|
||||
Reference in New Issue
Block a user