(options, method)
| 510 | return newoptions |
| 511 | } |
| 512 | function httpRequest(options, method) { |
| 513 | //options = changeCode(options) |
| 514 | typeof (method) === 'undefined' ? ('body' in options ? method = 'post' : method = 'get') : method = method |
| 515 | return new Promise((resolve) => { |
| 516 | $[method](options, (err, resp, data) => { |
| 517 | try { |
| 518 | if (err) { |
| 519 | console.log(`${method}请求失败`); |
| 520 | //console.log(JSON.parse(err)); |
| 521 | $.logErr(err); |
| 522 | //throw new Error(err); |
| 523 | //console.log(err); |
| 524 | } else { |
| 525 | //httpResult = data; |
| 526 | //httpResponse = resp; |
| 527 | if (data) { |
| 528 | data = JSON.parse(data); |
| 529 | //console.log(data); |
| 530 | resolve(data) |
| 531 | } else { |
| 532 | console.log(`请求api返回数据为空,请检查自身原因`) |
| 533 | } |
| 534 | } |
| 535 | } catch (e) { |
| 536 | //console.log(e, resp); |
| 537 | $.logErr(e, resp); |
| 538 | } finally { |
| 539 | resolve(); |
| 540 | } |
| 541 | }) |
| 542 | }) |
| 543 | } |
| 544 | // 等待 X 秒 |
| 545 | function wait(n) { return new Promise(function (resolve) { setTimeout(resolve, n * 1000) }) } |
| 546 | // 双平台log输出 |
no test coverage detected