@cpzxrobot/sdk 1.2.96 → 1.2.98

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.js CHANGED
@@ -58,7 +58,6 @@ class Cpzxrobot {
58
58
  this.hash = "shzx";
59
59
  this.mode = "dev";
60
60
  this.auth = "";
61
- this.token = "";
62
61
  this.car = new car_gateway_1.CarGateway(this);
63
62
  this.project = new project_gateway_1.ProjectGateway(this);
64
63
  this.product = new product_gateway_1.ProductGateway(this);
@@ -126,7 +125,7 @@ class Cpzxrobot {
126
125
  this.mode = "miniapp_in_web";
127
126
  baseURL = "https://www.cpzxrobot.com";
128
127
  }
129
- this.platform = new web_platform_1.WebPlatform(this.token, this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
128
+ this.platform = new web_platform_1.WebPlatform(this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
130
129
  }
131
130
  this.platformReady = this.platform.ready();
132
131
  this.axios = this.platform.getAxiosFromMiniApp();
@@ -187,7 +186,7 @@ class Cpzxrobot {
187
186
  const token = localStorage.getItem("token");
188
187
  if (token) {
189
188
  logger(`found token(${token}) in localstorage`, "debug");
190
- this.token = token;
189
+ this.platform.setToken(token);
191
190
  this.axios.get("/api/v1/user/auth").then((res) => {
192
191
  if (res.data.Error) {
193
192
  window.location.href = "/login.html?error=" + res.data.Error;
@@ -252,12 +251,12 @@ class Cpzxrobot {
252
251
  return;
253
252
  }
254
253
  if (res.data.token) {
255
- this.token = "Bearer " + res.data.token;
254
+ this.platform.setToken("Bearer " + res.data.token);
256
255
  }
257
256
  else if (access_token.startsWith("Bearer ")) {
258
- this.token = access_token;
257
+ this.platform.setToken(access_token);
259
258
  }
260
- localStorage.setItem("token", this.token);
259
+ localStorage.setItem("token", this.platform.getToken());
261
260
  this.resolveReady(this.axios);
262
261
  });
263
262
  return;
@@ -272,7 +271,7 @@ class Cpzxrobot {
272
271
  logger(`sdk under ${this.mode} mode`, "debug");
273
272
  this.auth = auth;
274
273
  if (this.auth.startsWith("Bearer ")) {
275
- this.token = auth;
274
+ this.platform.setToken(auth);
276
275
  this.resolveReady(this.axios);
277
276
  }
278
277
  else {
@@ -286,7 +285,7 @@ class Cpzxrobot {
286
285
  throw res.data.Error;
287
286
  }
288
287
  else {
289
- this.token = "Bearer " + res.data.token;
288
+ this.platform.setToken("Bearer " + res.data.token);
290
289
  }
291
290
  this.resolveReady(this.axios);
292
291
  })
@@ -23,6 +23,11 @@ class MobilePlatform {
23
23
  }
24
24
  }, false);
25
25
  }
26
+ getToken() {
27
+ return "";
28
+ }
29
+ setToken(token) {
30
+ }
26
31
  setSelectedFarm(farm) {
27
32
  throw new Error("Method not implemented.");
28
33
  }
@@ -2,9 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlatformInterface = void 0;
4
4
  class PlatformInterface {
5
+ getToken() {
6
+ throw new Error("Method not implemented.");
7
+ }
8
+ setToken(token) {
9
+ throw new Error("Method not implemented.");
10
+ }
5
11
  //define constructor(token: string, appCode: string) {
6
- constructor(token, appCode, baseURL) {
7
- this.token = token;
12
+ constructor(appCode, baseURL) {
8
13
  this.appCode = appCode;
9
14
  this.baseURL = baseURL;
10
15
  }
@@ -4,40 +4,11 @@ exports.UserGateway = void 0;
4
4
  class UserGateway extends Object {
5
5
  constructor(context) {
6
6
  super();
7
- this._selectedFarm = {
8
- code: "",
9
- name: "",
10
- company_code: "",
11
- id: 0,
12
- };
13
- this._selectedUnit = {
14
- name: "",
15
- id: 0,
16
- };
17
7
  this.context = context;
18
8
  }
19
9
  //获得当前用户选择的工厂
20
10
  async getSelectedFarm() {
21
- await this.context.ready;
22
- return new Promise((resolve, reject) => {
23
- switch (this.context.mode) {
24
- case "dev":
25
- resolve(this._selectedFarm);
26
- break;
27
- case "miniapp_in_app":
28
- this.context.platform.getSelectedFarmFromMiniApp().then((farm) => {
29
- this._selectedFarm = farm;
30
- resolve(farm);
31
- });
32
- break;
33
- case "miniapp_in_web":
34
- resolve(this._selectedFarm);
35
- break;
36
- default:
37
- reject("dev mode, ignore");
38
- break;
39
- }
40
- });
11
+ return this.context.platform.getSelectedFarmFromMiniApp();
41
12
  }
42
13
  async selectUnit(unit) {
43
14
  if ((typeof unit === "string") || (typeof unit === "number")) {
@@ -50,27 +21,7 @@ class UserGateway extends Object {
50
21
  }
51
22
  //获得当前用户选择的单元
52
23
  getSelectedUnit() {
53
- return this.context.ready.then(() => {
54
- return new Promise((resolve, reject) => {
55
- switch (this.context.mode) {
56
- case "dev":
57
- resolve(this._selectedUnit);
58
- break;
59
- case "miniapp_in_app":
60
- this.context.platform.getSelectedUnitFromMiniApp().then((unit) => {
61
- this._selectedUnit = unit;
62
- resolve(unit);
63
- });
64
- break;
65
- case "miniapp_in_web":
66
- resolve(this._selectedUnit);
67
- break;
68
- default:
69
- reject("dev mode, ignore");
70
- break;
71
- }
72
- });
73
- });
24
+ return this.context.platform.getSelectedUnitFromMiniApp();
74
25
  }
75
26
  set selectedFarm(farm) {
76
27
  this.context.platform.setSelectedFarm(farm);
@@ -2,16 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebPlatform = void 0;
4
4
  class WebPlatform {
5
- constructor(token, appCode, baseURL, selectedFarm, selectedUnit) {
5
+ constructor(appCode, baseURL, selectedFarm, selectedUnit) {
6
6
  this.token = "";
7
7
  this.appCode = "";
8
8
  this.baseURL = "";
9
- this.token = token;
10
9
  this.appCode = appCode;
11
10
  this.baseURL = baseURL !== null && baseURL !== void 0 ? baseURL : "";
12
11
  this._selectedFarm = selectedFarm;
13
12
  this._selectedUnit = selectedUnit;
14
13
  }
14
+ getToken() {
15
+ return this.token;
16
+ }
17
+ setToken(token) {
18
+ this.token = token;
19
+ }
15
20
  setSelectedFarm(farm) {
16
21
  this._selectedFarm = farm;
17
22
  }
@@ -21,6 +21,11 @@ class WindwosMiniAppPlatform {
21
21
  }
22
22
  }, false);
23
23
  }
24
+ getToken() {
25
+ return "";
26
+ }
27
+ setToken(token) {
28
+ }
24
29
  setSelectedFarm(farm) {
25
30
  throw new Error("Method not implemented.");
26
31
  }
package/index.ts CHANGED
@@ -38,7 +38,7 @@ export class Cpzxrobot {
38
38
  axios!: MyAxiosInstance;
39
39
  appCode: string;
40
40
  user: UserGateway;
41
- token: string = "";
41
+ // token: string = "";
42
42
  factory: FactoryGateway;
43
43
  ready: Promise<MyAxiosInstance>;
44
44
  resolveReady!: (
@@ -129,7 +129,7 @@ export class Cpzxrobot {
129
129
  this.mode = "miniapp_in_web";
130
130
  baseURL = "https://www.cpzxrobot.com"
131
131
  }
132
- this.platform = new WebPlatform(this.token, this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
132
+ this.platform = new WebPlatform(this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
133
133
  }
134
134
 
135
135
  this.platformReady = this.platform.ready();
@@ -199,7 +199,7 @@ export class Cpzxrobot {
199
199
  const token = localStorage.getItem("token");
200
200
  if (token) {
201
201
  logger(`found token(${token}) in localstorage`, "debug");
202
- this.token = token;
202
+ this.platform.setToken(token);
203
203
  this.axios.get("/api/v1/user/auth").then((res) => {
204
204
  if (res.data.Error) {
205
205
  window.location.href = "/login.html?error=" + res.data.Error;
@@ -262,11 +262,11 @@ export class Cpzxrobot {
262
262
  return;
263
263
  }
264
264
  if (res.data.token) {
265
- this.token = "Bearer " + res.data.token;
265
+ this.platform.setToken("Bearer " + res.data.token);
266
266
  } else if (access_token.startsWith("Bearer ")) {
267
- this.token = access_token;
267
+ this.platform.setToken(access_token);
268
268
  }
269
- localStorage.setItem("token", this.token);
269
+ localStorage.setItem("token", this.platform.getToken());
270
270
  this.resolveReady(this.axios);
271
271
  });
272
272
  return;
@@ -280,7 +280,7 @@ export class Cpzxrobot {
280
280
  logger(`sdk under ${this.mode} mode`, "debug");
281
281
  this.auth = auth;
282
282
  if (this.auth.startsWith("Bearer ")) {
283
- this.token = auth;
283
+ this.platform.setToken(auth);
284
284
  this.resolveReady(this.axios);
285
285
  } else {
286
286
  this.axios
@@ -292,7 +292,7 @@ export class Cpzxrobot {
292
292
  if (res.data.Error) {
293
293
  throw res.data.Error;
294
294
  } else {
295
- this.token = "Bearer " + res.data.token;
295
+ this.platform.setToken("Bearer " + res.data.token);
296
296
  }
297
297
  this.resolveReady(this.axios);
298
298
  })
@@ -28,6 +28,12 @@ export class MobilePlatform implements PlatformInterface {
28
28
  }
29
29
  }, false);
30
30
  }
31
+ getToken(): string {
32
+ return "";
33
+ }
34
+ setToken(token: string): void {
35
+ }
36
+
31
37
  setSelectedFarm(farm: Factory): void {
32
38
  throw new Error("Method not implemented.");
33
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.2.96",
3
+ "version": "1.2.98",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,14 +1,18 @@
1
1
  import { Factory, MyAxiosInstance, Unit } from "./types";
2
2
 
3
3
  export abstract class PlatformInterface {
4
+ getToken(): string {
5
+ throw new Error("Method not implemented.");
6
+ }
7
+ setToken(token: string) {
8
+ throw new Error("Method not implemented.");
9
+ }
4
10
 
5
- token: string;
6
11
  appCode: string;
7
12
  baseURL: string;
8
13
 
9
14
  //define constructor(token: string, appCode: string) {
10
- constructor(token: string, appCode: string, baseURL: string) {
11
- this.token = token;
15
+ constructor(appCode: string, baseURL: string) {
12
16
  this.appCode = appCode;
13
17
  this.baseURL = baseURL;
14
18
  }
package/user_gateway.ts CHANGED
@@ -1,17 +1,7 @@
1
1
  import { Cpzxrobot, type Factory, type Unit } from "./types";
2
2
 
3
3
  export class UserGateway extends Object {
4
- _selectedFarm: Factory = {
5
- code: "",
6
- name: "",
7
- company_code: "",
8
- id: 0,
9
- };
10
4
  context: Cpzxrobot;
11
- _selectedUnit: Unit = {
12
- name: "",
13
- id: 0,
14
- };
15
5
 
16
6
  constructor(context: Cpzxrobot) {
17
7
  super();
@@ -20,29 +10,10 @@ export class UserGateway extends Object {
20
10
 
21
11
  //获得当前用户选择的工厂
22
12
  public async getSelectedFarm(): Promise<Factory> {
23
- await this.context.ready;
24
- return new Promise<Factory>((resolve, reject) => {
25
- switch (this.context.mode) {
26
- case "dev":
27
- resolve(this._selectedFarm);
28
- break;
29
- case "miniapp_in_app":
30
- this.context.platform.getSelectedFarmFromMiniApp().then((farm: any) => {
31
- this._selectedFarm = farm;
32
- resolve(farm);
33
- });
34
- break;
35
- case "miniapp_in_web":
36
- resolve(this._selectedFarm);
37
- break;
38
- default:
39
- reject("dev mode, ignore");
40
- break;
41
- }
42
- });
13
+ return this.context.platform.getSelectedFarmFromMiniApp()
43
14
  }
44
15
 
45
- public async selectUnit(unit: Unit|String|Number) {
16
+ public async selectUnit(unit: Unit | String | Number) {
46
17
  if ((typeof unit === "string") || (typeof unit === "number")) {
47
18
  var axios = await this.context.ready;
48
19
  this.context.platform.setSelectedUnit(unit);
@@ -53,27 +24,7 @@ export class UserGateway extends Object {
53
24
 
54
25
  //获得当前用户选择的单元
55
26
  getSelectedUnit() {
56
- return this.context.ready.then(() => {
57
- return new Promise<Unit>((resolve, reject) => {
58
- switch (this.context.mode) {
59
- case "dev":
60
- resolve(this._selectedUnit);
61
- break;
62
- case "miniapp_in_app":
63
- this.context.platform.getSelectedUnitFromMiniApp().then((unit: any) => {
64
- this._selectedUnit = unit;
65
- resolve(unit);
66
- });
67
- break;
68
- case "miniapp_in_web":
69
- resolve(this._selectedUnit);
70
- break;
71
- default:
72
- reject("dev mode, ignore");
73
- break;
74
- }
75
- });
76
- });
27
+ return this.context.platform.getSelectedUnitFromMiniApp();
77
28
  }
78
29
 
79
30
  set selectedFarm(farm: Factory) {
@@ -121,7 +72,7 @@ export class UserGateway extends Object {
121
72
  args = {
122
73
  roleCode: role
123
74
  }
124
- }else{
75
+ } else {
125
76
  args = {
126
77
  ...role,
127
78
  }
@@ -129,7 +80,7 @@ export class UserGateway extends Object {
129
80
  var axios = await this.context.ready;
130
81
  var factory = await this.context.user.getSelectedFarm();
131
82
  //当前如果打开的是公司,则说明该应用支持在公司级别打开,则要求该应用应该有对应的公司级别的角色配置,所以并不需要查找公司下属工厂或工厂的对应公司,再去查找用户
132
- return axios.get(`/api/v2/company/${factory.id}/users`,{
83
+ return axios.get(`/api/v2/company/${factory.id}/users`, {
133
84
  params: args
134
85
  });
135
86
  }
@@ -341,7 +292,7 @@ export class UserGateway extends Object {
341
292
  return axios.post('/api/v2/coremde-sale/task/list', params);
342
293
  },
343
294
  // 任务指派功能
344
- assign: (taskId: number, deptId: number, handleUserId: number = 0)=> {
295
+ assign: (taskId: number, deptId: number, handleUserId: number = 0) => {
345
296
  return this.context.ready.then((axios) => {
346
297
  return axios.post('/api/v2/coremde-sale/task/assign', {
347
298
  taskId,
package/web_platform.ts CHANGED
@@ -8,13 +8,18 @@ export class WebPlatform implements PlatformInterface {
8
8
  _selectedFarm: Factory | undefined;
9
9
  _selectedUnit: Unit | undefined;
10
10
 
11
- constructor(token: string, appCode: string, baseURL: string, selectedFarm: Factory | undefined, selectedUnit: Unit | undefined) {
12
- this.token = token;
11
+ constructor(appCode: string, baseURL: string, selectedFarm: Factory | undefined, selectedUnit: Unit | undefined) {
13
12
  this.appCode = appCode;
14
13
  this.baseURL = baseURL ?? "";
15
14
  this._selectedFarm = selectedFarm;
16
15
  this._selectedUnit = selectedUnit;
17
16
  }
17
+ getToken(): string {
18
+ return this.token;
19
+ }
20
+ setToken(token: string): void {
21
+ this.token = token;
22
+ }
18
23
  setSelectedFarm(farm: Factory): void {
19
24
  this._selectedFarm = farm;
20
25
  }
@@ -23,6 +23,11 @@ export class WindwosMiniAppPlatform implements PlatformInterface {
23
23
  }
24
24
  }, false);
25
25
  }
26
+ getToken(): string {
27
+ return "";
28
+ }
29
+ setToken(token: string): void {
30
+ }
26
31
  setSelectedFarm(farm: Factory): void {
27
32
  throw new Error("Method not implemented.");
28
33
  }