You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.5 KiB
90 lines
2.5 KiB
<template>
|
|
<view></view>
|
|
</template>
|
|
|
|
<script>
|
|
/* 路由分发页面仅供跳转页面 */
|
|
export default {
|
|
onLoad(options){
|
|
console.log('wai',options)
|
|
if(this.$shared.isValueType(options.scene) != 'undefined'){
|
|
const scene = decodeURIComponent(options.scene); // 二维码扫码进入
|
|
// const par = this.strToObj(scene);
|
|
// this.routeToPage(par);
|
|
// console.log('内部',options)
|
|
// console.log('====',par)
|
|
|
|
this.getTokenValue(scene);
|
|
}else{
|
|
// this.routeToPage(options);
|
|
// 普通小程序分享进入
|
|
this.getTokenValue(options.token);
|
|
}
|
|
},
|
|
methods: {
|
|
getTokenValue(token){
|
|
this.$http(this.API.API_WAREHOUSE_GET, {key: token}).then(res => {
|
|
console.log("getTokenValue", res);
|
|
let options = JSON.parse(res.data);
|
|
this.routeToPage(options);
|
|
}).catch(err => {
|
|
// 当token获取失败,则默认跳转到首页
|
|
this.$url('/pages/index/index', {type: 'switch'});
|
|
})
|
|
},
|
|
// 路由分发
|
|
routeToPage(options){
|
|
if(options.route == 'goods_detail' || options.route == 'goods'){
|
|
options.page_url = '/pages/goodsDetail/index';
|
|
this.joinPagePath(options);
|
|
}else if(options.route == 'home'){
|
|
options.page_url = '/pages/index/index';
|
|
options.is_tabbar = true; // 是否为tabbar,如果是需要多传入该参数
|
|
this.joinPagePath(options);
|
|
}else{
|
|
let obj = {
|
|
page_url: '/pages/index/index', // 啥都不填,默认跳转到首页
|
|
is_tabbar: true
|
|
};
|
|
this.joinPagePath(obj);
|
|
}
|
|
},
|
|
// 拼接地址,并相应跳转
|
|
joinPagePath(par){
|
|
let path = par.page_url;
|
|
let options = {}; // 传给页面的参数,用于解决switch不能传参的问题
|
|
let flag = true; // 标志,用于判断拼接次数,?只能出现一次
|
|
for(let i in par){
|
|
if(i != 'route' && i != 'page_url' && i != 'is_tabbar'){ // 跳过route、page_url、is_tabbar
|
|
options[i] = par[i];
|
|
if(flag){
|
|
path += '?'+ i +'='+ par[i];
|
|
flag = false;
|
|
}else{
|
|
path += '&'+ i +'='+ par[i];
|
|
}
|
|
}
|
|
}
|
|
console.log(par);
|
|
if(par.is_tabbar){
|
|
uni.setStorageSync('homePageOptions', options);
|
|
this.$url(par.page_url, {type: 'switch'});
|
|
}else{
|
|
this.$url(path, {type: 'redirect'});
|
|
}
|
|
},
|
|
// 将key=value&key=value形式的字符串转为对象
|
|
strToObj(str){
|
|
let obj = {};
|
|
if(!str) return obj;
|
|
|
|
let arr = str.split('&');
|
|
arr.map(item => {
|
|
let a = item.split('=');
|
|
obj[a[0]] = a[1];
|
|
});
|
|
return obj;
|
|
}
|
|
}
|
|
}
|
|
</script>
|