提交 14f3378e 编写于 作者: inkwalk's avatar inkwalk

feat(App): compressImage

上级 51d52eb2
......@@ -53,6 +53,7 @@ export * from './protocols/media/getVideoInfo'
export * from './protocols/media/saveImageToPhotosAlbum'
export * from './protocols/media/saveVideoToPhotosAlbum'
export * from './protocols/media/getRecorderManager'
export * from './protocols/media/compressImage'
export * from './protocols/network/request'
export * from './protocols/network/downloadFile'
......
import { getRealPath } from '@dcloudio/uni-platform'
export const API_COMPRESS_IMAGE = 'compressImage'
export type API_TYPE_COMPRESS_IMAGE = typeof uni.compressImage
export const CompressImageOptions: ApiOptions<API_TYPE_COMPRESS_IMAGE> = {
formatArgs: {
src(src, params) {
params.src = getRealPath(src)
},
},
}
export const CompressImageProtocol: ApiProtocol<API_TYPE_COMPRESS_IMAGE> = {
src: {
type: String,
required: true,
},
}
......@@ -17,6 +17,7 @@ export * from './media/previewImage'
export * from './media/getRecorderManager'
export * from './media/saveVideoToPhotosAlbum'
export * from './media/saveImageToPhotosAlbum'
export * from './media/compressImage'
export * from './keyboard/keyboard'
......
import { extend } from '@vue/shared'
import { getFileName } from '../../../helpers/file'
import { TEMP_PATH } from '../constants'
import {
API_COMPRESS_IMAGE,
API_TYPE_COMPRESS_IMAGE,
defineAsyncApi,
CompressImageOptions,
CompressImageProtocol,
} from '@dcloudio/uni-api'
export const compressImage = defineAsyncApi<API_TYPE_COMPRESS_IMAGE>(
API_COMPRESS_IMAGE,
(options, { resolve, reject }) => {
const dst = `${TEMP_PATH}/compressed/${Date.now()}_${getFileName(
options.src
)}`
plus.zip.compressImage(
extend({}, options, {
dst,
}),
() => {
resolve({
tempFilePath: dst,
})
},
reject
)
},
CompressImageProtocol,
CompressImageOptions
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册