UNPKG

mtl-js-sdk

Version:

ynf-fw-mtl-api

116 lines (106 loc) 3.39 kB
"use strict"; function Plugin(options, exports = {}) { const { platform } = options || { platform: window.mtl.platform }; const upesnVersion = window.mtl.upesnVersion || 0 function successCallBack(object = {}) { object.success && object.success({status : true}); object.complete && object.complete({status : true}); } //打开相机 function openCamera(obj={}) { if (platform === 'APIAndroid' || platform === 'APIIos' || (platform === 'upesn' && upesnVersion > 0)) { const { recordSecond = 15, shootMode = 1, watermark = {}, isEditImage = true } = obj; obj.recordSecond = recordSecond; obj.shootMode = shootMode; obj.watermark = watermark; obj.isEditImage = isEditImage; execApiBridge("openCamera", "mediaCollector", obj); } else { successCallBack(obj) } } // 打开预览页面 function openPreview(obj={}) { if (platform === 'APIAndroid' || platform === 'APIIos' || (platform === 'upesn' && upesnVersion > 0)) { const { selectedIndex = 0, paths = [] } = obj; if (paths && paths.length <= 0) { invokeFail(obj, { msg: "preview paths is null", }); return; } obj.selectedIndex = selectedIndex; obj.paths = paths; execApiBridge("openPreview", "mediaCollector", obj); } else { successCallBack(obj) } } // 编辑图片 function imageEdit(obj={}) { if (platform === 'APIAndroid' || platform === 'APIIos' || (platform === 'upesn' && upesnVersion > 0)) { const { watermark = {} } = obj; obj.watermark = watermark; execApiBridge("imageEdit", "mediaCollector", obj); } else { successCallBack(obj) } } // 打开预览视频页面 function videoPreview(obj={}) { if (platform === 'APIAndroid' || platform === 'APIIos' || (platform === 'upesn' && upesnVersion > 0)) { const { videoPath } = obj; if (!videoPath) { invokeFail(obj, { msg: "preview video Path is null", }); return; } obj.videoPath = videoPath; execApiBridge("videoPreview", "mediaCollector", obj); } else { successCallBack(obj) } } // 获取视频缩略图 function getVideoThumbnail(obj={}) { if (platform === 'APIAndroid' || platform === 'APIIos' || (platform === 'upesn' && upesnVersion > 0)) { const { videoPath } = obj; if (!videoPath) { invokeFail(obj, { msg: "Video Thumbnail path is null", }); return; } obj.videoPath = videoPath; execApiBridge("getVideoThumbnail", "mediaCollector", obj); } else { successCallBack(obj) } } // api内部方法 function execApiBridge(method, requireName, object) { console.log('------------------------', object) console.log('------------------------', method, requireName ) mtl.execPluginBridge({ ...object, method, requireName }) } function invokeFail(param, err) { if (!param) return; if (err && !err.message) { err.message = err.msg || err.errMsg; } typeof param.fail === "function" && param.fail(err); } let apiMethods = { openCamera, openPreview, imageEdit, videoPreview, getVideoThumbnail, }; const methods = apiMethods; exports.module = methods; exports.symbolPath = "video"; return exports; } export default Plugin;