From 511c004c33f22dae8b47c14b85d85f89e0850374 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Fri, 17 Sep 2021 11:46:37 +0800 Subject: [PATCH] =?UTF-8?q?chore(App):=20chooseImage=E3=80=81chooseVideo?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vue-cli-plugin-uni/commands/build.js | 2 +- .../service/api/media/choose-image.js | 43 ++------------ .../service/api/media/choose-video.js | 57 +++++++------------ 3 files changed, 25 insertions(+), 77 deletions(-) diff --git a/packages/vue-cli-plugin-uni/commands/build.js b/packages/vue-cli-plugin-uni/commands/build.js index 6d5acabd1..e3cdd53aa 100644 --- a/packages/vue-cli-plugin-uni/commands/build.js +++ b/packages/vue-cli-plugin-uni/commands/build.js @@ -133,7 +133,7 @@ async function build (args, api, options) { log() if (!runByHBuilderX && !runByAliIde) { - logWithSpinner(uniI18n.__('pluginUni.startCompileProjectToPlatform', { 0: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM, 1: process.env.UNI_MP_PLUGIN ? uniI18n.__('platform') : uniI18n.__('plugin') })) + logWithSpinner(uniI18n.__('pluginUni.startCompileProjectToPlatform', { 0: process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM, 1: process.env.UNI_MP_PLUGIN ? uniI18n.__('plugin') : uniI18n.__('platform') })) } const targetDir = api.resolve(options.outputDir) diff --git a/src/platforms/app-plus/service/api/media/choose-image.js b/src/platforms/app-plus/service/api/media/choose-image.js index 5e9822eb7..103e8abd8 100644 --- a/src/platforms/app-plus/service/api/media/choose-image.js +++ b/src/platforms/app-plus/service/api/media/choose-image.js @@ -7,8 +7,7 @@ import { } from '../../bridge' import { - warpPlusErrorCallback, - getFileName + warpPlusErrorCallback } from '../util' import { @@ -28,24 +27,6 @@ function getFileInfo (filePath) { }) } -function compressImage (tempFilePath) { - const dstPath = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(tempFilePath)}` - return new Promise((resolve) => { - plus.nativeUI.showWaiting() - plus.zip.compressImage({ - src: tempFilePath, - dst: dstPath, - overwrite: true - }, () => { - plus.nativeUI.closeWaiting() - resolve(dstPath) - }, () => { - plus.nativeUI.closeWaiting() - resolve(tempFilePath) - }) - }) -} - export function chooseImage ({ count, sizeType, @@ -57,7 +38,6 @@ export function chooseImage ({ function successCallback (paths) { const tempFiles = [] const tempFilePaths = [] - // plus.zip.compressImage 压缩文件并发调用在iOS端容易出现问题(图像错误、闪退),改为队列执行 Promise.all(paths.map((path) => getFileInfo(path))) .then((filesInfo) => { filesInfo.forEach((file, index) => { @@ -77,25 +57,12 @@ export function chooseImage ({ function openCamera () { const camera = plus.camera.getCamera() - camera.captureImage(path => { - // fix By Lxh 暂时添加拍照压缩逻辑,等客户端增加逻辑后修改 - // 判断是否需要压缩 - if (sizeType && sizeType.includes('compressed')) { - return getFileInfo(path).then(({ size }) => { - // 压缩阈值 0.5 兆 - const THRESHOLD = 1024 * 1024 * 0.5 - return size && size > THRESHOLD - ? compressImage(path).then(dstPath => successCallback([dstPath])) - : successCallback([path]) - }).catch(errorCallback) - } - - return successCallback([path]) - }, - errorCallback, { + camera.captureImage(path => successCallback([path]), + errorCallback, { filename: TEMP_PATH + '/camera/', resolution: 'high', - crop + crop, + sizeType }) } diff --git a/src/platforms/app-plus/service/api/media/choose-video.js b/src/platforms/app-plus/service/api/media/choose-video.js index 2a9b1c56b..2dc883bea 100644 --- a/src/platforms/app-plus/service/api/media/choose-video.js +++ b/src/platforms/app-plus/service/api/media/choose-video.js @@ -7,8 +7,7 @@ import { } from '../../bridge' import { - warpPlusErrorCallback, - getFileName + warpPlusErrorCallback } from '../util' import { @@ -24,40 +23,20 @@ export function chooseVideo ({ const errorCallback = warpPlusErrorCallback(callbackId, 'chooseVideo', 'cancel') function successCallback (tempFilePath = '') { - const filename = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(tempFilePath)}` - const compressVideo = compressed ? new Promise((resolve) => { - plus.zip.compressVideo({ - src: tempFilePath, - filename, - quality: 'medium' - }, ({ tempFilePath }) => { - resolve(tempFilePath) - }, () => { - resolve(tempFilePath) - }) - }) : Promise.resolve(tempFilePath) - if (compressed) { - plus.nativeUI.showWaiting() - } - compressVideo.then(tempFilePath => { - if (compressed) { - plus.nativeUI.closeWaiting() - } - plus.io.getVideoInfo({ - filePath: tempFilePath, - success (videoInfo) { - const result = { - errMsg: 'chooseVideo:ok', - tempFilePath: tempFilePath - } - result.size = videoInfo.size - result.duration = videoInfo.duration - result.width = videoInfo.width - result.height = videoInfo.height - invoke(callbackId, result) - }, - fail: errorCallback - }) + plus.io.getVideoInfo({ + filePath: tempFilePath, + success (videoInfo) { + const result = { + errMsg: 'chooseVideo:ok', + tempFilePath: tempFilePath + } + result.size = videoInfo.size + result.duration = videoInfo.duration + result.width = videoInfo.width + result.height = videoInfo.height + invoke(callbackId, result) + }, + fail: errorCallback }) } @@ -69,7 +48,8 @@ export function chooseVideo ({ multiple: true, maximum: 1, filename: TEMP_PATH + '/gallery/', - permissionAlert: true + permissionAlert: true, + videoCompress: compressed }) } @@ -78,7 +58,8 @@ export function chooseVideo ({ plusCamera.startVideoCapture(successCallback, errorCallback, { index: camera === 'front' ? 2 : 1, videoMaximumDuration: maxDuration, - filename: TEMP_PATH + '/camera/' + filename: TEMP_PATH + '/camera/', + videoCompress: compressed }) } -- GitLab