@cpzxrobot/sdk 1.3.116 → 1.3.117

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.
@@ -131,6 +131,11 @@ class MobilePlatform {
131
131
  return this.platform.callHandler("app.scanQrcode");
132
132
  });
133
133
  }
134
+ getUserFromCache(userId) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ return this.platform.callHandler("app.getUserFromCache", userId);
137
+ });
138
+ }
134
139
  setTitle(title) {
135
140
  this.platform.callHandler("app.setTitle", title);
136
141
  }
@@ -313,6 +313,10 @@ class UserGateway extends Object {
313
313
  var factory = yield this.context.user.getSelectedFarm();
314
314
  var url = '/api/v1/user/info';
315
315
  if (userId) {
316
+ var userInCache = yield this.context.platform.getUserFromCache(userId);
317
+ if (userInCache) {
318
+ return userInCache;
319
+ }
316
320
  url += `/${userId}`;
317
321
  }
318
322
  return axios.get(url, {
@@ -395,6 +395,23 @@ class WebPlatform {
395
395
  }
396
396
  return Promise.resolve(this._selectedUnit);
397
397
  }
398
+ getUserFromCache(userId) {
399
+ return __awaiter(this, void 0, void 0, function* () {
400
+ // 从本地缓存中获取用户数据
401
+ const userKey = `user_${userId}`;
402
+ const userData = localStorage.getItem(userKey);
403
+ if (userData) {
404
+ try {
405
+ return JSON.parse(userData);
406
+ }
407
+ catch (error) {
408
+ console.error('Failed to parse user data from cache:', error);
409
+ return null;
410
+ }
411
+ }
412
+ return null;
413
+ });
414
+ }
398
415
  jumpToMiniApp(url) {
399
416
  window.location.href = url;
400
417
  return Promise.resolve();
@@ -148,5 +148,12 @@ class WindwosMiniAppPlatform {
148
148
  // @ts-ignore
149
149
  (_a = window.miniapp) === null || _a === void 0 ? void 0 : _a.aiAssist(args);
150
150
  }
151
+ getUserFromCache(userId) {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ var _a;
154
+ // @ts-ignore
155
+ return yield ((_a = window.miniapp) === null || _a === void 0 ? void 0 : _a.getUserFromCache(userId));
156
+ });
157
+ }
151
158
  }
152
159
  exports.WindwosMiniAppPlatform = WindwosMiniAppPlatform;
@@ -130,6 +130,10 @@ export class MobilePlatform implements PlatformInterface {
130
130
  return this.platform.callHandler("app.scanQrcode");
131
131
  }
132
132
 
133
+ async getUserFromCache(userId: number): Promise<any> {
134
+ return this.platform.callHandler("app.getUserFromCache", userId);
135
+ }
136
+
133
137
  setTitle(title: string): void {
134
138
  this.platform.callHandler("app.setTitle", title);
135
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.116",
3
+ "version": "1.3.117",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,4 +34,5 @@ export abstract class PlatformInterface {
34
34
  //change factory
35
35
  abstract openFactorySelector():void;
36
36
  abstract aiAssist(args:AiAssistRequest):void;
37
+ abstract getUserFromCache(userId: number): Promise<any>;
37
38
  }
package/user_gateway.ts CHANGED
@@ -342,6 +342,11 @@ export class UserGateway extends Object {
342
342
  var factory = await this.context.user.getSelectedFarm()
343
343
  var url = '/api/v1/user/info'
344
344
  if (userId) {
345
+ var userInCache = await this.context.platform.getUserFromCache(userId);
346
+ if (userInCache) {
347
+ return userInCache
348
+ }
349
+
345
350
  url += `/${userId}`
346
351
  }
347
352
  return axios.get(url, {
package/web_platform.ts CHANGED
@@ -399,6 +399,21 @@ export class WebPlatform implements PlatformInterface {
399
399
  return Promise.resolve(this._selectedUnit);
400
400
  }
401
401
 
402
+ async getUserFromCache(userId: number): Promise<any> {
403
+ // 从本地缓存中获取用户数据
404
+ const userKey = `user_${userId}`;
405
+ const userData = localStorage.getItem(userKey);
406
+ if (userData) {
407
+ try {
408
+ return JSON.parse(userData);
409
+ } catch (error) {
410
+ console.error('Failed to parse user data from cache:', error);
411
+ return null;
412
+ }
413
+ }
414
+ return null;
415
+ }
416
+
402
417
  jumpToMiniApp(url: string): Promise<void> {
403
418
  window.location.href = url;
404
419
  return Promise.resolve();
@@ -139,4 +139,9 @@ export class WindwosMiniAppPlatform implements PlatformInterface {
139
139
  // @ts-ignore
140
140
  window.miniapp?.aiAssist(args);
141
141
  }
142
+
143
+ async getUserFromCache(userId: number): Promise<any> {
144
+ // @ts-ignore
145
+ return await window.miniapp?.getUserFromCache(userId);
146
+ }
142
147
  }