@cpzxrobot/sdk 1.3.56 → 1.3.58
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/pigfarm_gateway.js +5 -0
- package/dist/web_platform.js +82 -1
- package/package.json +1 -1
- package/pigfarm_gateway.ts +5 -0
- package/web_platform.ts +87 -8
package/dist/pigfarm_gateway.js
CHANGED
|
@@ -259,10 +259,15 @@ class PigfarmGateway extends Object {
|
|
|
259
259
|
var axios = await this.context.ready;
|
|
260
260
|
return axios.post(`/api/v1/pigfarm/heatLamp/config/update`, lamp);
|
|
261
261
|
},
|
|
262
|
+
//用于设置保温灯分组,TODO : 应该有更直观的命名
|
|
262
263
|
updateByUnit: async (unit, lamp, ids = null) => {
|
|
263
264
|
var axios = await this.context.ready;
|
|
264
265
|
return axios.post(`/api/v1/pigfarm/heatLamp/config/${unit.id}/update`, Object.assign(Object.assign({}, lamp), { ids }));
|
|
265
266
|
},
|
|
267
|
+
deleteGroup: async (id) => {
|
|
268
|
+
var axios = await this.context.ready;
|
|
269
|
+
return axios.post(`/api/v1/pigfarm/heatLamp/deleteGroup?id=${id}`);
|
|
270
|
+
},
|
|
266
271
|
switchByUnit: async (unit, action, ids = null) => {
|
|
267
272
|
var axios = await this.context.ready;
|
|
268
273
|
var args = {
|
package/dist/web_platform.js
CHANGED
|
@@ -186,8 +186,89 @@ class WebPlatform {
|
|
|
186
186
|
return { data: blob };
|
|
187
187
|
},
|
|
188
188
|
getAndPreview: async function (url, config) {
|
|
189
|
+
var _a;
|
|
189
190
|
url = instance.processQueryParams(url, config);
|
|
190
|
-
|
|
191
|
+
const response = await instance.fetchWithAuth(url, {
|
|
192
|
+
method: 'GET',
|
|
193
|
+
});
|
|
194
|
+
const blob = await response.blob();
|
|
195
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
196
|
+
// 解析文件名
|
|
197
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
198
|
+
let filename = (_a = config === null || config === void 0 ? void 0 : config.fileName) !== null && _a !== void 0 ? _a : "";
|
|
199
|
+
if (filename === "") {
|
|
200
|
+
if (contentDisposition) {
|
|
201
|
+
const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
|
|
202
|
+
if (utf8FilenameMatch) {
|
|
203
|
+
filename = decodeURIComponent(utf8FilenameMatch[1]);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
|
|
207
|
+
if (filenameMatch)
|
|
208
|
+
filename = filenameMatch[1];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
filename = "file";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// 支持预览的文件类型
|
|
216
|
+
const previewableTypes = [
|
|
217
|
+
'image/jpeg', 'image/png', 'image/gif', 'image/svg+xml',
|
|
218
|
+
'application/pdf',
|
|
219
|
+
'text/plain', 'application/json', 'text/csv', 'text/xml',
|
|
220
|
+
'video/mp4', 'audio/mpeg'
|
|
221
|
+
];
|
|
222
|
+
if (previewableTypes.some(type => contentType.includes(type))) {
|
|
223
|
+
const previewUrl = URL.createObjectURL(blob);
|
|
224
|
+
if (contentType.includes('image')) {
|
|
225
|
+
// 图片预览 - 直接在新窗口打开 blob URL
|
|
226
|
+
const win = window.open(previewUrl, '_blank');
|
|
227
|
+
if (win) {
|
|
228
|
+
win.document.title = filename;
|
|
229
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
230
|
+
}
|
|
231
|
+
return { data: blob };
|
|
232
|
+
}
|
|
233
|
+
else if (contentType.includes('pdf')) {
|
|
234
|
+
// PDF预览 - 直接在新窗口打开 blob URL
|
|
235
|
+
const win = window.open(previewUrl, '_blank');
|
|
236
|
+
if (win) {
|
|
237
|
+
win.document.title = filename;
|
|
238
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
239
|
+
}
|
|
240
|
+
return { data: blob };
|
|
241
|
+
}
|
|
242
|
+
else if (contentType.includes('text') || contentType.includes('json') || contentType.includes('xml') || contentType.includes('csv')) {
|
|
243
|
+
// 文本文件预览 - 创建下载链接并自动点击
|
|
244
|
+
const text = await blob.text();
|
|
245
|
+
const blobObj = new Blob([text], { type: contentType });
|
|
246
|
+
const url = URL.createObjectURL(blobObj);
|
|
247
|
+
const a = document.createElement('a');
|
|
248
|
+
a.href = url;
|
|
249
|
+
a.target = '_blank';
|
|
250
|
+
a.style.display = 'none';
|
|
251
|
+
document.body.appendChild(a);
|
|
252
|
+
a.click();
|
|
253
|
+
setTimeout(() => {
|
|
254
|
+
document.body.removeChild(a);
|
|
255
|
+
URL.revokeObjectURL(url);
|
|
256
|
+
}, 100);
|
|
257
|
+
return { data: blob };
|
|
258
|
+
}
|
|
259
|
+
else if (contentType.includes('video') || contentType.includes('audio')) {
|
|
260
|
+
// 视频/音频预览 - 直接在新窗口打开 blob URL
|
|
261
|
+
const win = window.open(previewUrl, '_blank');
|
|
262
|
+
if (win) {
|
|
263
|
+
win.document.title = filename;
|
|
264
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
265
|
+
}
|
|
266
|
+
return { data: blob };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// 不支持的预览类型或preview=false时,直接下载
|
|
270
|
+
await instance.saveBlob(blob, filename);
|
|
271
|
+
return { data: blob };
|
|
191
272
|
},
|
|
192
273
|
upload: async (url, option) => {
|
|
193
274
|
return new Promise((resolve, reject) => {
|
package/package.json
CHANGED
package/pigfarm_gateway.ts
CHANGED
|
@@ -318,6 +318,7 @@ export class PigfarmGateway extends Object {
|
|
|
318
318
|
var axios = await this.context.ready;
|
|
319
319
|
return axios.post(`/api/v1/pigfarm/heatLamp/config/update`, lamp);
|
|
320
320
|
},
|
|
321
|
+
//用于设置保温灯分组,TODO : 应该有更直观的命名
|
|
321
322
|
updateByUnit: async (unit: Unit, lamp: HeatLamp, ids: Number[] | null = null): Promise<any> => {
|
|
322
323
|
var axios = await this.context.ready;
|
|
323
324
|
return axios.post(`/api/v1/pigfarm/heatLamp/config/${unit.id}/update`, {
|
|
@@ -325,6 +326,10 @@ export class PigfarmGateway extends Object {
|
|
|
325
326
|
ids
|
|
326
327
|
});
|
|
327
328
|
},
|
|
329
|
+
deleteGroup: async (id: any): Promise<any> => {
|
|
330
|
+
var axios = await this.context.ready;
|
|
331
|
+
return axios.post(`/api/v1/pigfarm/heatLamp/deleteGroup?id=${id}`);
|
|
332
|
+
},
|
|
328
333
|
switchByUnit: async (unit: Unit, action: "on" | "off", ids: Number[] | null = null): Promise<any> => {
|
|
329
334
|
var axios = await this.context.ready;
|
|
330
335
|
var args: {
|
package/web_platform.ts
CHANGED
|
@@ -98,7 +98,7 @@ export class WebPlatform implements PlatformInterface {
|
|
|
98
98
|
if (config && config.params) {
|
|
99
99
|
// 检查URL是否已包含查询参数
|
|
100
100
|
const hasExistingParams = url.includes('?');
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
const flattenParams = (params: any, prefix = '') => {
|
|
103
103
|
const result: Record<string, string> = {};
|
|
104
104
|
Object.keys(params).forEach(key => {
|
|
@@ -112,10 +112,10 @@ export class WebPlatform implements PlatformInterface {
|
|
|
112
112
|
});
|
|
113
113
|
return result;
|
|
114
114
|
};
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
const flattened = flattenParams(config.params);
|
|
117
117
|
const newParams = new URLSearchParams(flattened).toString();
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
// 根据是否已有参数决定使用?还是&连接
|
|
120
120
|
url += (hasExistingParams ? '&' : '?') + newParams;
|
|
121
121
|
delete config.params;
|
|
@@ -135,7 +135,7 @@ export class WebPlatform implements PlatformInterface {
|
|
|
135
135
|
//test content-type, if it is json, then parse it
|
|
136
136
|
if (response.headers.get('Content-Type')?.includes('application/json')) {
|
|
137
137
|
return { data: await response.json() };
|
|
138
|
-
}else {
|
|
138
|
+
} else {
|
|
139
139
|
return response.blob();
|
|
140
140
|
}
|
|
141
141
|
},
|
|
@@ -172,7 +172,7 @@ export class WebPlatform implements PlatformInterface {
|
|
|
172
172
|
});
|
|
173
173
|
return { data: await response.json() };
|
|
174
174
|
},
|
|
175
|
-
getAndSave: async function(url: string, config?: any) {
|
|
175
|
+
getAndSave: async function (url: string, config?: any) {
|
|
176
176
|
url = instance.processQueryParams(url, config);
|
|
177
177
|
const response = await instance.fetchWithAuth(url, {
|
|
178
178
|
method: 'GET',
|
|
@@ -201,13 +201,92 @@ export class WebPlatform implements PlatformInterface {
|
|
|
201
201
|
await instance.saveBlob(blob, filename);
|
|
202
202
|
return { data: blob };
|
|
203
203
|
},
|
|
204
|
-
getAndPreview: async function(url: string, config?: {
|
|
204
|
+
getAndPreview: async function (url: string, config?: {
|
|
205
205
|
fileName?: string;
|
|
206
206
|
params?: any;
|
|
207
207
|
preview?: boolean;
|
|
208
|
-
}){
|
|
208
|
+
}) {
|
|
209
209
|
url = instance.processQueryParams(url, config);
|
|
210
|
-
|
|
210
|
+
const response = await instance.fetchWithAuth(url, {
|
|
211
|
+
method: 'GET',
|
|
212
|
+
});
|
|
213
|
+
const blob = await response.blob();
|
|
214
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
215
|
+
|
|
216
|
+
// 解析文件名
|
|
217
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
218
|
+
let filename = config?.fileName ?? "";
|
|
219
|
+
if (filename === "") {
|
|
220
|
+
if (contentDisposition) {
|
|
221
|
+
const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
|
|
222
|
+
if (utf8FilenameMatch) {
|
|
223
|
+
filename = decodeURIComponent(utf8FilenameMatch[1]);
|
|
224
|
+
} else {
|
|
225
|
+
const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
|
|
226
|
+
if (filenameMatch) filename = filenameMatch[1];
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
filename = "file";
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// 支持预览的文件类型
|
|
234
|
+
const previewableTypes = [
|
|
235
|
+
'image/jpeg', 'image/png', 'image/gif', 'image/svg+xml',
|
|
236
|
+
'application/pdf',
|
|
237
|
+
'text/plain', 'application/json', 'text/csv', 'text/xml',
|
|
238
|
+
'video/mp4', 'audio/mpeg'
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
if (previewableTypes.some(type => contentType.includes(type))) {
|
|
242
|
+
const previewUrl = URL.createObjectURL(blob);
|
|
243
|
+
|
|
244
|
+
if (contentType.includes('image')) {
|
|
245
|
+
// 图片预览 - 直接在新窗口打开 blob URL
|
|
246
|
+
const win = window.open(previewUrl, '_blank');
|
|
247
|
+
if (win) {
|
|
248
|
+
win.document.title = filename;
|
|
249
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
250
|
+
}
|
|
251
|
+
return { data: blob };
|
|
252
|
+
} else if (contentType.includes('pdf')) {
|
|
253
|
+
// PDF预览 - 直接在新窗口打开 blob URL
|
|
254
|
+
const win = window.open(previewUrl, '_blank');
|
|
255
|
+
if (win) {
|
|
256
|
+
win.document.title = filename;
|
|
257
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
258
|
+
}
|
|
259
|
+
return { data: blob };
|
|
260
|
+
} else if (contentType.includes('text') || contentType.includes('json') || contentType.includes('xml') || contentType.includes('csv')) {
|
|
261
|
+
// 文本文件预览 - 创建下载链接并自动点击
|
|
262
|
+
const text = await blob.text();
|
|
263
|
+
const blobObj = new Blob([text], { type: contentType });
|
|
264
|
+
const url = URL.createObjectURL(blobObj);
|
|
265
|
+
const a = document.createElement('a');
|
|
266
|
+
a.href = url;
|
|
267
|
+
a.target = '_blank';
|
|
268
|
+
a.style.display = 'none';
|
|
269
|
+
document.body.appendChild(a);
|
|
270
|
+
a.click();
|
|
271
|
+
setTimeout(() => {
|
|
272
|
+
document.body.removeChild(a);
|
|
273
|
+
URL.revokeObjectURL(url);
|
|
274
|
+
}, 100);
|
|
275
|
+
return { data: blob };
|
|
276
|
+
} else if (contentType.includes('video') || contentType.includes('audio')) {
|
|
277
|
+
// 视频/音频预览 - 直接在新窗口打开 blob URL
|
|
278
|
+
const win = window.open(previewUrl, '_blank');
|
|
279
|
+
if (win) {
|
|
280
|
+
win.document.title = filename;
|
|
281
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
282
|
+
}
|
|
283
|
+
return { data: blob };
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// 不支持的预览类型或preview=false时,直接下载
|
|
288
|
+
await instance.saveBlob(blob, filename);
|
|
289
|
+
return { data: blob };
|
|
211
290
|
},
|
|
212
291
|
upload: async (url: string, option?: any) => {
|
|
213
292
|
return new Promise<any>((resolve, reject) => {
|