|
|
/**
|
|
|
* url解析到path
|
|
|
*/
|
|
|
import {
|
|
|
stringify,
|
|
|
parse
|
|
|
} from '../vendors/query-stringify';
|
|
|
|
|
|
import APPIDCONFIG from './wxIdConfig'
|
|
|
import PATHS from './routerConfig.js'
|
|
|
const LOCAL_HOST = 'https://miniapp.yohobuy.com/';
|
|
|
const BRIAGE_FLAG = 'openby:yohobuy';
|
|
|
const GO_MINIAPP = 'go.miniapp';
|
|
|
/**
|
|
|
* jumpUrl:跳转URL
|
|
|
* defaultAppId:默认appId,当前引用小程序ID
|
|
|
*/
|
|
|
function urlToPath(jumpUrl, defaultAppId) {
|
|
|
console.log('jumpUrl:' + jumpUrl);
|
|
|
if (!jumpUrl) {
|
|
|
return {};
|
|
|
}
|
|
|
let targetAppId = defaultAppId
|
|
|
let pageName = '';
|
|
|
let pagePath = '';
|
|
|
let query = {};
|
|
|
let appId = '';
|
|
|
let appName = '';
|
|
|
let jumpType = 'navigateTo'
|
|
|
let miniApp = '';
|
|
|
|
|
|
//MKT,STORE小程序使用的规则,后续尽量不使用,统一规则
|
|
|
// 跳转到小程序内
|
|
|
// router.go('https://miniapp.yohobuy.com/pages/index/index?xxxx=ghh&ytty=444');
|
|
|
|
|
|
// 跳转到小程序外
|
|
|
// router.go('https://miniapp.yohobuy.com/pages/index/index?app=yohobuy&xxxx=ghh&ytty=444');
|
|
|
|
|
|
//yohobuy={ "action": "go.miniapp", "params": { "appId": "gh_afb5ac7a8f9d", "path": "/pages/index/index", "debugmode": "1" } }
|
|
|
//appId:小程序标识(appId) , path:小程序落地页面路径,缺省到小程序首页 开发人员配置选项debugmode,1表示开发版 2表示体验版 0 or字段缺省表示正式版本
|
|
|
// url 包含 open:yohobuy
|
|
|
let index = jumpUrl.indexOf(BRIAGE_FLAG)
|
|
|
if (index > -1) {
|
|
|
let openBy = {}
|
|
|
if (typeof jumpUrl === 'string') { // 处理普通url
|
|
|
let [uri, search] = jumpUrl.split('?');
|
|
|
const qs = parse(search);
|
|
|
console.log('search:' + search);
|
|
|
|
|
|
// 排除search内from_page_param参数的url参数
|
|
|
search = search.replace(/"from_page_param":"[^,]+"/, '"from_page_param":""');
|
|
|
search = search.replace(/'from_page_param':'[^,]+'/, "'from_page_param':''");
|
|
|
console.log('qs:')
|
|
|
console.log(qs)
|
|
|
|
|
|
// console.log('tempArr:' + tempArr)
|
|
|
// tempArr.splice(0, 1);
|
|
|
// let search = tempArr.join('?');
|
|
|
let qsItem = qs['openby:yohobuy']
|
|
|
console.log(qsItem)
|
|
|
if (!qs[BRIAGE_FLAG]) return {};
|
|
|
openBy = JSON.parse(qs[BRIAGE_FLAG]);
|
|
|
|
|
|
} else if (typeof jumpUrl === 'object') { // 处理公共跳转页面path参数
|
|
|
openBy = JSON.parse(jumpUrl[BRIAGE_FLAG]);
|
|
|
}
|
|
|
|
|
|
let action = openBy.action;
|
|
|
console.log(action)
|
|
|
query = openBy.params;
|
|
|
jumpType = openBy.jumpType || 'navigateTo';
|
|
|
appId = openBy.appId || '';
|
|
|
if (query && query.appId) {
|
|
|
appId = query.appId || '';
|
|
|
}
|
|
|
//跳转到外部小程序
|
|
|
if (action === GO_MINIAPP) {
|
|
|
pagePath = query.path
|
|
|
} else {
|
|
|
if (!appId && !appName){
|
|
|
targetAppId = appId || defaultAppId
|
|
|
}
|
|
|
let { cAppId, pagePath } = parsePath(targetAppId, appName, action, pageName)
|
|
|
if (cAppId && cAppId !== defaultAppId) {
|
|
|
appId = cAppId
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
delete query.appId
|
|
|
delete query.path
|
|
|
delete query.jumpType
|
|
|
miniApp = openBy.miniApp;
|
|
|
|
|
|
|
|
|
//==========================
|
|
|
|
|
|
} else {
|
|
|
//是否以LOCAL_HOST开头
|
|
|
let index = jumpUrl.indexOf(LOCAL_HOST)
|
|
|
console.log('is-indexOf:' + index)
|
|
|
const [uri, search] = jumpUrl.split('?');
|
|
|
query = parse(search);
|
|
|
|
|
|
if (index > -1) {
|
|
|
pagePath = uri.split(LOCAL_HOST)[1];
|
|
|
appId = query.appId || '';
|
|
|
appName = query.app || '';
|
|
|
jumpType = query.jumpType || 'navigateTo';
|
|
|
delete query.appId
|
|
|
delete query.jumpType
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
appId,
|
|
|
pagePath,
|
|
|
query,
|
|
|
jumpType
|
|
|
};
|
|
|
}
|
|
|
/**
|
|
|
* 获取页面路径
|
|
|
*/
|
|
|
function parsePath(targetAppId, appName, action, pageName) {
|
|
|
let toPath = ''
|
|
|
let appId = ''
|
|
|
APPIDCONFIG.some((info) => {
|
|
|
let cAppId = info.appId;
|
|
|
let cAppName = info.appName;
|
|
|
console.log('cAppId:' + cAppId + "//appName:" + appName)
|
|
|
//如果ID相同,查找path
|
|
|
if (cAppId === targetAppId || cAppName === appName) {
|
|
|
info.paths.some((pathInfo) => {
|
|
|
if (pathInfo.action === action || pathInfo.tag === pageName) {
|
|
|
toPath = pathInfo.pathName
|
|
|
return true;
|
|
|
}
|
|
|
})
|
|
|
appId = cAppId;
|
|
|
}
|
|
|
return (cAppId === targetAppId || cAppName === appName);
|
|
|
});
|
|
|
return {appId,toPath};
|
|
|
}
|
|
|
|
|
|
// export default urlToPath;
|
|
|
module.exports = {
|
|
|
urlToPath: urlToPath,
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|