wtt
2025-08-12 112bb1d3ca7e5c813adc9514f6b56b5e4886f49b
utils/common.js
@@ -239,6 +239,59 @@
            }
        })
    }
   doRequest2({url, data, resFunction, errFunction, method, that}){
      that = that || this;
      let errorTip = null;
      uni.showLoading({
          title: '加载中...'
      })
      uni.request({
          method: method || "GET",
          url: this.serverUrl + url,
          data: data || "",
          success: (res) => {
              if (typeof resFunction === 'function') {
                  resFunction.call(that, res)
              } else if (typeof errFunction === 'undefined' || errFunction === null) {
                  return
              } else {
                  throw new TypeError("访问成功回调函数类型不为函数或者空!")
              }
          },
          fail: (err) => {
              console.error(err)
              errorTip = () => {
                  uni.showToast({
                      icon: "none",
                      title: err.errMsg || err.data.message || "接口异常!",
                      duration: 2000
                  })
              }
              if (typeof errFunction === 'function') {
                  errFunction.call(that, err)
              } else if (typeof errFunction === 'undefined' || errFunction === null) {
                  return
              } else {
                  throw new TypeError("访问失败回调函数类型不为函数或者空!")
              }
          },
          complete() {
              setTimeout(() => {
                  uni.hideLoading()
                  if (errorTip != null) {
                      errorTip()
                  }
              }, 1000)
          }
      })
   }
   stringToBoolean(str) {
     // 忽略大小写的转换
     return str?.toLowerCase() === "true";
   }
    // uni-app 播放音频封装
    playSound(e) {