//选择图片文件
export const chooseImage = (count) => {
    return new Promise((resolve) => {
        uni.chooseImage({
            count: count,
            sizeType: ['original'],
            sourceType: ['album', 'camera'],
            success: ({tempFiles}) => {
                resolve(tempFiles);
            },
            fail: () => {
                resolve([]);
            }
        });
    })
}

//选择视频文件
export const chooseVideo = () => {
    return new Promise((resolve) => {
        uni.chooseVideo({
            sourceType: ['camera', 'album'],
            success: (res) => {
                resolve(res);
            },
            fail: () => {
                resolve({});
            }
        });
    })
}

export const filterSize = (size) => {
    if (!size) return '';
    if (size < pow1024(1)) return size + ' B';
    if (size < pow1024(2)) return (size / pow1024(1)).toFixed(2) + ' KB';
    if (size < pow1024(3)) return (size / pow1024(2)).toFixed(2) + ' MB';
    if (size < pow1024(4)) return (size / pow1024(3)).toFixed(2) + ' GB';
    return (size / pow1024(4)).toFixed(2) + ' TB'
}

// 求次幂
function pow1024(num) {
    return Math.pow(1024, num)
}
