urlResolve.js 870 Bytes
export function navigateToPage(url, params = {}, type = 'navigateTo') {
  console.log(type, "type");
  
  const query = Object.keys(params)
    .map(
      (key) =>
        `${encodeURIComponent(key)}=${encodeURIComponent(
          typeof params[key] === "object"
            ? JSON.stringify(params[key])
            : params[key]
        )}`
    )
    .join("&");

  uni[type]({
    url: `${url}?${query}`,
  });
}

// 工具方法 - 接收参数(自动 decode)
export function getPageParams(options) {
  const result = {};
  Object.keys(options).forEach((key) => {
    const value = decodeURIComponent(options[key]);
    try {
      // 尝试解析 JSON,如果失败就当普通字符串
      result[key] = JSON.parse(value);
    } catch (e) {
      // result[key] = decodeURIComponent(options[key]);
      result[key] = value;
    }
  });
  return result;
}