Browse Source

拍照和视频的数据调整

dev
wangmingyong@163.com 2 weeks ago
parent
commit
556ad37fe3
  1. 25
      zdxt-web-client/zdxt-efcode-enterprise-app/src/util/w6sMedia.js

25
zdxt-web-client/zdxt-efcode-enterprise-app/src/util/w6sMedia.js

@ -41,6 +41,13 @@ export const ensureW6sAuth = () => {
const signature = sha1(str).toString().toLowerCase() const signature = sha1(str).toString().toLowerCase()
// SDK 默认接口超时仅 5s,getLocation 等 API 未在 5s 内回调会报"接口调用超时"
// 且 takePhotoAndAddWaterMark 内部会先调 getLocation,必须放宽超时
w6s.init({
auth: true,
timeout: 5 * 60 * 1000, // 5 分钟,覆盖拍照+定位全流程
})
w6s.config({ w6s.config({
access_key: access_key, access_key: access_key,
nonce: nonce, nonce: nonce,
@ -80,8 +87,10 @@ export const takePhotoWithWaterMark = async () => {
locationEnable: true, locationEnable: true,
success: (res) => { success: (res) => {
console.log('[w6sMedia] takePhotoAndAddWaterMark success 原始返回:', res) console.log('[w6sMedia] takePhotoAndAddWaterMark success 原始返回:', res)
console.log('[w6sMedia] 返回字段 imageURL:', res?.imageURL, 'key:', res?.key, 'imageInfo:', res?.imageInfo) // 实际返回结构为 { result: { imageURL, key, imageInfo, mediaId } }(SDK jsonParser 包了一层 result)
resolve(res) const result = res?.result || res || {}
console.log('[w6sMedia] 返回字段 imageURL:', result?.imageURL, 'key:', result?.key, 'imageInfo:', result?.imageInfo)
resolve(result)
}, },
fail: (err) => { fail: (err) => {
console.error('[w6sMedia] takePhotoAndAddWaterMark fail:', err) console.error('[w6sMedia] takePhotoAndAddWaterMark fail:', err)
@ -110,15 +119,21 @@ export const startVideoRecorder = async ({
front, front,
success: (res) => { success: (res) => {
console.log('[w6sMedia] startVideoRecoder success 原始返回:', res) console.log('[w6sMedia] startVideoRecoder success 原始返回:', res)
const info = res?.info || {} // 实际返回结构为 { result: { code, message, info } }(SDK jsonParser 会包一层 result),而非 d.ts 声明的 { info }
const result = res?.result || res || {}
const info = result?.info || {}
if (!info.video_path) { if (!info.video_path) {
reject(new Error('录制未生成视频文件')) reject(new Error('录制未生成视频文件'))
return return
} }
// 客户端返回的是裸绝对路径(如 /data/data/.../xxx.mp4),FileTransfer 需要 file:// 前缀
const rawPath = info.video_path
const videoPath = /^file:\/\//.test(rawPath) ? rawPath : `file://${rawPath}`
// 从路径提取文件名(可能带查询参数) // 从路径提取文件名(可能带查询参数)
const name = (info.video_path.split('/').pop() || '').split('?')[0] || `video-${Date.now()}.mp4` const name = (videoPath.split('/').pop() || '').split('?')[0] || `video-${Date.now()}.mp4`
console.log('[w6sMedia] 解析出 video_path:', videoPath, 'name:', name)
resolve({ resolve({
video_path: info.video_path, video_path: videoPath,
video_duration: info.video_duration, video_duration: info.video_duration,
video_size: info.video_size, video_size: info.video_size,
video_thumbnail: info.video_thumbnail, video_thumbnail: info.video_thumbnail,

Loading…
Cancel
Save