miniapp-web-jsapi
Version:
JSAPI/View adapter for miniprogram running on the web
77 lines • 2.12 kB
JavaScript
import JsUtils from "../../../utils/js-utils";
export var NavigateBizSceneCode;
(function (NavigateBizSceneCode) {
/**
* 在 App 内的容器 使用新页面打开指定的 H5 页面
*/
NavigateBizSceneCode["WEB_PAGE"] = "WEB_PAGE";
/**
* 打开 Scheme/Deeplink 等
*/
NavigateBizSceneCode["SCHEME"] = "SCHEME";
/**
* 打开钱包扫一扫功能
*/
NavigateBizSceneCode["SCAN"] = "SCAN";
/**
* 打开当面付
*/
NavigateBizSceneCode["QR_PAY"] = "QR_PAY";
/**
* 打开绑卡页面
*/
NavigateBizSceneCode["BIND_CARD"] = "BIND_CARD";
/**
* 打开钱包的充值页
*/
NavigateBizSceneCode["TOP_UP"] = "TOP_UP";
})(NavigateBizSceneCode || (NavigateBizSceneCode = {}));
/**
* 导航到钱包某个业务场景
*
* @link https://yuque.antfin.com/docs/share/9e1b8ec0-2f51-421f-9518-1b9e183ac4c8?#
*/
export function navigateToBizScene(options) {
var sceneCode = options.sceneCode,
param = options.param,
success = options.success,
fail = options.fail;
var notifySuccess = function notifySuccess() {
success === null || success === void 0 ? void 0 : success();
};
var notifyFailed = function notifyFailed(error) {
fail === null || fail === void 0 ? void 0 : fail(error);
};
switch (sceneCode) {
case NavigateBizSceneCode.WEB_PAGE:
var webPageParams = param;
if (JsUtils.isNotEmpty(webPageParams.url)) {
window.open(webPageParams.url);
notifySuccess();
} else {
notifyFailed({
errorCode: 'PARAM_ILLEGAL',
errorMessage: 'url is empty'
});
}
break;
case NavigateBizSceneCode.SCHEME:
var schemeParams = param;
if (JsUtils.isNotEmpty(schemeParams.scheme)) {
window.open(schemeParams.scheme);
notifySuccess();
} else {
notifyFailed({
errorCode: 'PARAM_ILLEGAL',
errorMessage: 'scheme is empty'
});
}
break;
default:
notifyFailed({
errorCode: 'UNKNOWN',
errorMessage: 'not implemented for this sceneCode'
});
return;
}
}