@cpzxrobot/sdk 1.3.1 → 1.3.3

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.
@@ -2,12 +2,6 @@
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
- }
11
5
  //define constructor(token: string, appCode: string) {
12
6
  constructor(appCode, baseURL) {
13
7
  this.appCode = appCode;
@@ -331,5 +331,39 @@ class ProjectGateway extends Object {
331
331
  }
332
332
  };
333
333
  }
334
+ get type() {
335
+ return {
336
+ // 获取类型列表
337
+ list: (args) => {
338
+ return this.context.ready.then((axios) => {
339
+ return axios.post(`/api/v2/coremde-sale/project/type/list`, args);
340
+ });
341
+ },
342
+ // 获取类型详情
343
+ get: (id) => {
344
+ return this.context.ready.then((axios) => {
345
+ return axios.get(`/api/v2/coremde-sale/project/type/get/${id}`);
346
+ });
347
+ },
348
+ // 新增项目类型
349
+ add: (args) => {
350
+ return this.context.ready.then((axios) => {
351
+ return axios.post(`/api/v2/coremde-sale/project/type/add`, args);
352
+ });
353
+ },
354
+ // 修改项目类型
355
+ update: (args) => {
356
+ return this.context.ready.then((axios) => {
357
+ return axios.post(`/api/v2/coremde-sale/project/type/update`, args);
358
+ });
359
+ },
360
+ // 删除项目类型
361
+ delete: (id) => {
362
+ return this.context.ready.then((axios) => {
363
+ return axios.get(`/api/v2/coremde-sale/project/type/delete/${id}`);
364
+ });
365
+ }
366
+ };
367
+ }
334
368
  }
335
369
  exports.ProjectGateway = ProjectGateway;
@@ -12,7 +12,6 @@ class UserGateway extends Object {
12
12
  }
13
13
  async selectUnit(unit) {
14
14
  if ((typeof unit === "string") || (typeof unit === "number")) {
15
- var axios = await this.context.ready;
16
15
  var resp = await this.context.unit.get(unit);
17
16
  this.context.platform.setSelectedUnit(resp.data);
18
17
  }
@@ -70,6 +69,7 @@ class UserGateway extends Object {
70
69
  });
71
70
  }
72
71
  async mypermission(params = undefined) {
72
+ var _a;
73
73
  var axios = await this.context.ready;
74
74
  var factory = await this.context.user.getSelectedFarm();
75
75
  var args;
@@ -78,11 +78,11 @@ class UserGateway extends Object {
78
78
  }
79
79
  else {
80
80
  args = {
81
- factoryId: factory.id
81
+ factoryId: (_a = factory.id) !== null && _a !== void 0 ? _a : 0
82
82
  };
83
83
  }
84
84
  return axios.get("/api/v2/user/role/mypermission", {
85
- params
85
+ args
86
86
  });
87
87
  }
