From 8b5c4b4aaaf3c438a0b2dcd2d7b8dc7f70e2d23c Mon Sep 17 00:00:00 2001 From: "wangmingyong@163.com" Date: Thu, 20 Aug 2026 17:57:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E7=8E=B0=E5=9C=BA=E6=8B=8D=E7=85=A7?= =?UTF-8?q?=E5=92=8C=E8=A7=86=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/util/w6sMedia.js | 47 ++++++++++++++++--- .../nos/components/NosDetailMaterialsTab.vue | 27 ++++++++--- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/zdxt-web-client/zdxt-efcode-enterprise-app/src/util/w6sMedia.js b/zdxt-web-client/zdxt-efcode-enterprise-app/src/util/w6sMedia.js index d7f2ddb3..9e75baf9 100644 --- a/zdxt-web-client/zdxt-efcode-enterprise-app/src/util/w6sMedia.js +++ b/zdxt-web-client/zdxt-efcode-enterprise-app/src/util/w6sMedia.js @@ -73,7 +73,9 @@ export const takePhotoWithWaterMark = async ({ timeEnable = true, locationEnable = true, } = {}) => { + console.log('[w6sMedia] takePhotoWithWaterMark 开始, 入参:', { content, fontSize, color, timeEnable, locationEnable }) await ensureW6sAuth() + console.log('[w6sMedia] 鉴权完成, 准备调起拍照') return new Promise((resolve, reject) => { w6s.image.takePhotoAndAddWaterMark({ content, @@ -82,8 +84,15 @@ export const takePhotoWithWaterMark = async ({ markDisable: false, timeEnable, locationEnable, - success: resolve, - fail: reject, + success: (res) => { + console.log('[w6sMedia] takePhotoAndAddWaterMark success 原始返回:', res) + console.log('[w6sMedia] 返回字段 imageURL:', res?.imageURL, 'key:', res?.key, 'imageInfo:', res?.imageInfo) + resolve(res) + }, + fail: (err) => { + console.error('[w6sMedia] takePhotoAndAddWaterMark fail:', err) + reject(err) + }, }) }) } @@ -95,15 +104,23 @@ export const startVideoRecorder = async ({ front = false, syncSystemAlbum = false, } = {}) => { + console.log('[w6sMedia] startVideoRecorder 开始, 入参:', { duration, quality, front, syncSystemAlbum }) await ensureW6sAuth() + console.log('[w6sMedia] 录制前鉴权完成, 准备调起录制') return new Promise((resolve, reject) => { w6s.video.startVideoRecoder({ duration, quality, front, sync_system_album: syncSystemAlbum, - success: resolve, - fail: reject, + success: (res) => { + console.log('[w6sMedia] startVideoRecoder success 原始返回:', res) + resolve(res) + }, + fail: (err) => { + console.error('[w6sMedia] startVideoRecoder fail:', err) + reject(err) + }, }) }) } @@ -123,12 +140,15 @@ export const uploadLocalFileToBackend = async ({ fileName = 'upload', mimeType = 'image/jpeg', }) => { + console.log('[w6sMedia] uploadLocalFileToBackend 开始, 入参:', { fileURL, fileName, mimeType }) await ensureW6sAuth() + console.log('[w6sMedia] 上传前鉴权完成') return new Promise((resolve, reject) => { const token = $globalStore.useCommon?.token || '' // w6s.file.upload 需要完整 URL const api = `${baseUrl}/app-enf/common/file/upload` const server = /^https?:/.test(api) ? api : `${window.location.origin}${api}` + console.log('[w6sMedia] 上传目标 server:', server, 'token 存在:', !!token) const opts = new window.FileUploadOptions() opts.fileKey = 'file' @@ -138,21 +158,36 @@ export const uploadLocalFileToBackend = async ({ Authorization: token ? `Bearer ${token}` : '', clientid: '9e6eb24cd4e169a98b0d2cd8034d877b', } - const fileIns = new w6s.file.upload(opts) + console.log('[w6sMedia] FileUploadOptions 构造完成:', { fileKey: opts.fileKey, fileName: opts.fileName, mimeType: opts.mimeType, headers: opts.headers }) + + let fileIns + try { + fileIns = new w6s.file.upload(opts) + } catch (e) { + console.error('[w6sMedia] new w6s.file.upload 抛错:', e) + reject(e) + return + } fileIns.upload({ fileURL, server, trustAllHosts: false, success: (res) => { + console.log('[w6sMedia] file.upload success 原始返回:', res) // Cordova FileTransfer 返回 res.response 为字符串 try { const parsed = typeof res.response === 'string' ? JSON.parse(res.response) : res.response + console.log('[w6sMedia] 解析后的上传响应:', parsed) resolve(parsed) } catch (e) { + console.warn('[w6sMedia] 响应 JSON 解析失败, 返回原始 response:', res.response) resolve(res.response) } }, - fail: reject, + fail: (err) => { + console.error('[w6sMedia] file.upload fail:', err) + reject(err) + }, }) }) } diff --git a/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/nos/components/NosDetailMaterialsTab.vue b/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/nos/components/NosDetailMaterialsTab.vue index ea3791ff..a9122ccd 100644 --- a/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/nos/components/NosDetailMaterialsTab.vue +++ b/zdxt-web-client/zdxt-efcode-enterprise-app/src/views/enterprise/nos/components/NosDetailMaterialsTab.vue @@ -178,10 +178,12 @@ @@ -323,7 +325,7 @@ const isProd = computed(() => appEnv === 'prod') const showUploadAction = ref(false) const activeUploadItem = ref(null) const uploadActions = [ - { name: '拍照(带水印与经纬度)' }, + { name: '拍照' }, { name: '录制视频' }, ] @@ -401,23 +403,27 @@ const onOpenUploadAction = (item) => { const onSelectUploadAction = ({ name }) => { const item = activeUploadItem.value if (!item) return - if (name === '拍照(带水印与经纬度)') onTakePhoto(item) + if (name === '拍照') onTakePhoto(item) else if (name === '录制视频') onRecordVideo(item) } // 拍照带水印(时间戳 + 经纬度自动叠加) const onTakePhoto = async (item) => { + console.log('[NosDetail] onTakePhoto 开始, item:', item, 'fileList:', item?.fileList) try { const watermarkContent = $globalStore.useCommon?.enterpriseName || '深圳市行政执法监督码' const res = await takePhotoWithWaterMark({ content: watermarkContent }) + console.log('[NosDetail] 拍照返回 res:', res, 'imageURL:', res?.imageURL, 'key:', res?.key) + const localPath = res.imageURL || res.key + console.log('[NosDetail] 解析出的 localPath:', localPath) await pushSdkFileToFileList(item, { - localPath: res.imageURL || res.key, + localPath, fileName: `photo-${Date.now()}.jpg`, mimeType: 'image/jpeg', isImage: true, }) } catch (err) { - console.error('w6s 拍照失败', err) + console.error('[NosDetail] w6s 拍照失败', err) showToast('拍照失败或已取消') } } @@ -441,7 +447,11 @@ const onRecordVideo = async (item) => { // 通用:把 SDK 返回的本地文件上传后端 → 写入 fileList const pushSdkFileToFileList = async (item, { localPath, fileName, mimeType, isImage }) => { - if (!localPath) return + console.log('[NosDetail] pushSdkFileToFileList 开始, 入参:', { localPath, fileName, mimeType, isImage }) + if (!localPath) { + console.warn('[NosDetail] pushSdkFileToFileList localPath 为空, 直接返回') + return + } const fileObj = { url: '', isImage, @@ -449,22 +459,27 @@ const pushSdkFileToFileList = async (item, { localPath, fileName, mimeType, isIm message: '上传中...', } item.fileList.push(fileObj) + console.log('[NosDetail] 已 push 到 fileList, 当前 fileList 长度:', item.fileList.length, 'fileObj:', fileObj) try { const res = await uploadLocalFileToBackend({ fileURL: localPath, fileName, mimeType }) + console.log('[NosDetail] 上传后端返回 res:', res) const data = res && res.data ? res.data : res const filePath = typeof data === 'string' ? data : (data && (data.data || data.url || data.fileUrl || data.path)) || '' + console.log('[NosDetail] 解析出的 filePath:', filePath, 'data:', data) if (filePath) { fileObj.url = toFullFileUrl(filePath) fileObj.status = 'done' fileObj.message = '' + console.log('[NosDetail] 上传成功, fileObj.url:', fileObj.url) } else { fileObj.status = 'failed' fileObj.message = '上传失败' + console.warn('[NosDetail] 上传失败: filePath 为空') } } catch (err) { - console.error('w6s 上传后端失败', err) + console.error('[NosDetail] w6s 上传后端失败:', err) fileObj.status = 'failed' fileObj.message = '上传失败' }