UNPKG

dingtalk-jsapi

Version:

钉钉 模块化 多端统一 API

1 lines 1.71 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.h5IosBridgeInit=void 0;var h5BridgeReadyPromise;exports.h5IosBridgeInit=function(){return h5BridgeReadyPromise||(h5BridgeReadyPromise=new Promise(function(e,r){if("undefined"!=typeof WebViewJavascriptBridge){try{WebViewJavascriptBridge.init(function(e,r){})}catch(e){return r()}return e({})}document.addEventListener("WebViewJavascriptBridgeReady",function(){if("undefined"==typeof WebViewJavascriptBridge)return r();try{WebViewJavascriptBridge.init(function(e,r){})}catch(e){return r()}return e({})},!1)})),h5BridgeReadyPromise};var h5IosBridge=function(e,r){return h5BridgeReadyPromise||(h5BridgeReadyPromise=exports.h5IosBridgeInit()),h5BridgeReadyPromise.then(function(){var i=Object.assign({},r);return new Promise(function(r,n){if(!0===i.watch){var o=i.onSuccess;delete i.onSuccess,"function"==typeof i.success&&(o=i.success,delete i.success),"undefined"!=typeof WebViewJavascriptBridge&&WebViewJavascriptBridge.registerHandler(e,function(e,r){"function"==typeof o&&o.call(null,e),r&&r({errorCode:"0",errorMessage:"success"})})}void 0!==window.WebViewJavascriptBridge&&window.WebViewJavascriptBridge.callHandler(e,Object.assign({},i),function(e){var o=e||{};"0"===o.errorCode?("function"==typeof i.success?i.success.call(null,o.result):"function"==typeof i.onSuccess&&i.onSuccess.call(null,o.result),r(o.result)):("-1"===o.errorCode?"function"==typeof i.cancel?i.cancel.call(null,o,o.errorCode):"function"==typeof i.onCancel&&i.onCancel.call(null,o,o.errorCode):"function"==typeof i.fail?i.fail.call(null,o,o.errorCode):"function"==typeof i.onFail&&i.onFail.call(null,o,o.errorCode),n(o))})})})};exports.default=h5IosBridge;