@tmsfe/tms-core 0.0.127 → 0.0.128

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.127",
3
+ "version": "0.0.128",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -96,7 +96,10 @@ const login = async () => {
96
96
  */
97
97
  async function setPaypointAuth(param = {}) {
98
98
  const request = getRequestInstnce();
99
- const userInfo = await getLoginInfo();
99
+ const [userInfo, mycarPubOpenId] = await Promise.all([
100
+ getLoginInfo(),
101
+ getMycarPubOpenId(),
102
+ ]);
100
103
 
101
104
  const req = {
102
105
  traceSource: param.traceSource || 1, // 请求类型
@@ -106,7 +109,7 @@ async function setPaypointAuth(param = {}) {
106
109
  subAppId: param.appId || 'wx735359beafd78b9f', // 默认使用我的车的小程序号发布号发布
107
110
  appId: param.wechaId || 'wx29d15d946a7f2351', // 默认使用我的车的公众号id
108
111
  ...userInfo,
109
- openId: userInfo.mycarPubOpenId,
112
+ openId: mycarPubOpenId,
110
113
  };
111
114
 
112
115
  const res = await request.post('paypoint/setpayauth', req);
@@ -173,7 +176,10 @@ async function getPermissionList(param = {}) {
173
176
  */
174
177
  async function terminatePaypointPermisson(param = {}) {
175
178
  const request = getRequestInstnce();
176
- const userInfo = await getLoginInfo();
179
+ const [userInfo, mycarPubOpenId] = await Promise.all([
180
+ getLoginInfo(),
181
+ getMycarPubOpenId(),
182
+ ]);
177
183
 
178
184
  const data = {
179
185
  traceSource: param.traceSource || 1, // 请求来源
@@ -185,7 +191,7 @@ async function terminatePaypointPermisson(param = {}) {
185
191
  reason: param.reason || '其他',
186
192
  serviceId: param.serviceId,
187
193
  ...userInfo,
188
- openId: userInfo.mycarPubOpenId,
194
+ openId: mycarPubOpenId,
189
195
  };
190
196
 
191
197
  const res = await request.post('paypoint/terminatePaypointPermisson', data);
@@ -82,7 +82,12 @@ async function login() {
82
82
  // @ts-ignore
83
83
  const { trafficEntrence: registerSource, scene: sceneId } = getOpenAppTrafficData();
84
84
 
85
- userData = await getApp().tms.createRequest({ withAuth: false }).post('user/login', { code, registerSource, sceneId });
85
+ userData = await getApp().tms.createRequest({ withAuth: false }).post('user/login', {
86
+ code,
87
+ sceneId,
88
+ registerSource,
89
+ apiVer: 1, // 1表示不需要再去请求mycarPubOpenId,能快100ms
90
+ });
86
91
  } catch (e) {
87
92
  console.error(e); // eslint-disable-line
88
93
  }
@@ -156,12 +161,27 @@ let getMycarPubOpenIdProm;
156
161
  * 获取失败时,返回rejected Promise,rejected数据为错误对象
157
162
  */
158
163
  const getMycarPubOpenId = () => {
159
- if (getMycarPubOpenIdProm) { // 避免重复获取
164
+ if (getMycarPubOpenIdProm) {
165
+ return getMycarPubOpenIdProm;
166
+ }
167
+
168
+ // 优先用缓存的
169
+ const key = 'tms.pubOpenId';
170
+ const pubOpenId = wx.getStorageSync(key);
171
+ if (pubOpenId) {
172
+ getMycarPubOpenIdProm = Promise.resolve(pubOpenId);
160
173
  return getMycarPubOpenIdProm;
161
174
  }
162
175
 
176
+ // 从接口请求
163
177
  getMycarPubOpenIdProm = getOaPubOpenId('mycar')
164
- .then(openId => openId || Promise.reject(new Error('No mycarPubOpenId found')))
178
+ .then((pubOpenId) => {
179
+ if (pubOpenId) {
180
+ wx.setStorageSync(key, pubOpenId);
181
+ return pubOpenId;
182
+ }
183
+ return Promise.reject(new Error('No mycarPubOpenId found'));
184
+ })
165
185
  .catch((e) => {
166
186
  getMycarPubOpenIdProm = null;
167
187
  return Promise.reject(e);