1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| Vue.prototype.$to = function(href) { if(!href) { return; }
if(href === 'exit') { return wx.exitMiniProgram(); }
if(href.indexOf('http') === 0) { return uni.navigateTo({ url: '/pages/other/webview', success: function(res) { res.eventChannel.emit('href', href); }, }); }
if(href.indexOf('wx') === 0) { const current_appid = wx.getAccountInfoSync().miniProgram.appId;
if(href.indexOf(current_appid) === 0) { return uni.showToast({ title: '无法跳转当前小程序', icon: 'none', }); }
const identifier_index = href.indexOf('|');
if(identifier_index === false) { return wx.navigateToMiniProgram({ appId: href, }); }
href = [ href.substring(0, identifier_index), href.substring(identifier_index + 1), ].filter(v => v);
if(href.length === 1) { return wx.navigateToMiniProgram({ appId: href[0], }); }
return wx.navigateToMiniProgram({ appId: href[0], path: href[1] || '', }); }
if(href.indexOf('plugin-private://wx') === 0) { return uni.navigateTo({ url: href, }); }
if(href.indexOf('/pages/') !== 0 && href.indexOf('pages/') !== 0) { return uni.showToast({ title: '路径错误', icon: 'none', }); }
if(href.indexOf('/') !== 0) { href = '/' + href; }
const pages = getCurrentPages();
const page = pages[pages.length - 1];
const identifier_index = href.indexOf('?');
let _href = [];
if(identifier_index === -1) { _href = [ href, ]; } else { _href = [ href.substring(0, identifier_index), href.substring(identifier_index + 1), ].filter(v => v); }
if(_href[0] === '/' + page.route) { const param = qs.parse(_href[1] || '');
page.onLoad && page.onLoad(param);
return; }
if (/^\/pages\/(index|personal)\/index$/g.test(_href[0])) { return uni.switchTab({ url: _href[0], success: function() { }, }); }
uni.navigateTo({ url: href, });
return; }
|