UNPKG

autobots-lib

Version:

汽车人基础库

98 lines (90 loc) 2.93 kB
'use strict'; import React from 'react-native'; import Native from '../native'; const { NativeModules } = React; let NativeManager = { jumpModule(url) { if (!url) { return; } if (NativeModules.NativeManager && NativeModules.NativeManager.jumpModule) { NativeModules.NativeManager.jumpModule(url); } else { let moduleCode = null; if (url.indexOf('?') !== -1) { let query = url.slice(0, url.indexOf('?')); let allPath = query.split('//')[1]; moduleCode = allPath.split('/')[0]; } let param = this.getLocationParams(url); let moduleUrl = param.url ? param.url : ''; let jumpType = param.type ? param.type: 3; if (moduleCode == 'autohome.helper.app' && param.code){ moduleCode = param.code; } else if (moduleCode == 'webview') { moduleCode = 'QR_FUNDRASING'; jumpType = 2; } if (param.type && param.type == 3) { moduleUrl = 'apps/rn/api/bundle/' + moduleCode; } let level = param.level ? param.level : 0; let tools = param.tools ? param.tools : ''; let supportedOrientations = param.supportedOrientations ? param.supportedOrientations : 26; let useWebKit = param.useWebKit ? param.useWebKit : 0; let needPin = param.needPin ? param.needPin : 0; let needVpn = param.needVpn ? param.needVpn : 0; let customTitle = param.customTitle ? param.customTitle : ''; this.jumpToModule(moduleCode, level, moduleUrl, jumpType, param, tools, supportedOrientations, useWebKit, needPin, needVpn, customTitle); } }, getLocationParams(href) { let params = null; let query = null; if (href.indexOf('?') !== -1) { query = href.slice(href.indexOf('?') + 1); if (query.length > 0) { params = {}; query = query.split('&'); for (let i = 0; i < query.length; i++) { let param = query[i]; let tempParam = param.split('='); params[tempParam[0]] = param.substring(param.indexOf('=') + 1, param.length); } } } return params; }, jumpToModule( code, level, url, type, rnInitParams, tools, supportedOrientations, useWebKit, needPin, needVpn, customTitle ) { let dict = {}; if (rnInitParams) { if (typeof rnInitParams === 'string') { dict = JSON.parse(rnInitParams); } else { dict = rnInitParams; } } let urlStr = `autobots://rn/jump?code=${code}&level=${level}&url=${url}&type=${type}`; urlStr += `&tools=${tools}&supportedOrientations=${supportedOrientations}`; urlStr += `&useWebKit=${useWebKit}&needPin=${needPin}&needVpn=${needVpn}`; urlStr += `&customTitle=${customTitle}`; urlStr += `&rnInitParams=${encodeURIComponent(JSON.stringify(dict))}`; Native.callNative(urlStr, () => { }); } }; module.exports = NativeManager;