@cpzxrobot/sdk 1.1.38 → 1.1.39

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
@@ -68,7 +68,7 @@ class Cpzxrobot {
68
68
  }
69
69
  initAxios(baseURL) {
70
70
  if (this.mode !== "miniapp_in_app") {
71
- const instance = axios_1.default.create({
71
+ var instance = axios_1.default.create({
72
72
  baseURL,
73
73
  });
74
74
  instance.interceptors.request.use((config) => {
@@ -80,6 +80,16 @@ class Cpzxrobot {
80
80
  // 对请求错误做些什么
81
81
  return Promise.reject(error);
82
82
  });
83
+ // @ts-ignore
84
+ instance.getAndSave = (url, data, fileName) => {
85
+ return instance.get(url, {
86
+ responseType: "blob",
87
+ params: data,
88
+ }).then((res) => {
89
+ this.saveBlob(res.data, fileName || "file");
90
+ });
91
+ };
92
+ // @ts-ignore
83
93
  this.axios = instance;
84
94
  }
85
95
  }
@@ -155,6 +165,10 @@ class Cpzxrobot {
155
165
  console.log(url, data);
156
166
  return platform.callHandler("axios_post", url, data);
157
167
  },
168
+ getAndSave: function (url, data, fileName) {
169
+ console.log(url, data);
170
+ return platform.callHandler("axios_getAndSave", url, data);
171
+ }
158
172
  };
159
173
  if (
160
174
  // @ts-ignore
@@ -31,7 +31,7 @@ class ProductGateway extends Object {
31
31
  //下载报价单
32
32
  export: (args) => {
33
33
  return this.context.ready.then((axios) => {
34
- return axios.post(`/api/v2/coremde-sale/product/price/export`, args);
34
+ return axios.getAndSave(`/api/v2/coremde-sale/product/price/export`, args, "报价单.xlsx");
35
35
  });
36
36
  },
37
37
  add: (args) => {
package/index.ts CHANGED
@@ -44,7 +44,7 @@ export class Cpzxrobot {
44
44
  setTitle!: (title: string) => void;
45
45
  saveBase64!: (base64: string, filename: string) => void;
46
46
  saveBlob!: (blob: Blob, filename: string) => void;
47
- scanQrcode!:() => Promise<string>;
47
+ scanQrcode!: () => Promise<string>;
48
48
  vibrate!: (time?: number) => void;
49
49
  assistant: AssistantGateway;
50
50
  energy: EnergyGateway;
@@ -91,9 +91,9 @@ export class Cpzxrobot {
91
91
 
92
92
  initAxios(baseURL: string) {
93
93
  if (this.mode !== "miniapp_in_app") {
94
- const instance = axios.create({
94
+ var instance = axios.create({
95
95
  baseURL,
96
- });
96
+ })
97
97
  instance.interceptors.request.use(
98
98
  (config) => {
99
99
  // 在发送请求之前在头部添加token
@@ -107,6 +107,16 @@ export class Cpzxrobot {
107
107
  return Promise.reject(error);
108
108
  }
109
109
  );
110
+ // @ts-ignore
111
+ instance.getAndSave = (url: string, data?: any, fileName?: string) => {
112
+ return instance.get(url, {
113
+ responseType: "blob",
114
+ params: data,
115
+ }).then((res) => {
116
+ this.saveBlob(res.data, fileName || "file");
117
+ });
118
+ }
119
+ // @ts-ignore
110
120
  this.axios = instance;
111
121
  }
112
122
  }
@@ -165,7 +175,7 @@ export class Cpzxrobot {
165
175
  this._jumpToMiniApp = function (url: string) {
166
176
  return platform.callHandler("app.openMiniapp", url);
167
177
  };
168
- this.scanQrcode = function(){
178
+ this.scanQrcode = function () {
169
179
  return platform.callHandler("app.scanQrcode");
170
180
  }
171
181
  this.setTitle = function (title: string) {
@@ -187,6 +197,10 @@ export class Cpzxrobot {
187
197
  console.log(url, data);
188
198
  return platform.callHandler("axios_post", url, data);
189
199
  },
200
+ getAndSave: function (url, data, fileName) {
201
+ console.log(url, data);
202
+ return platform.callHandler("axios_getAndSave", url, data);
203
+ }
190
204
  };
191
205
  if (
192
206
  // @ts-ignore
@@ -334,7 +348,7 @@ export class Cpzxrobot {
334
348
  this.resolveReady(this.axios);
335
349
  });
336
350
  return;
337
- }else{
351
+ } else {
338
352
  //jump to miniapp login page
339
353
  window.location.href = "/login.html";
340
354
  }
@@ -382,20 +396,20 @@ export default function (
382
396
  selectedFarm: Factory;
383
397
  selectedUnit: Unit;
384
398
  } = {
385
- devAuth: "",
386
- appCode: "",
387
- baseURL: "https://www.cpzxrobot.com/",
388
- selectedFarm: {
389
- id: 0,
390
- code: "",
391
- name: "",
392
- company_code: "",
393
- },
394
- selectedUnit: {
395
- id: 0,
396
- name: "",
397
- },
398
- }
399
+ devAuth: "",
400
+ appCode: "",
401
+ baseURL: "https://www.cpzxrobot.com/",
402
+ selectedFarm: {
403
+ id: 0,
404
+ code: "",
405
+ name: "",
406
+ company_code: "",
407
+ },
408
+ selectedUnit: {
409
+ id: 0,
410
+ name: "",
411
+ },
412
+ }
399
413
  ): Cpzxrobot {
400
414
  if (!_instance) {
401
415
  _instance = new Cpzxrobot(args.appCode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.1.38",
3
+ "version": "1.1.39",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -50,7 +50,7 @@ export class ProductGateway extends Object {
50
50
  pageSize: number;
51
51
  }) => {
52
52
  return this.context.ready.then((axios) => {
53
- return axios.post(`/api/v2/coremde-sale/product/price/export`, args);
53
+ return axios.getAndSave(`/api/v2/coremde-sale/product/price/export`, args, "报价单.xlsx");
54
54
  });
55
55
  },
56
56
  add: (args: {
package/types.d.ts CHANGED
@@ -268,6 +268,7 @@ type FeedTower = {
268
268
  interface MyAxiosInstance {
269
269
  get: (url: string, config?: any) => Promise<any>;
270
270
  post: (url: string, data?: any, config?: any) => Promise<any>;
271
+ getAndSave: (url: string, data?: any, fileName?: string) => Promise<any>;
271
272
  }
272
273
 
273
274
  interface Assistant {