mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-05 19:41:45 +08:00
fix(uploader): fix chooseImage error in PC (#5477)
This commit is contained in:
parent
f197c5f3c3
commit
7498ed12c3
@ -1,5 +1,9 @@
|
||||
import { isDef, isNumber, isPlainObject, isPromise } from './validator';
|
||||
import { canIUseGroupSetData, canIUseNextTick } from './version';
|
||||
import {
|
||||
canIUseGroupSetData,
|
||||
canIUseNextTick,
|
||||
getSystemInfoSync,
|
||||
} from './version';
|
||||
|
||||
export { isDef } from './validator';
|
||||
export { getSystemInfoSync } from './version';
|
||||
@ -109,3 +113,5 @@ export function getCurrentPage<T>() {
|
||||
const pages = getCurrentPages();
|
||||
return pages[pages.length - 1] as T & WechatMiniprogram.Page.TrivialInstance;
|
||||
}
|
||||
|
||||
export const isPC = ['mac', 'windows'].includes(getSystemInfoSync().platform);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { pickExclude } from '../common/utils';
|
||||
import { pickExclude, isPC } from '../common/utils';
|
||||
import { isImageUrl, isVideoUrl } from '../common/validator';
|
||||
|
||||
export interface File {
|
||||
@ -45,13 +45,15 @@ export function isVideoFile(item: File): boolean {
|
||||
}
|
||||
|
||||
function formatImage(
|
||||
res: WechatMiniprogram.ChooseMediaSuccessCallbackResult
|
||||
res:
|
||||
| WechatMiniprogram.ChooseMediaSuccessCallbackResult
|
||||
| WechatMiniprogram.ChooseImageSuccessCallbackResult
|
||||
): File[] {
|
||||
return res.tempFiles.map((item) => ({
|
||||
...pickExclude(item, ['path']),
|
||||
type: 'image',
|
||||
url: item.tempFilePath,
|
||||
thumb: item.tempFilePath,
|
||||
url: item.tempFilePath || item.path,
|
||||
thumb: item.tempFilePath || item.path,
|
||||
}));
|
||||
}
|
||||
|
||||
@ -101,16 +103,26 @@ export function chooseFile({
|
||||
return new Promise<File | File[]>((resolve, reject) => {
|
||||
switch (accept) {
|
||||
case 'image':
|
||||
wx.chooseMedia({
|
||||
count: multiple ? Math.min(maxCount, 9) : 1,
|
||||
mediaType: ['image'],
|
||||
sourceType: capture,
|
||||
maxDuration,
|
||||
sizeType,
|
||||
camera,
|
||||
success: (res) => resolve(formatImage(res)),
|
||||
fail: reject,
|
||||
});
|
||||
if (isPC) {
|
||||
wx.chooseImage({
|
||||
count: multiple ? Math.min(maxCount, 9) : 1,
|
||||
sourceType: capture,
|
||||
sizeType,
|
||||
success: (res) => resolve(formatImage(res)),
|
||||
fail: reject,
|
||||
});
|
||||
} else {
|
||||
wx.chooseMedia({
|
||||
count: multiple ? Math.min(maxCount, 9) : 1,
|
||||
mediaType: ['image'],
|
||||
sourceType: capture,
|
||||
maxDuration,
|
||||
sizeType,
|
||||
camera,
|
||||
success: (res) => resolve(formatImage(res)),
|
||||
fail: reject,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'media':
|
||||
wx.chooseMedia({
|
||||
|
Loading…
x
Reference in New Issue
Block a user