
export const chooseImage = (config) => {
  config = {
    ...{
      count: 1,
      mediaType: ['image'],
      sourceType: ['album', 'camera'],
      sizeType: ['original', 'compressed'],
      camera: 'back'
    }, config
  }

  return new Promise((resolve, reject) => {

    // #ifdef MP-WEIXIN
    uni.chooseMedia({
      ...config,
      success: (res) => {
        resolve(res);
      },
      fail: (err) => {
        reject(err);
      }
    });
    // #endif

    // #ifndef MP-WEIXIN
    uni.chooseImage({
      ...config,
      success: (res) => {
        resolve(res);
      },
      fail: (err) => {
        reject(err);
      }
    });
    // #endif
  });

}


export const chooseFile = (count = 1) => {
  return new Promise((resolve, reject) => {
    // #ifdef MP-WEIXIN
    wx.chooseMessageFile({
      count: count,
      success:  (res)=> {
        resolve(res);
      },
      fail:(err)=>{
        reject(err);
      }

    })
    // #endif
    // #ifdef H5
    // 需要hx2.9.9以上才支持uni.chooseFile
    uni.chooseFile({
      count: count,
      success:  (res)=> {
        resolve(res);
      },
      fail:(err)=>{
        reject(err);
      }
    });
    // #endif
  });
}

