/*
* URL分为3中类型
* 1. 以uni://开头的地址是uni-app原生的页面
* 2. 以http或者https开头的地址是H5
* 3. 跳转到其它APP的地址
* */


export const Jump = function (url, type='navigate') {
	console.log(url,type,'路径1')
    if (!url) return;
    const index = url.indexOf(":");

    if (index !== -1) {
        const schema = url.substring(0, index)
        let targetPath
        switch (schema) {
            case "uni":
                const path = url.substring(index + 1)
                targetPath = path;
                break;
            case "http":
            case "https":
                const h5Url = encodeURIComponent(url)
                targetPath = `/pages/web/web?url=${h5Url}`;
                break;
            default:
                console.log("跳转到其它APP 或者 小程序 或者其它的内容")
                break;
        }
        console.log(targetPath,'路径')

        switch (type) {
            case 'redirect':
                uni.redirectTo({
                    url: targetPath
                })
                break;
            case 'tab':
                uni.switchTab({
                    url: targetPath
                })
                break;
            case 'launch':
                uni.reLaunch({
                    url: targetPath
                })
                break;
            default:
                uni.navigateTo({
                    url: targetPath
                })
                break;
        }


    }


}
export default {
    Jump
}
