@cpzxrobot/sdk 1.3.126 → 1.3.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/dist/mobile_platform.js +9 -0
- package/dist/pigfarm_gateway.js +6 -2
- package/dist/web_platform.js +16 -1
- package/mobile_platform.ts +7 -0
- package/package.json +1 -1
- package/pigfarm_gateway.ts +6 -4
- package/types.d.ts +1 -0
- package/web_platform.ts +30 -1
package/dist/mobile_platform.js
CHANGED
|
@@ -109,6 +109,15 @@ class MobilePlatform {
|
|
|
109
109
|
delete that.sseCallbacks[randomId];
|
|
110
110
|
});
|
|
111
111
|
},
|
|
112
|
+
postAsSse: function (url, fn, config) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
var randomId = Math.random().toString(36).substring(2);
|
|
115
|
+
that.sseCallbacks[randomId] = fn;
|
|
116
|
+
console.log("postAsSse", url, fn, randomId);
|
|
117
|
+
yield that.platform.callHandler("axios_postAsSse", url, config, randomId);
|
|
118
|
+
delete that.sseCallbacks[randomId];
|
|
119
|
+
});
|
|
120
|
+
},
|
|
112
121
|
};
|
|
113
122
|
}
|
|
114
123
|
getSelectedFarmFromMiniApp() {
|
package/dist/pigfarm_gateway.js
CHANGED
|
@@ -209,9 +209,13 @@ class PigfarmGateway extends Object {
|
|
|
209
209
|
}),
|
|
210
210
|
template: {
|
|
211
211
|
//获取配置模版列表
|
|
212
|
-
list: (factory) => __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
list: (factory, structType) => __awaiter(this, void 0, void 0, function* () {
|
|
213
213
|
var axios = yield this.context.ready;
|
|
214
|
-
|
|
214
|
+
var url = `/api/v1/pigfarm/heatLamp/config/template/list/${factory.id}`;
|
|
215
|
+
if (structType) {
|
|
216
|
+
url += `?structType=${structType}`;
|
|
217
|
+
}
|
|
218
|
+
return axios.get(url);
|
|
215
219
|
}),
|
|
216
220
|
//增加模板
|
|
217
221
|
add: (factory, name, data) => {
|
package/dist/web_platform.js
CHANGED
|
@@ -84,7 +84,14 @@ class WebPlatform {
|
|
|
84
84
|
headers.set('Miniapp-Code', (_a = this.appCode) !== null && _a !== void 0 ? _a : "");
|
|
85
85
|
headers.set('Accept', 'text/event-stream');
|
|
86
86
|
headers.set('Cache-Control', 'no-cache');
|
|
87
|
-
|
|
87
|
+
// 处理 body 是 object 的情况
|
|
88
|
+
let processedInit = init;
|
|
89
|
+
if ((init === null || init === void 0 ? void 0 : init.body) && typeof init.body === 'object' && !(init.body instanceof FormData) && !(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer)) {
|
|
90
|
+
processedInit = Object.assign(Object.assign({}, init), { body: JSON.stringify(init.body), headers: Object.assign(Object.assign({}, init.headers), { 'Content-Type': 'application/json' }) });
|
|
91
|
+
// 更新 headers 对象
|
|
92
|
+
headers.set('Content-Type', 'application/json');
|
|
93
|
+
}
|
|
94
|
+
const response = yield fetch(this.baseURL + input.toString(), Object.assign(Object.assign({}, processedInit), { headers }));
|
|
88
95
|
var reader = response.body.getReader();
|
|
89
96
|
const decoder = new TextDecoder("utf-8");
|
|
90
97
|
let done = false;
|
|
@@ -357,6 +364,14 @@ class WebPlatform {
|
|
|
357
364
|
method: 'GET',
|
|
358
365
|
}, fn).then(resolve).catch(reject);
|
|
359
366
|
});
|
|
367
|
+
},
|
|
368
|
+
postAsSse: (url, fn, _config) => {
|
|
369
|
+
return new Promise((resolve, reject) => {
|
|
370
|
+
instance.streamWithAuth(url, {
|
|
371
|
+
method: 'POST',
|
|
372
|
+
body: (_config === null || _config === void 0 ? void 0 : _config.body) || {},
|
|
373
|
+
}, fn).then(resolve).catch(reject);
|
|
374
|
+
});
|
|
360
375
|
}
|
|
361
376
|
};
|
|
362
377
|
}
|
package/mobile_platform.ts
CHANGED
|
@@ -111,6 +111,13 @@ export class MobilePlatform implements PlatformInterface {
|
|
|
111
111
|
await that.platform.callHandler("axios_getAsSse", url, config, randomId);
|
|
112
112
|
delete that.sseCallbacks[randomId];
|
|
113
113
|
},
|
|
114
|
+
postAsSse: async function (url, fn, config?) {
|
|
115
|
+
var randomId = Math.random().toString(36).substring(2);
|
|
116
|
+
that.sseCallbacks[randomId] = fn;
|
|
117
|
+
console.log("postAsSse", url, fn, randomId);
|
|
118
|
+
await that.platform.callHandler("axios_postAsSse", url, config, randomId);
|
|
119
|
+
delete that.sseCallbacks[randomId];
|
|
120
|
+
},
|
|
114
121
|
};
|
|
115
122
|
}
|
|
116
123
|
|
package/package.json
CHANGED
package/pigfarm_gateway.ts
CHANGED
|
@@ -249,11 +249,13 @@ export class PigfarmGateway extends Object {
|
|
|
249
249
|
},
|
|
250
250
|
template: {
|
|
251
251
|
//获取配置模版列表
|
|
252
|
-
list: async (factory: Factory): Promise<any> => {
|
|
252
|
+
list: async (factory: Factory, structType?: string): Promise<any> => {
|
|
253
253
|
var axios = await this.context.ready;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
var url = `/api/v1/pigfarm/heatLamp/config/template/list/${factory.id}`;
|
|
255
|
+
if (structType) {
|
|
256
|
+
url += `?structType=${structType}`;
|
|
257
|
+
}
|
|
258
|
+
return axios.get(url);
|
|
257
259
|
},
|
|
258
260
|
//增加模板
|
|
259
261
|
add: (factory: Factory, name: String, data: HeatLamp) => {
|
package/types.d.ts
CHANGED
|
@@ -296,6 +296,7 @@ interface MyAxiosInstance {
|
|
|
296
296
|
//option.data:上传的数据,例如{id:123,name:"xxx"},文件会被附加到data中,作为文件字段上传
|
|
297
297
|
upload: (url: string, option?: {}) => Promise<any>;
|
|
298
298
|
getAsSse: (url: string, fn: any, config?: any) => Promise<any>;
|
|
299
|
+
postAsSse: (url: string, fn: any, config?: any) => Promise<any>;
|
|
299
300
|
delete: (url: string, data?: any, config?: any) => Promise<any>;
|
|
300
301
|
}
|
|
301
302
|
|
package/web_platform.ts
CHANGED
|
@@ -79,8 +79,24 @@ export class WebPlatform implements PlatformInterface {
|
|
|
79
79
|
headers.set('Miniapp-Code', this.appCode ?? "");
|
|
80
80
|
headers.set('Accept', 'text/event-stream');
|
|
81
81
|
headers.set('Cache-Control', 'no-cache');
|
|
82
|
+
|
|
83
|
+
// 处理 body 是 object 的情况
|
|
84
|
+
let processedInit = init;
|
|
85
|
+
if (init?.body && typeof init.body === 'object' && !(init.body instanceof FormData) && !(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer)) {
|
|
86
|
+
processedInit = {
|
|
87
|
+
...init,
|
|
88
|
+
body: JSON.stringify(init.body),
|
|
89
|
+
headers: {
|
|
90
|
+
...init.headers,
|
|
91
|
+
'Content-Type': 'application/json'
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// 更新 headers 对象
|
|
95
|
+
headers.set('Content-Type', 'application/json');
|
|
96
|
+
}
|
|
97
|
+
|
|
82
98
|
const response = await fetch(this.baseURL + input.toString(), {
|
|
83
|
-
...
|
|
99
|
+
...processedInit,
|
|
84
100
|
headers
|
|
85
101
|
});
|
|
86
102
|
|
|
@@ -361,6 +377,19 @@ export class WebPlatform implements PlatformInterface {
|
|
|
361
377
|
method: 'GET',
|
|
362
378
|
}, fn).then(resolve).catch(reject);
|
|
363
379
|
});
|
|
380
|
+
},
|
|
381
|
+
postAsSse: (url: string, fn: any, _config?: {
|
|
382
|
+
fileName?: string;
|
|
383
|
+
params?: any;
|
|
384
|
+
preview?: boolean;
|
|
385
|
+
body?: any;
|
|
386
|
+
}) => {
|
|
387
|
+
return new Promise<any>((resolve, reject) => {
|
|
388
|
+
instance.streamWithAuth(url, {
|
|
389
|
+
method: 'POST',
|
|
390
|
+
body: _config?.body || {},
|
|
391
|
+
}, fn).then(resolve).catch(reject);
|
|
392
|
+
});
|
|
364
393
|
}
|
|
365
394
|
};
|
|
366
395
|
}
|