/* ***********
  Author: Alexander
  Created: 2020-5-14 20:47:05
*********** */

import { Toast } from 'vant'
import { getvideoCover } from '@/api/ShortVideo/ShortVideo.js'
import Compressor from 'compressorjs';
function upLoaderImg(file) {    // file为你读取成功的回调文件信息
  return new Promise((resolve, reject) => {
    new Compressor(file, {
      quality: 0.6,
      success(result) {
        const params = new FormData();
        params.append('file', result, result.name);
        let config = {
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }
        getvideoCover(params, config)
          .then(res => {
            console.log('封面',res);
            if (res.data.success) {
              resolve(res.data.path)
            } else {
              // Toast.fail(res.data && (res.data.resultMsg))
              reject(res.data)
            }
          })
          .catch(err => {
            Toast.fail('系统异常')
            reject(err)
          })
      }
    })

  })
}

export default upLoaderImg