<NME> methods.js
<BEF> import {
  isFunc,
  isPlainObject
} from './utils/tools'
import {
  draw,
  getImageInfo,
  canvasToTempFilePath,
  loadCanvasImage
} from './utils/promisify'
import CanvasToBase64 from './utils/canvas2base64'

export default function methods () {
  const self = this

  const boundWidth = self.width // 裁剪框默认宽度，即整个画布宽度
  const boundHeight = self.height // 裁剪框默认高度，即整个画布高度

  const {
    id,
    targetId,
    pixelRatio
  } = self

  let {
    x = 0,
    y = 0,
    width = boundWidth,
    height = boundHeight
  } = self.cut

  self.updateCanvas = (done) => {
    if (self.croperTarget) {
      //  画布绘制图片
      self.ctx.drawImage(
        self.croperTarget,
        self.imgLeft,
        self.imgTop,
        self.scaleWidth,
        self.scaleHeight
      )
    }
    isFunc(self.onBeforeDraw) && self.onBeforeDraw(self.ctx, self)

    self.setBoundStyle(self.boundStyle) //	设置边界样式

    if (self.type !== '2d') {
      self.ctx.draw(false, done)
    }

    done && done()
    return self
  }

  self.pushOrigin = self.pushOrign = (src) => {
    self.src = src

    isFunc(self.onBeforeImageLoad) && self.onBeforeImageLoad(self.ctx, self)

    return loadCanvasImage(self, src).then((img) => {
      self.croperTarget = img

      return getImageInfo({ src })
        .then(res => {
          let innerAspectRadio = res.width / res.height
          let customAspectRadio = width / height

          if (innerAspectRadio < customAspectRadio) {
            self.rectX = x
            self.baseWidth = width
            self.baseHeight = width / innerAspectRadio
            self.rectY = y - Math.abs((height - self.baseHeight) / 2)
          } else {
            self.rectY = y
            self.baseWidth = height * innerAspectRadio
            self.baseHeight = height
            self.rectX = x - Math.abs((width - self.baseWidth) / 2)
          }

          self.imgLeft = self.rectX
          self.imgTop = self.rectY
          self.scaleWidth = self.baseWidth
          self.scaleHeight = self.baseHeight

          self.update()

          return new Promise((resolve) => {
            self.updateCanvas(resolve)
          })
        })
        .then(() => {
          isFunc(self.onImageLoad) && self.onImageLoad(self.ctx, self)
        })
    })
  }

  self.removeImage = () => {
    self.src = ''
    self.croperTarget = ''

    if (self.type === '2d') {
      return self.ctx.clearRect(0, 0, self.canvas.width, self.canvas.height)
    } else {
  }

  self.getCropperImage = (opt, fn) => {
    const customOptions = opt

    let canvasOptions = {
      canvasId: id,
      y,
      width,
      height
    }, done)
  }

    let task = () => Promise.resolve()

    if (
      isPlainObject(customOptions) &&
      customOptions.original
    ) {
      // original mode
      task = () => {
        self.targetCtx.drawImage(
      x: x,
      y: y,
      width: width,
      height: height
    }

    if (self.type === '2d') {
      canvasOptions.canvas = self.canvas
    }

    let task = () => Promise.resolve()

    if (customOptions.original) {
      // original mode
      task = () => {
        self.targetCtx.drawImage(
          self.croperTarget,
          self.imgLeft * pixelRatio,

    return task()
      .then(() => {
        if (isPlainObject(customOptions)) {
          canvasOptions = Object.assign({}, canvasOptions, customOptions)
        }

        if (isFunc(customOptions)) {
          fn = customOptions
        }

        const arg = canvasOptions.componentContext
          ? [canvasOptions, canvasOptions.componentContext]
          : [canvasOptions]
          x: x * pixelRatio,
          y: y * pixelRatio,
      })
      .then(res => {
        const tempFilePath = res.tempFilePath

        return isFunc(fn)
          ? fn.call(self, tempFilePath, null)
          : tempFilePath
      })
      .catch((err) => {
        if (isFunc(fn)) {
          fn.call(self, null, err)
        } else {
          throw err
        }
          : [canvasOptions]

        return canvasToTempFilePath.apply(null, arg)
      })
      .then(res => {
        const tempFilePath = res.tempFilePath
        return callback
          ? callback.call(self, tempFilePath, null)
          : tempFilePath
      })
      .catch((err) => {
        if (callback) {
          callback.call(self, null, err)
        } else {
          throw err
        }
      })
  }
}

<MSG> feat: use jpg as default file type

<DFF> @@ -1,6 +1,5 @@
 import {
-  isFunc,
-  isPlainObject
+  isFunc
 } from './utils/tools'
 import {
   draw,
@@ -104,7 +103,8 @@ export default function methods () {
   }
 
   self.getCropperImage = (opt, fn) => {
-    const customOptions = opt
+    const customOptions = Object.assign({fileType: 'jpg'}, opt)
+    const callback = isFunc(opt) ? opt : isFunc(fn) ? fn : null
 
     let canvasOptions = {
       canvasId: id,
@@ -116,10 +116,7 @@ export default function methods () {
 
     let task = () => Promise.resolve()
 
-    if (
-      isPlainObject(customOptions) &&
-      customOptions.original
-    ) {
+    if (customOptions.original) {
       // original mode
       task = () => {
         self.targetCtx.drawImage(
@@ -144,14 +141,7 @@ export default function methods () {
 
     return task()
       .then(() => {
-        if (isPlainObject(customOptions)) {
-          canvasOptions = Object.assign({}, canvasOptions, customOptions)
-        }
-
-        if (isFunc(customOptions)) {
-          fn = customOptions
-        }
-
+        Object.assign(canvasOptions, customOptions)
         const arg = canvasOptions.componentContext
           ? [canvasOptions, canvasOptions.componentContext]
           : [canvasOptions]
@@ -160,14 +150,13 @@ export default function methods () {
       })
       .then(res => {
         const tempFilePath = res.tempFilePath
-
-        return isFunc(fn)
-          ? fn.call(self, tempFilePath, null)
+        return callback
+          ? callback.call(self, tempFilePath, null)
           : tempFilePath
       })
       .catch((err) => {
-        if (isFunc(fn)) {
-          fn.call(self, null, err)
+        if (callback) {
+          callback.call(self, null, err)
         } else {
           throw err
         }

feat: use jpg as default file type