uniapp-request-sdk 1.4.5 → 1.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ interface IParams {
11
11
  maxRetryCount?: number;
12
12
  /** 请求超时时间默认10s,ms为单位 */
13
13
  timeout?: number;
14
- /** 上传文件的请求超时时间,ms为单位 */
14
+ /** 上传文件的请求超时时间,ms为单位,默认5s */
15
15
  uploadTimeout?: number;
16
16
  /** 请求尝试延迟时间默认3s,ms为单位 */
17
17
  retryDelay?: number;
@@ -25,6 +25,8 @@ interface IParams {
25
25
  tokenPrefix?: string;
26
26
  /** 自定义得到token的函数,默认使用从客户端获取token的方式 */
27
27
  getTokenFun?: () => Promise<string>;
28
+ /** 用户名,用于日志排查使用 */
29
+ userName?: string;
28
30
  }
29
31
  declare function requestPromise(options?: RequestOptions & {
30
32
  timeout: number;
@@ -32,6 +34,8 @@ declare function requestPromise(options?: RequestOptions & {
32
34
  declare class UniRequest {
33
35
  /** 基准路径 */
34
36
  private baseUrl;
37
+ /** 用户名 */
38
+ private userName;
35
39
  /** 错误处理函数 */
36
40
  private onErrorHandler;
37
41
  /** 默认请求头 */
package/dist/index.esm.js CHANGED
@@ -37,6 +37,7 @@ function _toPropertyKey(arg) {
37
37
 
38
38
  /** 客户端交互内置事件名称 */
39
39
  var EVENT_NAME = {
40
+ /** 通知APP退出到登录页面 */
40
41
  LOGOUT: 'logout'
41
42
  };
42
43
  function requestPromise(options) {
@@ -71,6 +72,8 @@ var UniRequest = /*#__PURE__*/function () {
71
72
  _classCallCheck(this, UniRequest);
72
73
  /** 基准路径 */
73
74
  this.baseUrl = '';
75
+ /** 用户名 */
76
+ this.userName = '';
74
77
  /** 错误处理函数 */
75
78
  this.onErrorHandler = function (error) {
76
79
  console.error(error);
@@ -118,14 +121,21 @@ var UniRequest = /*#__PURE__*/function () {
118
121
  value: function request(params) {
119
122
  var _this3 = this;
120
123
  var callbackPromise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : requestPromise;
124
+ var _a;
121
125
  var url = params.url;
126
+ var appVersion = (_a = uni.getSystemInfoSync()) === null || _a === void 0 ? void 0 : _a.appVersion;
122
127
  /** 如果是http开头的,则不需要加入baseUrl */
123
128
  if (!/^https?:\/\//.test(url)) {
124
- url = "".concat(this.baseUrl.replace(/\/$/, ''), "/").concat(params.url.replace(/^\//, ''), "?t=").concat(Date.now());
129
+ url = "".concat(this.baseUrl.replace(/\/$/, ''), "/").concat(params.url.replace(/^\//, ''), "?t=").concat(Date.now(), "&appVersion=").concat(appVersion, "&userName=").concat(this.userName);
125
130
  } else {
126
131
  url = "".concat(params.url, "?t=").concat(Date.now());
127
132
  }
128
- var header = Object.assign(Object.assign({}, this.header), params.header);
133
+ var header = Object.assign(Object.assign(Object.assign({}, this.header), params.header), {
134
+ /** 添加日志上报的小程序版本 */
135
+ 'X-Request-AppVersion': appVersion,
136
+ /** 添加日志上报的小程序userName */
137
+ 'X-Request-UserName': this.userName
138
+ });
129
139
  var requestedToken = false;
130
140
  var retryCount = 0;
131
141
  return new Promise(function (res, rej) {
@@ -160,7 +170,7 @@ var UniRequest = /*#__PURE__*/function () {
160
170
  /** 获取token应该立马请求,不需要延迟 */
161
171
  retryFucntion();
162
172
  })["catch"](function () {
163
- if (_this3.maxRetryCount > retryCount) {
173
+ if (_this3.maxRetryCount > retryCount && !requestedToken) {
164
174
  delayRetryFcuntion();
165
175
  } else {
166
176
  _this3.rejectHandler(rej, resData);
@@ -177,14 +187,14 @@ var UniRequest = /*#__PURE__*/function () {
177
187
  console.log('用户无权限,调用logout事件,退出到登录页');
178
188
  });
179
189
  } else {
180
- if (_this3.maxRetryCount > retryCount) {
190
+ if (_this3.maxRetryCount > retryCount && !requestedToken) {
181
191
  delayRetryFcuntion();
182
192
  } else {
183
193
  _this3.rejectHandler(rej, resData);
184
194
  }
185
195
  }
186
196
  })["catch"](function (rejData) {
187
- if (_this3.maxRetryCount > retryCount) {
197
+ if (_this3.maxRetryCount > retryCount && !requestedToken) {
188
198
  delayRetryFcuntion();
189
199
  } else {
190
200
  _this3.rejectHandler(rej, rejData);
package/dist/index.umd.js CHANGED
@@ -43,6 +43,7 @@
43
43
 
44
44
  /** 客户端交互内置事件名称 */
45
45
  var EVENT_NAME = {
46
+ /** 通知APP退出到登录页面 */
46
47
  LOGOUT: 'logout'
47
48
  };
48
49
  function requestPromise(options) {
@@ -77,6 +78,8 @@
77
78
  _classCallCheck(this, UniRequest);
78
79
  /** 基准路径 */
79
80
  this.baseUrl = '';
81
+ /** 用户名 */
82
+ this.userName = '';
80
83
  /** 错误处理函数 */
81
84
  this.onErrorHandler = function (error) {
82
85
  console.error(error);
@@ -124,14 +127,21 @@
124
127
  value: function request(params) {
125
128
  var _this3 = this;
126
129
  var callbackPromise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : requestPromise;
130
+ var _a;
127
131
  var url = params.url;
132
+ var appVersion = (_a = uni.getSystemInfoSync()) === null || _a === void 0 ? void 0 : _a.appVersion;
128
133
  /** 如果是http开头的,则不需要加入baseUrl */
129
134
  if (!/^https?:\/\//.test(url)) {
130
- url = "".concat(this.baseUrl.replace(/\/$/, ''), "/").concat(params.url.replace(/^\//, ''), "?t=").concat(Date.now());
135
+ url = "".concat(this.baseUrl.replace(/\/$/, ''), "/").concat(params.url.replace(/^\//, ''), "?t=").concat(Date.now(), "&appVersion=").concat(appVersion, "&userName=").concat(this.userName);
131
136
  } else {
132
137
  url = "".concat(params.url, "?t=").concat(Date.now());
133
138
  }
134
- var header = Object.assign(Object.assign({}, this.header), params.header);
139
+ var header = Object.assign(Object.assign(Object.assign({}, this.header), params.header), {
140
+ /** 添加日志上报的小程序版本 */
141
+ 'X-Request-AppVersion': appVersion,
142
+ /** 添加日志上报的小程序userName */
143
+ 'X-Request-UserName': this.userName
144
+ });
135
145
  var requestedToken = false;
136
146
  var retryCount = 0;
137
147
  return new Promise(function (res, rej) {
@@ -166,7 +176,7 @@
166
176
  /** 获取token应该立马请求,不需要延迟 */
167
177
  retryFucntion();
168
178
  })["catch"](function () {
169
- if (_this3.maxRetryCount > retryCount) {
179
+ if (_this3.maxRetryCount > retryCount && !requestedToken) {
170
180
  delayRetryFcuntion();
171
181
  } else {
172
182
  _this3.rejectHandler(rej, resData);
@@ -183,14 +193,14 @@
183
193
  console.log('用户无权限,调用logout事件,退出到登录页');
184
194
  });
185
195
  } else {
186
- if (_this3.maxRetryCount > retryCount) {
196
+ if (_this3.maxRetryCount > retryCount && !requestedToken) {
187
197
  delayRetryFcuntion();
188
198
  } else {
189
199
  _this3.rejectHandler(rej, resData);
190
200
  }
191
201
  }
192
202
  })["catch"](function (rejData) {
193
- if (_this3.maxRetryCount > retryCount) {
203
+ if (_this3.maxRetryCount > retryCount && !requestedToken) {
194
204
  delayRetryFcuntion();
195
205
  } else {
196
206
  _this3.rejectHandler(rej, rejData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uniapp-request-sdk",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "description": "用于uniapp小程序的请求库的sdk",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": " dist/index.esm.js",