@tmsfe/tms-core 0.0.180 → 0.0.181

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/request.js +21 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.180",
3
+ "version": "0.0.181",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/src/request.js CHANGED
@@ -9,7 +9,7 @@
9
9
  * 框架判断在不同的运行环境,切换调用不同运行环境提供的方法。
10
10
  */
11
11
  import md5 from './md5';
12
- import { getEnvInfo } from './env';
12
+ import { getEnvInfo, getAuthInfo } from './env';
13
13
  import { safeJsonParse } from './objUtils';
14
14
  import { encryptObjInit } from './encrypt/index';
15
15
  import reporter from './report/index';
@@ -125,10 +125,18 @@ const composeParam = async (param = {}, withAuth = true, baseParam = {}) => {
125
125
  const modifyAuthParam = async (param, withAuth) => {
126
126
  const requestParam = { ...param };
127
127
  if (withAuth) {
128
- const { uid, token, openId } = await wx.tmsLoginPromise;
129
- requestParam.userId = uid;
130
- requestParam.token = token;
131
- requestParam.openId = openId;
128
+ // 优先使用wx.tmsLoginPromise获取鉴权信息,否则调用getAuthInfo()
129
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
130
+ const authInfo = wx.tmsLoginPromise
131
+ ? await wx.tmsLoginPromise
132
+ : await getAuthInfo();
133
+
134
+ // 统一处理鉴权参数赋值
135
+ Object.assign(requestParam, {
136
+ userId: authInfo.uid || authInfo.userId,
137
+ token: authInfo.token,
138
+ openId: authInfo.openId,
139
+ });
132
140
  return requestParam;
133
141
  }
134
142
  delete requestParam.userId;
@@ -459,28 +467,28 @@ const isPathNeedRetryLogin = (path) => {
459
467
  ];
460
468
 
461
469
  // 检查路径是否在白名单中
462
- return !noRetryPaths.some(noRetryPath => path.includes(noRetryPath));
470
+ return noRetryPaths.every(noRetryPath => !path.includes(noRetryPath));
463
471
  };
464
472
 
465
-
466
- let refreshFlag = false;
473
+ let refreshPromise;
467
474
  async function loginRefresh() {
468
- if (!refreshFlag) {
475
+ if (!refreshPromise) {
469
476
  // 调用runtime的login方法刷新token
470
477
  const { tms } = getApp();
471
478
  wx.tmsLoginPromise = undefined;
472
479
  try {
473
- refreshFlag = true;
474
- await tms.login();
480
+ refreshPromise = tms.login();
481
+ await refreshPromise;
475
482
  // 登录成功,清除Promise
476
- refreshFlag = false;
483
+ refreshPromise = undefined;
477
484
  } catch (err) {
478
485
  // 登录失败重试
479
486
  setTimeout(() => {
480
- refreshFlag = false;
487
+ refreshPromise = undefined;
481
488
  }, 100);
482
489
  }
483
490
  }
491
+ return await refreshPromise;
484
492
  }
485
493
 
486
494
  // 统一返回格式