| 308 | |
| 309 | //===============================================网络请求httpRequest========================================= |
| 310 | function httpRequest(options, timeout = 1 * 1000) { |
| 311 | method = options.method ? options.method.toLowerCase() : options.body ? "post" : "get"; |
| 312 | return new Promise(resolve => { |
| 313 | setTimeout(() => { |
| 314 | $[method](options, (err, resp, data) => { |
| 315 | try { |
| 316 | if (err) { |
| 317 | console.log(JSON.stringify(err)); |
| 318 | $.logErr(err); |
| 319 | } else { |
| 320 | try { data = JSON.parse(data); } catch (error) { } |
| 321 | } |
| 322 | } catch (e) { |
| 323 | console.log(e); |
| 324 | $.logErr(e, resp); |
| 325 | } finally { |
| 326 | resolve(data); |
| 327 | } |
| 328 | }) |
| 329 | }, timeout) |
| 330 | }) |
| 331 | } |
| 332 | //==============================================Debug模式=============================================== |
| 333 | function debugLog(...args) { |
| 334 | if (debug) { |