UNPKG

mtl-js-sdk

Version:

365 lines (293 loc) 10.4 kB
"use strict"; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } define(['../../common/environment.js'], function (environment) { var SUCCESS_CODE = 200; var FAIL_CODE = 1; var unsupportFailRes = { code: FAIL_CODE, message: "当前平台不支持" }; function navigateTo(object) { mtlBridge.call('MTLNavigateService', 'navigateTo', object); } function redirectTo(object) { mtlBridge.call('MTLNavigateService', 'redirectTo', object); } function navigateBack(object) { mtlBridge.call('MTLNavigateService', 'navigateBack', object); } function chooseImage(object) { mtlBridge.call('MTLImagePicker', 'chooseImage', object); } function previewImage(object) { mtlBridge.call('MTLImagePicker', 'previewImage', object); } function uploadImage(object) { mtlBridge.call('MTLImagePicker', 'uploadImage', object); } function downloadImage(object) { mtlBridge.call('MTLImagePicker', 'downloadImage', object); } function getLocalImgSrc(object) { mtlBridge.call('MTLImagePicker', 'getLocalImgSrc', object); } function getLocalImgData(object) { mtlBridge.call('MTLImagePicker', 'getLocalImgData', object); } function scanQRCode(object) { mtlBridge.call('MTLImagePicker', 'scanQRCode', object); } function generateQRCode(object) { mtlBridge.call('MTLImagePicker', 'generateQRCode', object); } function getNetworkType(object) { mtlBridge.call('MTLReachabilityService', 'getNetworkType', object); } function getMac(object) { mtlBridge.call('MTLReachabilityService', 'getMac', object); } function translateVoice(object) { mtlBridge.call('MTLSpeechRecognitionService', 'translateVoice', object); } function startRecord(object) { mtlBridge.call('MTLVoice', 'startRecord', object); } function stopRecord(object) { mtlBridge.call('MTLVoice', 'stopRecord', object); } function onVoiceRecordEnd(object) { mtlBridge.call('MTLVoice', 'onVoiceRecordEnd', object); } function playVoice(object) { mtlBridge.call('MTLVoice', 'playVoice', object); } function stopVoice(object) { mtlBridge.call('MTLVoice', 'stopVoice', object); } function pauseVoice(object) { mtlBridge.call('MTLVoice', 'pauseVoice', object); } function onVoicePlayEnd(object) { mtlBridge.call('MTLVoice', 'onVoicePlayEnd', object); } function uploadVoice(object) { mtlBridge.call('MTLVoice', 'uploadVoice', object); } function downloadVoice(object) { mtlBridge.call('MTLVoice', 'downloadVoice', object); } function openLocation(object) { mtlBridge.call('MTLLocation', 'openLocation', object); } function getLocation(object) { mtlBridge.call('MTLLocation', 'getLocation', object); } function initFace(object) { mtlBridge.call('MTLFace', 'initFace', object); } function faceRegister(object) { mtlBridge.call('MTLFace', 'faceRegister', object); } function faceVerify(object) { mtlBridge.call('MTLFace', 'faceVerify', object); } function scanInvoice(object) { mtlBridge.call('MTLOCRService', 'scanInvoice', object); } function recognizeInvoice(object) { mtlBridge.call('MTLOCRService', 'recognizeInvoice', object); } function scanIDCard(object) { mtlBridge.call('MTLOCRService', 'scanIDCard', object); } function recognizeIDCard(object) { mtlBridge.call('MTLOCRService', 'recognizeIDCard', object); } function scanBankCard(object) { mtlBridge.call('MTLOCRService', 'scanBankCard', object); } function recognizeBankCard(object) { mtlBridge.call('MTLOCRService', 'recognizeBankCard', object); } function initSpeech(object) { mtlBridge.call('MTLVUIService', 'initSpeech', object); } function openSpeechPage(object) { mtlBridge.call('MTLVUIService', 'openSpeechPage', object); } function startSpeechSyn(object) { mtlBridge.call('MTLVUIService', 'startSpeechSyn', object); } function stopSpeechSyn(object) { mtlBridge.call('MTLVUIService', 'stopSpeechSyn', object); } function startSpeechRecog(object) { mtlBridge.call('MTLVUIService', 'startSpeechRecog', object); } function stopSpeechRecog(object) { mtlBridge.call('MTLVUIService', 'stopSpeechRecog', object); } function releaseSpeech(object) { mtlBridge.call('MTLVUIService', 'releaseSpeech', object); } function cancelAITask(object) { mtlBridge.call('MTLVUIService', 'cancelAITask', object); } function request(object) { mtlBridge.call('MTLNetWorkService', 'request', object); } function setStorage(object) { mtlBridge.call('MTLNetWorkService', 'setStorage', object); } function getStorage(object) { mtlBridge.call('MTLNetWorkService', 'getStorage', object); } function removeStorage(object) { mtlBridge.call('MTLNetWorkService', 'removeStorage', object); } function clearStorage(object) { mtlBridge.call('MTLNetWorkService', 'clearStorage', object); } function getNetworkTypeSync() { return mtlBridge.callSync("Device.getDeviceSync", {}); } function uploadFile(object) { mtlBridge.call('MTLNetWorkService', 'uploadFile', object); } function downFile(object) { mtlBridge.call('MTLNetWorkService', 'downFile', object); } function downloadFile(object) { mtlBridge.call('MTLNetWorkService', 'downloadFile', object); } function isWebviewCanGoBack(object) { mtlBridge.call('MTLDeviceService', 'canBack', object); } function onWebviewGoBack(object) { mtlBridge.call('MTLDeviceService', 'back', object); } function getAppVersion(object) { mtlBridge.call('MTLAppManageService', 'getAppVersion', object); } function upgradeApp(object) { mtlBridge.call('MTLAppManageService', 'upgradeApp', object); } function upgrade(object) { mtlBridge.call('MTLAppManageService', 'upgrade', object); } function getAppInfo(object) { window.mtl_handleCallback({ callbackId: object.callbackId, data: { "appId": "67a870c3-1abe-4eb0-b3a8-08f9585558b2" }, code: 0 }); } function doShare(object) { var type = object.type, desc = object.desc, imgUrl = object.imgUrl, link = object.link; var obj = _objectSpread({}, object); delete object.imgUrl; delete object.link; delete object.text; delete object.type; obj.platform = type; obj.text = desc; obj.img = imgUrl; obj.url = link; mtl.umshare.doShare(obj); } function openShare(object) { var desc = object.desc, imgUrl = object.imgUrl, link = object.link; var obj = _objectSpread({}, object); delete object.imgUrl; delete object.link; delete object.text; obj.text = desc; obj.img = imgUrl; obj.url = link; mtl.umshare.openShare(obj); } var exports = { navigateTo: navigateTo, redirectTo: redirectTo, navigateBack: navigateBack, chooseImage: chooseImage, previewImage: previewImage, uploadImage: uploadImage, downloadImage: downloadImage, getLocalImgSrc: getLocalImgSrc, getLocalImgData: getLocalImgData, scanQRCode: scanQRCode, generateQRCode: generateQRCode, getNetworkType: getNetworkType, getMac: getMac, translateVoice: translateVoice, startRecord: startRecord, stopRecord: stopRecord, onVoiceRecordEnd: onVoiceRecordEnd, playVoice: playVoice, stopVoice: stopVoice, pauseVoice: pauseVoice, onVoicePlayEnd: onVoicePlayEnd, uploadVoice: uploadVoice, downloadVoice: downloadVoice, openLocation: openLocation, getLocation: getLocation, initFace: initFace, faceRegister: faceRegister, faceVerify: faceVerify, scanInvoice: scanInvoice, recognizeInvoice: recognizeInvoice, scanIDCard: scanIDCard, recognizeIDCard: recognizeIDCard, scanBankCard: scanBankCard, recognizeBankCard: recognizeBankCard, initSpeech: initSpeech, openSpeechPage: openSpeechPage, startSpeechSyn: startSpeechSyn, stopSpeechSyn: stopSpeechSyn, startSpeechRecog: startSpeechRecog, stopSpeechRecog: stopSpeechRecog, releaseSpeech: releaseSpeech, cancelAITask: cancelAITask, request: request, setStorage: setStorage, getStorage: getStorage, removeStorage: removeStorage, clearStorage: clearStorage, uploadFile: uploadFile, downFile: downFile, downloadFile: downloadFile, login: environment.login, changeTenant: environment.changeTenant, sendValidateCode: environment.sendValidateCode, validateCodeLogin: environment.validateCodeLogin, getAppList: environment.getAppList, getAppVersion: getAppVersion, upgradeApp: upgradeApp, upgrade: upgrade, isWebviewCanGoBack: isWebviewCanGoBack, onWebviewGoBack: onWebviewGoBack, doShare: doShare, openShare: openShare, getAppInfo: getAppInfo }; var unsupportMethods = ["getAuthCode", "getAppCode", "getUserInfo", "chooseLocalFiles", "openSchema"]; function unsupportMethodIMP() { var object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; object.fail && object.fail(unsupportFailRes); object.complete && object.complete(unsupportFailRes); } unsupportMethods.forEach(function (prop) { exports[prop] = unsupportMethodIMP; }); // exports.device = mtlBridge.callSync("MTLDevice.getDeviceSync"); return exports; });