客户图片预览
This commit is contained in:
@@ -578,7 +578,7 @@ import {
|
||||
addCustomer,
|
||||
updateCustomer,
|
||||
uploadCustomerPhoto,
|
||||
loadCustomerPhotoForDisplay,
|
||||
previewCustomerPhoto,
|
||||
deleteCustomer,
|
||||
batchDeleteCustomer,
|
||||
exportCustomerFlow,
|
||||
@@ -989,16 +989,13 @@ export default {
|
||||
})
|
||||
if (!kind) return
|
||||
|
||||
const fieldMap = { front: 'frontPhotoUrl', side: 'sidePhotoUrl', life: 'lifePhotoUrl' }
|
||||
const titleMap = { front: '正面照片', side: '侧面照片', life: '生活照片' }
|
||||
const field = fieldMap[kind]
|
||||
const stored = field && row[field] ? String(row[field]).trim() : ''
|
||||
if (!stored) {
|
||||
this.$message.warning(`该客户未设置${titleMap[kind] || '该类型'}地址`)
|
||||
if (row.id == null || String(row.id).trim() === '') {
|
||||
this.$message.warning('无法预览:缺少客户ID')
|
||||
return
|
||||
}
|
||||
|
||||
this.photoPreviewTitle = `${row.customerName || '客户'} — ${titleMap[kind]}`
|
||||
this.photoPreviewTitle = `${row.customerName || '客户'} — ${titleMap[kind] || ''}`
|
||||
this.photoPreviewLoadError = false
|
||||
this.revokePhotoPreviewObjectUrl()
|
||||
this.photoPreviewSrc = ''
|
||||
@@ -1006,35 +1003,38 @@ export default {
|
||||
this.photoPreviewLoading = true
|
||||
|
||||
try {
|
||||
const result = await loadCustomerPhotoForDisplay(stored)
|
||||
if (result.useDirect) {
|
||||
this.photoPreviewSrc = result.url
|
||||
} else {
|
||||
const blob = result.blob
|
||||
if (!(blob instanceof Blob) || blob.size === 0) {
|
||||
this.$message.error('未获取到图片数据')
|
||||
return
|
||||
}
|
||||
const ct = (blob.type || '').toLowerCase()
|
||||
if (ct.includes('json') || ct === 'text/plain') {
|
||||
const text = await blob.text()
|
||||
let msg = '加载失败'
|
||||
try {
|
||||
const j = JSON.parse(text)
|
||||
msg = j.message || j.msg || msg
|
||||
} catch (e) {
|
||||
if (text) msg = text.slice(0, 200)
|
||||
}
|
||||
this.$message.error(msg)
|
||||
this.photoPreviewVisible = false
|
||||
return
|
||||
}
|
||||
this.photoPreviewObjectUrl = URL.createObjectURL(blob)
|
||||
this.photoPreviewSrc = this.photoPreviewObjectUrl
|
||||
const blob = await previewCustomerPhoto({ id: row.id, photoType: kind })
|
||||
if (!(blob instanceof Blob) || blob.size === 0) {
|
||||
this.$message.error('未获取到图片数据')
|
||||
this.photoPreviewVisible = false
|
||||
return
|
||||
}
|
||||
const ct = (blob.type || '').toLowerCase()
|
||||
if (ct.includes('json') || ct === 'text/plain') {
|
||||
const text = await blob.text()
|
||||
let msg = '加载失败'
|
||||
try {
|
||||
const j = JSON.parse(text)
|
||||
msg = j.message || j.msg || msg
|
||||
} catch (e) {
|
||||
if (text) msg = text.slice(0, 200)
|
||||
}
|
||||
this.$message.error(msg)
|
||||
this.photoPreviewVisible = false
|
||||
return
|
||||
}
|
||||
this.photoPreviewObjectUrl = URL.createObjectURL(blob)
|
||||
this.photoPreviewSrc = this.photoPreviewObjectUrl
|
||||
} catch (err) {
|
||||
console.error('加载客户照片失败:', err)
|
||||
this.$message.error((err && err.message) || '加载照片失败,请稍后重试')
|
||||
const status = err && err.response && err.response.status
|
||||
if (status === 404) {
|
||||
this.$message.warning('未找到该照片或客户未上传此类型照片')
|
||||
} else if (status === 400) {
|
||||
this.$message.warning('请求参数无效')
|
||||
} else {
|
||||
this.$message.error((err && err.message) || '加载照片失败,请稍后重试')
|
||||
}
|
||||
this.photoPreviewVisible = false
|
||||
} finally {
|
||||
this.photoPreviewLoading = false
|
||||
|
||||
Reference in New Issue
Block a user