沙盘演示系统应用的微信小程序
zuoxiao
2024-11-04 e0143ad80f9c78ac1eb1bd06782567ebffb67b8f
api/request.js
@@ -33,7 +33,8 @@
    form,
    isShowLoding,
    timeout,
    header
    header,
    useParams
  } = _options
  const app = getApp()
  // 设置请求头
@@ -56,6 +57,8 @@
    header.Authorization = `Bearer ${token}`
  }
  header.tag = app.globalData.tag;
  header.appId = app.globalData.AppID;
  return new Promise((resolve, reject) => {
    console.log("url:" + BASEURL + url);
    if (isShowLoding) {
@@ -70,6 +73,12 @@
    } else {
      myUrl = BASEURL + url;
    }
     // 如果 useParams 为 true,拼接查询参数
     if (useParams && data) {
      const queryString = objToQueryString(data); // 使用上面定义的函数
      myUrl += `?${queryString}`; // 拼接查询字符串
      data = {}; // 请求体数据设为空
  }
    wx.request({
      url: myUrl,
      data,
@@ -114,7 +123,14 @@
    })
  })
}
function objToQueryString(obj) {
  return Object.keys(obj)
      .map(key => {
          // 对键和值进行 URL 编码
          return `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
      })
      .join('&'); // 将所有键值对用 '&' 连接起来
}
// 封装toast函数
function showToast(title, icon = 'none', duration = 2500, mask = false) {
  wx.showToast({