From 1f0d537c80ffbd5c4245369189aa5d2fe6be9303 Mon Sep 17 00:00:00 2001 From: zhoulinf <2507241354@qq.com> Date: Tue, 4 Aug 2026 17:45:47 +0800 Subject: [PATCH] =?UTF-8?q?CRM=5F26-08-05#story#9126,=E8=BD=A6=E8=BE=86?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E3=80=81=E6=9C=8D=E5=8A=A1=E5=95=86=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=B3=BB=E7=BB=9F=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/index/vehicleAdd.vue | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/views/index/vehicleAdd.vue b/src/views/index/vehicleAdd.vue index 789b3067..a7c8f43f 100644 --- a/src/views/index/vehicleAdd.vue +++ b/src/views/index/vehicleAdd.vue @@ -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) - this.cameraGuideType = type - this.cameraGuideVisible = true - } else { + async onLicenseSlotClick(type) { // 行驶证三槽位点击拦截:前置探测相机,可用才进引导页,否则直接降级系统选择器 + this.cameraGuideType = type + 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)