chooseImageInApp
App 端选图 / 拍照适配器,被 showImage 内部调用。
前置依赖
typescript
interface ImageInAppDeps {
chooseImage: UniApp['chooseImage']
log: Console['log']
error: Console['error']
}| 依赖 | 说明 |
|---|---|
chooseImage | UniApp 选图 API |
log / error | 成功 / 失败日志 |
chooseImageInApp
函数签名
typescript
function chooseImageInApp(
options?: ImageOptions,
deps: ImageInAppDeps
): Promise<ImageResult>参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
options.count | number | 否 | 最多可选张数,默认 9 |
options.sizeType | ('original' | 'compressed')[] | 否 | 默认 ['original', 'compressed'] |
options.sourceType | ('album' | 'camera')[] | 否 | 默认 ['album', 'camera'] |
deps | ImageInAppDeps | 是 | 环境依赖 |
返回值
| 类型 | 说明 |
|---|---|
Promise<ImageResult> | 含规范化后的 tempFilePaths、tempFiles 及 raw;失败 reject |
工作原理
- 调用
deps.chooseImage,传入 count / sizeType / sourceType 默认值。 - 成功回调中将
tempFilePaths、tempFiles归一化为数组结构(兼容字符串或单对象响应)。 tempFiles条目统一为{ path, size, type?, name? },路径字段兼容path与tempFilePath。- 失败时 reject 并附带
errMsg与原始错误raw。