UNPKG

dingtalk-jsapi

Version:

钉钉 模块化 多端统一 API

1 lines 2.51 kB
"use strict";function handleBridgeResponse(e,n,i,o){if(e&&e.errorCode)if(e.errorCode===BRIDGE_ERROR_CODE.SUCCESS){var a=e.result;handleCallback(o,"onSuccess",a),n(a)}else console.warn("API 调用失败",e),handleCallback(o,"onFail",e),i(e);else e&&"false"===e.success?(handleCallback(o,"onFail",e),i(e)):(handleCallback(o,"onSuccess",e),n(e))}var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var n,i=1,o=arguments.length;i<o;i++){n=arguments[i];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},__assign.apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.handleBridgeResponse=exports.BRIDGE_ERROR_CODE=void 0;var env_1=require("../../env"),h5Event_1=require("./h5Event"),setMenu_1=require("../../common/api/biz/navigation/setMenu"),setRight_1=require("../../common/api/biz/navigation/setRight"),BRIDGE_ERROR_CODE;!function(e){e.SUCCESS="0"}(BRIDGE_ERROR_CODE=exports.BRIDGE_ERROR_CODE||(exports.BRIDGE_ERROR_CODE={}));var handleIosEvent=function(e){if(env_1.getENV().platform===env_1.ENV_ENUM.gdtIos){var n=function(n){var i,o;"function"==typeof(null===e||void 0===e?void 0:e.onSuccess)&&(null===e||void 0===e||e.onSuccess(n.data)),"function"==typeof(null===(i=null===e||void 0===e?void 0:e.params)||void 0===i?void 0:i.onSuccess)&&(null===(o=null===e||void 0===e?void 0:e.params)||void 0===o||o.onSuccess(n.data))};(null===e||void 0===e?void 0:e.__apiName)===setRight_1.apiName&&h5Event_1.on("navRightButton",n),(null===e||void 0===e?void 0:e.__apiName)===setMenu_1.apiName&&h5Event_1.on("navMenu",n)}},handleCallback=function(e,n,i){e&&"function"==typeof e[n]&&e[n].call(null,i),(null===e||void 0===e?void 0:e.params)&&"function"==typeof(null===e||void 0===e?void 0:e.params[n])&&(null===e||void 0===e||e.params[n].call(null,i))};exports.handleBridgeResponse=handleBridgeResponse;var h5MobileBridgeReadyPromise,h5MobileInit=function(){return h5MobileBridgeReadyPromise||(h5MobileBridgeReadyPromise=new Promise(function(e,n){window.AlipayJSBridge?e():document.addEventListener("AlipayJSBridgeReady",function(){e()},!1)})),h5MobileBridgeReadyPromise},h5MobileBridge=function(e,n){return h5MobileInit().then(function(){return new Promise(function(i,o){var a=__assign({_apiName:e},n);handleIosEvent(n),window.AlipayJSBridge.call(e,a,function(e){handleBridgeResponse(e,i,o,n)})})})},getMobileBridge=function(){return h5MobileInit().then(function(){return h5MobileBridge})};exports.default=getMobileBridge;