CRM_26-08-05#story#9126,车辆管理、服务商管理系统需求

This commit is contained in:
zlf
2026-08-04 17:45:47 +08:00
parent cad1bcc505
commit 1f0d537c80
+22 -10
View File
@@ -944,15 +944,29 @@ export default {
return compressedFile;
},
isCameraSupported() { // 是否支持 getUserMedia(不支持则降级系统选择器)
return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)
return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) && window.isSecureContext !== false
},
onLicenseSlotClick(type) { // 行驶证三槽位点击拦截:支持相机进引导页,不支持降级系统选择器
if (this.isCameraSupported()) {
console.log('navigator.mediaDevices.getUserMedia', navigator.mediaDevices.getUserMedia)
async onLicenseSlotClick(type) { // 行驶证三槽位点击拦截:前置探测相机,可用才进引导页,否则直接降级系统选择器
this.cameraGuideType = type
this.cameraGuideVisible = true
} else {
if (!this.isCameraSupported()) {
// 不支持 getUserMedia(如 iOS 微信、非 HTTPS、老 WebView):直接调系统选择器
this.triggerNativeUpload(type)
return
}
try {
// 前置真实探测相机可用性,避免进入拍摄引导页后黑屏;拿到流立即释放
const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' }, audio: false })
stream.getTracks().forEach(t => t.stop())
this.cameraGuideVisible = true
} catch (e) {
console.error('probe getUserMedia error:', e)
if (e && (e.name === 'NotAllowedError' || e.name === 'SecurityError')) {
// 权限被拒:弹框询问(重试/从相册选择)
this.onCameraFallback()
} else {
// 无摄像头、被占用等其他异常:直接降级系统选择器
this.triggerNativeUpload(type)
}
}
},
triggerNativeUpload(type) { // 主动触发对应 uploader 的原生文件选择
@@ -994,10 +1008,8 @@ export default {
cancelButtonText: '从相册选择',
confirmButtonColor: '#354D93',
}).then(() => {
// 重新打开拍摄引导(等弹层关闭状态先刷新,确保 visible 变化被组件感知)
this.$nextTick(() => {
this.cameraGuideVisible = true
})
// 重新走前置探测,探测通过才打开拍摄引导
this.onLicenseSlotClick(this.cameraGuideType)
}).catch(() => {
// 降级为系统选择器
this.triggerNativeUpload(this.cameraGuideType)