urlRoute.js 1.94 KB


import queryString from '../vendors/query-string';

const GO_LIST = 'go.list';
const GO_PRODUCTPOOL = 'go.poollist';
const GO_SHOP = 'go.shop';

const GO_BRAND = 'go.brand';
const GO_CATEGORY = 'go.category';
const GO_DETAIL = 'go.productDetail';
const GO_COUPON = 'go.coupon';
const GO_MINE = 'go.mine';
const GO_NEW = 'go.new';
const GO_SHOPCART = 'go.shopcart';
const GO_H5 = 'go.h5';



function jumpByUrl(jumpUrl,pageName){
  if (!jumpUrl) {
    return;
  }

  let url = "";
  let startIndex = jumpUrl.indexOf('openby:yohobuy=');
  if (startIndex < 0) {
    return;
  }

  let jsonRule = jumpUrl.substring(startIndex+'openby:yohobuy='.length);
  let json = JSON.parse(jsonRule);
  let action = json.action;
  
  let path = '';

  if (GO_LIST === action) {
    let actionType = json.params.actiontype;
    if (1 == actionType) {
      path = "../goodsList/goodsList";
    } else if (2 == actionType) {
      path = "../goodsList/activtyDetail";
    }
  } else if (GO_BRAND === action) {
    path = "../goodsList/brand";
  } else if (GO_PRODUCTPOOL === action) {
    path = "../goodsList/productPool";
  } else if (GO_SHOP === action) {
    path = "../goodsList/brandStore";
  } else if (GO_DETAIL === action) {
    path = "../goodsDetail/goodsDetail";
  } else if (GO_COUPON === action) {
    path = "../coupon/coupon";
  }else if (GO_NEW === action) {
    path = "../goodsList/newArrival";
  } else if (GO_SHOPCART === action) {
    wx.switchTab({
      url: "/pages/shopCart/shopCart"
    })
    return;
  }else if (GO_CATEGORY === action) {
    wx.switchTab({
      url: "/pages/classify/category"
    })
    return;
  }else if (GO_MINE === action) {
    wx.switchTab({
      url: "/pages/userCenter/userCenter"
    })
    return;
  } 

  if (!path) {
    return;
  }

  let params = queryString.stringify(json.params, { encode: false });
  url = path + "?page_name=" + pageName + "&" + params;

  if (url) {
    wx.navigateTo({
      url: url,
    })
  }
}

export {
  jumpByUrl,
}