Compare commits
2
Commits
614bb875eb
...
1f0d537c80
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f0d537c80 | ||
|
|
cad1bcc505 |
@@ -944,14 +944,29 @@ export default {
|
|||||||
return compressedFile;
|
return compressedFile;
|
||||||
},
|
},
|
||||||
isCameraSupported() { // 是否支持 getUserMedia(不支持则降级系统选择器)
|
isCameraSupported() { // 是否支持 getUserMedia(不支持则降级系统选择器)
|
||||||
return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)
|
return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) && window.isSecureContext !== false
|
||||||
},
|
},
|
||||||
onLicenseSlotClick(type) { // 行驶证三槽位点击拦截:支持相机进引导页,不支持降级原系统选择器
|
async onLicenseSlotClick(type) { // 行驶证三槽位点击拦截:前置探测相机,可用才进引导页,否则直接降级系统选择器
|
||||||
if (this.isCameraSupported()) {
|
|
||||||
this.cameraGuideType = type
|
this.cameraGuideType = type
|
||||||
this.cameraGuideVisible = true
|
if (!this.isCameraSupported()) {
|
||||||
} else {
|
// 不支持 getUserMedia(如 iOS 微信、非 HTTPS、老 WebView):直接调系统选择器
|
||||||
this.triggerNativeUpload(type)
|
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 的原生文件选择
|
triggerNativeUpload(type) { // 主动触发对应 uploader 的原生文件选择
|
||||||
@@ -993,10 +1008,8 @@ export default {
|
|||||||
cancelButtonText: '从相册选择',
|
cancelButtonText: '从相册选择',
|
||||||
confirmButtonColor: '#354D93',
|
confirmButtonColor: '#354D93',
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// 重新打开拍摄引导(等弹层关闭状态先刷新,确保 visible 变化被组件感知)
|
// 重新走前置探测,探测通过才打开拍摄引导
|
||||||
this.$nextTick(() => {
|
this.onLicenseSlotClick(this.cameraGuideType)
|
||||||
this.cameraGuideVisible = true
|
|
||||||
})
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
// 降级为系统选择器
|
// 降级为系统选择器
|
||||||
this.triggerNativeUpload(this.cameraGuideType)
|
this.triggerNativeUpload(this.cameraGuideType)
|
||||||
|
|||||||
Reference in New Issue
Block a user