You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.3 KiB

import * as w6s from 'szient-js-sdk'
import { baseUrl } from '@/config/env'
import { $globalStore } from '@/common/globalStore'
// 拍照并加水印(时间戳 + 经纬度自动叠加到照片)
export const takePhotoWithWaterMark = ({
content = '',
fontSize = 14,
color = '#FF5858',
timeEnable = true,
locationEnable = true,
} = {}) => new Promise((resolve, reject) => {
w6s.image.takePhotoAndAddWaterMark({
content,
fontSize,
color,
markDisable: false,
timeEnable,
locationEnable,
success: resolve,
fail: reject,
})
})
// 录制视频
export const startVideoRecorder = ({
duration = 60,
quality = 1, // 0 高清 / 1 一般 / 2 流畅
front = false,
syncSystemAlbum = false,
} = {}) => new Promise((resolve, reject) => {
w6s.video.startVideoRecoder({
duration,
quality,
front,
sync_system_album: syncSystemAlbum,
success: resolve,
fail: reject,
})
})
// 获取定位(经纬度)
export const getLocation = () => new Promise((resolve, reject) => {
w6s.location.getLocation({ success: resolve, fail: reject })
})
// 上传本地文件到后端 /app-enf/common/file/upload
// 使用 w6s.file.upload(Cordova FileTransfer),直接传本地路径,无需 base64 转换
export const uploadLocalFileToBackend = ({
fileURL,
fileName = 'upload',
mimeType = 'image/jpeg',
}) => 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}`
const opts = new window.FileUploadOptions()
opts.fileKey = 'file'
opts.fileName = fileName
opts.mimeType = mimeType
opts.headers = {
Authorization: token ? `Bearer ${token}` : '',
clientid: '9e6eb24cd4e169a98b0d2cd8034d877b',
}
const fileIns = new w6s.file.upload(opts)
fileIns.upload({
fileURL,
server,
trustAllHosts: false,
success: (res) => {
// Cordova FileTransfer 返回 res.response 为字符串
try {
const parsed = typeof res.response === 'string' ? JSON.parse(res.response) : res.response
resolve(parsed)
} catch (e) {
resolve(res.response)
}
},
fail: reject,
})
})