request.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. module.exports = function(a) {
  2. a.data || (a.data = {});
  3. var o = this.core,
  4. e = this.core.getStorageSync(this.const.ACCESS_TOKEN),
  5. t = this.core.getStorageSync(this.const.FORM_ID_LIST);
  6. e && (a.data.access_token = e), a.data._version = this._version, a.data._platform = this.platform;
  7. var s = this;
  8. t && 1 <= t.length && s.is_form_id_request && (s.is_form_id_request = !1, s.request({
  9. url: s.api.default.form_id,
  10. method: "POST",
  11. data: {
  12. formIdList: JSON.stringify(t)
  13. },
  14. success: function(e) {
  15. s.core.removeStorageSync(s.const.FORM_ID_LIST)
  16. },
  17. complete: function() {
  18. s.is_form_id_request = !0
  19. }
  20. })), o.request({
  21. url: a.url,
  22. header: a.header || {
  23. "content-type": "application/x-www-form-urlencoded"
  24. },
  25. data: a.data || {},
  26. method: a.method || "GET",
  27. dataType: a.dataType || "json",
  28. success: function(e) {
  29. -1 == e.data.code ? (s.core.hideLoading(), s.page.setUserInfoShow(), s.is_login = !1) : -2 == e.data.code ? o.redirectTo({
  30. url: "/pages/store-disabled/store-disabled"
  31. }) : a.success && a.success(e.data)
  32. },
  33. fail: function(e) {
  34. if (console.warn("--- request fail >>>"), console.warn("--- " + a.url + " ---"), console.warn(e), console.warn(
  35. "<<< request fail ---"), a && a.noHandlerFail) "function" == typeof a.fail && a.fail(e.data);
  36. else {
  37. var t = getApp();
  38. t.is_on_launch ? (t.is_on_launch = !1, o.showModal({
  39. title: "网络请求出错",
  40. content: e.errMsg || "",
  41. showCancel: !1,
  42. success: function(e) {
  43. e.confirm && a.fail && a.fail(e)
  44. }
  45. })) : (o.showToast({
  46. title: e.errMsg,
  47. image: "/images/icon-warning.png"
  48. }), a.fail && a.fail(e))
  49. }
  50. },
  51. complete: function(t) {
  52. if (200 != t.statusCode && t.data && t.data.code && 500 == t.data.code) {
  53. var e = t.data.data.message;
  54. o.showModal({
  55. title: "系统错误",
  56. content: e + ";\r\n请将错误内容复制发送给我们,以便进行问题追踪。",
  57. cancelText: "关闭",
  58. confirmText: "复制",
  59. success: function(e) {
  60. e.confirm && o.setClipboardData({
  61. data: JSON.stringify({
  62. data: t.data.data,
  63. object: a
  64. })
  65. })
  66. }
  67. })
  68. }
  69. a.complete && a.complete(t)
  70. }
  71. })
  72. };