时空网前端
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.

69 lines
1.8 KiB

4 years ago
  1. <template>
  2. <view></view>
  3. </template>
  4. <script>
  5. /* 路由分发页面仅供跳转页面 */
  6. export default {
  7. onLoad(options){
  8. if(this.$shared.isValueType(options.scene) != 'undefined'){
  9. const scene = decodeURIComponent(options.scene); // 二维码扫码进入
  10. const par = this.strToObj(scene);
  11. this.routeToPage(par);
  12. }else{
  13. this.routeToPage(options); // 普通小程序分享进入
  14. }
  15. },
  16. methods: {
  17. // 路由分发
  18. routeToPage(options){
  19. if(options.route == 'goods_detail' || options.route == 'goods'){
  20. options.page_url = '/pages/goodsDetail/index';
  21. this.joinPagePath(options);
  22. }else if(options.route == 'home'){
  23. options.page_url = '/pages/index/index';
  24. options.is_tabbar = true; // 是否为tabbar,如果是需要多传入该参数
  25. this.joinPagePath(options);
  26. }else{
  27. let obj = {
  28. page_url: '/pages/index/index', // 啥都不填,默认跳转到首页
  29. is_tabbar: true
  30. };
  31. this.joinPagePath(obj);
  32. }
  33. },
  34. // 拼接地址,并相应跳转
  35. joinPagePath(par){
  36. let path = par.page_url;
  37. let flag = true; // 标志,用于判断拼接次数,?只能出现一次
  38. for(let i in par){
  39. if(i != 'route' && i != 'page_url' && i != 'is_tabbar'){ // 跳过route、page_url、is_tabbar
  40. if(flag){
  41. path += '?'+ i +'='+ par[i];
  42. flag = false;
  43. }else{
  44. path += '&'+ i +'='+ par[i];
  45. }
  46. }
  47. }
  48. if(par.is_tabbar){
  49. this.$url(path, {type: 'switch'});
  50. }else{
  51. this.$url(path, {type: 'redirect'});
  52. }
  53. },
  54. // 将key=value&key=value形式的字符串转为对象
  55. strToObj(str){
  56. let obj = {};
  57. if(!str) return obj;
  58. let arr = str.split('&');
  59. arr.map(item => {
  60. let a = item.split('=');
  61. obj[a[0]] = a[1];
  62. });
  63. return obj;
  64. }
  65. }
  66. }
  67. </script>