88
88
  async delete(id) {
@@ -24,9 +24,10 @@ class WebPlatform {
24
24
  this._selectedUnit = unit;
25
25
  }
26
26
  async fetchWithAuth(input, init) {
27
+ var _a;
27
28
  const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
28
29
  headers.set('Authorization', this.token);
29
- headers.set('Miniapp-Code', this.appCode);
30
+ headers.set('Miniapp-Code', (_a = this.appCode) !== null && _a !== void 0 ? _a : "");
30
31
  const response = await fetch(this.baseURL + input.toString(), Object.assign(Object.assign({}, init), { headers }));
31
32
  if (!response.ok) {
32
33
  throw new Error(`HTTP error! status: ${response.status}`);
@@ -35,9 +36,10 @@ class WebPlatform {
35
36
  }
36
37
  ;
37
38
  async streamWithAuth(input, init, fn) {
39
+ var _a;
38
40
  const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
39
41
  headers.set('Authorization', this.token);
40
- headers.set('Miniapp-Code', this.appCode);
42
+ headers.set('Miniapp-Code', (_a = this.appCode) !== null && _a !== void 0 ? _a : "");
41
43
  const response = await fetch(this.baseURL + input.toString(), Object.assign(Object.assign({}, init), { headers }));
42
44
  var reader = response.body.getReader();
43
45
  const decoder = new TextDecoder("utf-8");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,13 +1,6 @@
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
- }
10
-
11
4
  appCode: string;
12
5
  baseURL: string;
13
6
 
@@ -16,7 +9,8 @@ export abstract class PlatformInterface {
16
9
  this.appCode = appCode;
17
10
  this.baseURL = baseURL;
18
11
  }
19
-
12
+ abstract getToken(): string;
13
+ abstract setToken(token: string): void;
20
14
  abstract getSelectedFarmFromMiniApp(): Promise<any>;
21
15
  abstract getSelectedUnitFromMiniApp(): Promise<any>;
22
16
  abstract jumpToMiniApp(url: string): Promise<void>;
@@ -34,6 +28,6 @@ export abstract class PlatformInterface {
34
28
  abstract setProgress(precentage: number): void;
35
29
  abstract getAxiosFromMiniApp(): MyAxiosInstance;
36
30
  abstract ready(): Promise<boolean>;
37
- abstract setSelectedUnit(unit: Unit|String|Number): void;
38
- abstract setSelectedFarm(farm: Factory|String|Number): void;
31
+ abstract setSelectedUnit(unit: Unit | String | Number): void;
32
+ abstract setSelectedFarm(farm: Factory | String | Number): void;
39
33
  }
@@ -439,4 +439,53 @@ export class ProjectGateway extends Object {
439
439
  };
440
440
  }
441
441
 
442
+ get type() {
443
+ return {
444
+ // 获取类型列表
445
+ list: (args: {
446
+ pageNo: number;
447
+ pageSize: number;
448
+ CompanyId: number;
449
+ }) => {
450
+ return this.context.ready.then((axios) => {
451
+ return axios.post(`/api/v2/coremde-sale/project/type/list`, args);
452
+ });
453
+ },
454
+ // 获取类型详情
455
+ get: (id: number) => {
456
+ return this.context.ready.then((axios) => {
457
+ return axios.get(`/api/v2/coremde-sale/project/type/get/${id}`);
458
+ });
459
+ },
460
+ // 新增项目类型
461
+ add: (args: {
462
+ typeName: string;
463
+ CompanyId: number;
464
+ codePrefix: string;
465
+ remark?: string;
466
+ }) => {
467
+ return this.context.ready.then((axios) => {
468
+ return axios.post(`/api/v2/coremde-sale/project/type/add`, args);
469
+ });
470
+ },
471
+ // 修改项目类型
472
+ update: (args: {
473
+ id: number;
474
+ typeName: string;
475
+ CompanyId: number;
476
+ codePrefix: string;
477
+ remark?: string;
478
+ }) => {
479
+ return this.context.ready.then((axios) => {
480
+ return axios.post(`/api/v2/coremde-sale/project/type/update`, args);
481
+ });
482
+ },
483
+ // 删除项目类型
484
+ delete: (id: number) => {
485
+ return this.context.ready.then((axios) => {
486
+ return axios.get(`/api/v2/coremde-sale/project/type/delete/${id}`);
487
+ });
488
+ }
489
+ };
490
+ }
442
491
  }
package/types.d.ts CHANGED
@@ -366,6 +366,7 @@ class Cpzxrobot {
366
366
  // _getSelectedUnitFromMiniApp: () => Promise<Unit>;
367
367
  openMiniApp: (url: string) => void;
368
368
  on: (event: string, callback: (data: any) => void) => void;
369
+ setTitle: (title: string) => void;
369
370
  // setTitle: (title: string) => void;
370
371
  // saveBase64: (base64: string, filename: string) => void;
371
372
  // saveBlob: (blob: Blob, filename: string) => void;
package/user_gateway.ts CHANGED
@@ -15,7 +15,6 @@ export class UserGateway extends Object {
15
15
 
16
16
  public async selectUnit(unit: Unit | String | Number) {
17
17
  if ((typeof unit === "string") || (typeof unit === "number")) {
18
- var axios = await this.context.ready;
19
18
  var resp = await this.context.unit.get(unit);
20
19
  this.context.platform.setSelectedUnit(resp.data);
21
20
  } else {
@@ -100,11 +99,11 @@ export class UserGateway extends Object {
100
99
  }
101
100
  } else {
102
101
  args = {
103
- factoryId: factory.id
102
+ factoryId: factory.id ?? 0
104
103
  };
105
104
  }
106
105
  return axios.get("/api/v2/user/role/mypermission", {
107
- params
106
+ args
108
107
  });
109
108
  }
110
109
 
package/web_platform.ts CHANGED
@@ -30,7 +30,7 @@ export class WebPlatform implements PlatformInterface {
30
30
  async fetchWithAuth(input: RequestInfo, init?: RequestInit) {
31
31
  const headers = new Headers(init?.headers);
32
32
  headers.set('Authorization', this.token);
33
- headers.set('Miniapp-Code', this.appCode);
33
+ headers.set('Miniapp-Code', this.appCode ?? "");
34
34
  const response = await fetch(this.baseURL + input.toString(), {
35
35
  ...init,
36
36
  headers
@@ -45,7 +45,7 @@ export class WebPlatform implements PlatformInterface {
45
45
  async streamWithAuth(input: RequestInfo, init?: RequestInit, fn?: Function) {
46
46
  const headers = new Headers(init?.headers);
47
47
  headers.set('Authorization', this.token);
48
- headers.set('Miniapp-Code', this.appCode);
48
+ headers.set('Miniapp-Code', this.appCode ?? "");
49
49
  const response = await fetch(this.baseURL + input.toString(), {
50
50
  ...init,
51
51
  headers