@cpzxrobot/sdk 1.3.69 → 1.3.71
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/company_gateway.ts +3 -2
- package/device_filter.ts +4 -4
- package/device_gateway.ts +12 -2
- package/device_types/feedtower.ts +5 -5
- package/dist/camera_gateway.js +61 -42
- package/dist/car_gateway.js +54 -31
- package/dist/chickenfarm_gateway.js +11 -2
- package/dist/company_gateway.js +120 -94
- package/dist/device_gateway.js +210 -181
- package/dist/device_types/feedtower.js +130 -101
- package/dist/energy_gateway.js +33 -20
- package/dist/factory_gateway.js +129 -90
- package/dist/index.js +1 -1
- package/dist/mobile_platform.js +70 -43
- package/dist/pigfarm_gateway.js +51 -42
- package/dist/production_gateway.js +31 -18
- package/dist/project_gateway.js +12 -3
- package/dist/purchase_gateway.js +73 -38
- package/dist/sensor_datas.js +23 -11
- package/dist/sparepart_gateway.js +27 -18
- package/dist/test_strict.js +18 -0
- package/dist/user_gateway.js +131 -100
- package/dist/warehouse_gateway.js +34 -15
- package/dist/web_platform.js +213 -194
- package/dist/windows_platform.js +15 -5
- package/factory_gateway.ts +2 -2
- package/index.ts +3 -3
- package/mobile_platform.ts +3 -3
- package/news_gateway.ts +1 -1
- package/package.json +1 -1
- package/sensor_datas.ts +27 -16
- package/test_strict.ts +22 -0
- package/tsconfig.json +19 -19
- package/types.d.ts +12 -49
- package/web_platform.ts +15 -15
- package/windows_platform.ts +3 -3
package/dist/web_platform.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.WebPlatform = void 0;
|
|
4
13
|
class WebPlatform {
|
|
@@ -11,7 +20,7 @@ class WebPlatform {
|
|
|
11
20
|
this._selectedFarm = selectedFarm;
|
|
12
21
|
this._selectedUnit = selectedUnit;
|
|
13
22
|
}
|
|
14
|
-
addMessage(
|
|
23
|
+
addMessage(_message) {
|
|
15
24
|
throw new Error("Method not implemented.");
|
|
16
25
|
}
|
|
17
26
|
getToken() {
|
|
@@ -26,64 +35,68 @@ class WebPlatform {
|
|
|
26
35
|
setSelectedUnit(unit) {
|
|
27
36
|
this._selectedUnit = unit;
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
fetchWithAuth(input, init) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
var _a;
|
|
41
|
+
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
42
|
+
headers.set('Authorization', this.token);
|
|
43
|
+
headers.set('Miniapp-Code', (_a = this.appCode) !== null && _a !== void 0 ? _a : "");
|
|
44
|
+
const response = yield fetch(this.baseURL + input.toString(), Object.assign(Object.assign({}, init), { headers }));
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
49
|
+
});
|
|
39
50
|
}
|
|
40
51
|
;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
52
|
+
streamWithAuth(input, init, fn) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
var _a;
|
|
55
|
+
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
56
|
+
headers.set('Authorization', this.token);
|
|
57
|
+
headers.set('Miniapp-Code', (_a = this.appCode) !== null && _a !== void 0 ? _a : "");
|
|
58
|
+
headers.set('Accept', 'text/event-stream');
|
|
59
|
+
headers.set('Cache-Control', 'no-cache');
|
|
60
|
+
const response = yield fetch(this.baseURL + input.toString(), Object.assign(Object.assign({}, init), { headers }));
|
|
61
|
+
var reader = response.body.getReader();
|
|
62
|
+
const decoder = new TextDecoder("utf-8");
|
|
63
|
+
let done = false;
|
|
64
|
+
var buf = "";
|
|
65
|
+
while (!done) {
|
|
66
|
+
const { value, done } = yield reader.read();
|
|
67
|
+
if (done) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
const chunkValue = decoder.decode(value);
|
|
71
|
+
//split value to lines
|
|
72
|
+
// 将值拆分为行
|
|
73
|
+
buf = buf + chunkValue;
|
|
74
|
+
var i = buf.indexOf("\n");
|
|
75
|
+
while (i > -1) {
|
|
76
|
+
//find first \n
|
|
77
|
+
var line = buf.substring(0, i);
|
|
78
|
+
try {
|
|
79
|
+
if (line === "[DONE]") {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
else if (line.startsWith("data: ")) {
|
|
83
|
+
// remove prefix 'data: '
|
|
84
|
+
// 移除前缀 'data: '
|
|
85
|
+
var data = JSON.parse(line.split(": ")[1]);
|
|
86
|
+
//{"choices":[{"delta":{"content":" </"},"index":0}],"created":1741749068,"id":"chatcmpl-67ccb889154043f5874cbf3a64ec163e","model":"DeepSeek-R1","object":"chat.completion.chunk"}
|
|
87
|
+
fn === null || fn === void 0 ? void 0 : fn(data);
|
|
88
|
+
}
|
|
69
89
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// 移除前缀 'data: '
|
|
73
|
-
var data = JSON.parse(line.split(": ")[1]);
|
|
74
|
-
//{"choices":[{"delta":{"content":" </"},"index":0}],"created":1741749068,"id":"chatcmpl-67ccb889154043f5874cbf3a64ec163e","model":"DeepSeek-R1","object":"chat.completion.chunk"}
|
|
75
|
-
fn === null || fn === void 0 ? void 0 : fn(data);
|
|
90
|
+
catch (e) {
|
|
91
|
+
console.error("解析失败", e);
|
|
76
92
|
}
|
|
93
|
+
buf = buf.substring(i + 1);
|
|
94
|
+
i = buf.indexOf("\n");
|
|
77
95
|
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
console.error("解析失败", e);
|
|
80
|
-
}
|
|
81
|
-
buf = buf.substring(i + 1);
|
|
82
|
-
i = buf.indexOf("\n");
|
|
83
96
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
97
|
+
;
|
|
98
|
+
return true;
|
|
99
|
+
});
|
|
87
100
|
}
|
|
88
101
|
;
|
|
89
102
|
processQueryParams(url, config) {
|
|
@@ -115,170 +128,174 @@ class WebPlatform {
|
|
|
115
128
|
getAxiosFromMiniApp() {
|
|
116
129
|
var instance = this;
|
|
117
130
|
return {
|
|
118
|
-
get:
|
|
131
|
+
get: (url, config) => __awaiter(this, void 0, void 0, function* () {
|
|
119
132
|
var _a;
|
|
120
133
|
url = instance.processQueryParams(url, config);
|
|
121
|
-
const response =
|
|
134
|
+
const response = yield this.fetchWithAuth(url, {
|
|
122
135
|
method: 'GET',
|
|
123
136
|
headers: config === null || config === void 0 ? void 0 : config.headers
|
|
124
137
|
});
|
|
125
138
|
//test content-type, if it is json, then parse it
|
|
126
139
|
if ((_a = response.headers.get('Content-Type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
|
|
127
|
-
return { data:
|
|
140
|
+
return { data: yield response.json() };
|
|
128
141
|
}
|
|
129
142
|
else {
|
|
130
143
|
return response.blob();
|
|
131
144
|
}
|
|
132
|
-
},
|
|
133
|
-
delete:
|
|
134
|
-
const response =
|
|
145
|
+
}),
|
|
146
|
+
delete: (url, data, config) => __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const response = yield this.fetchWithAuth(url, {
|
|
135
148
|
method: 'DELETE',
|
|
136
149
|
headers: Object.assign({ 'Content-Type': 'application/json' }, config === null || config === void 0 ? void 0 : config.headers),
|
|
137
150
|
body: JSON.stringify(data)
|
|
138
151
|
});
|
|
139
|
-
return { data:
|
|
140
|
-
},
|
|
141
|
-
put:
|
|
142
|
-
const response =
|
|
152
|
+
return { data: yield response.json() };
|
|
153
|
+
}),
|
|
154
|
+
put: (url, data, config) => __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const response = yield this.fetchWithAuth(url, {
|
|
143
156
|
method: 'PUT',
|
|
144
157
|
headers: Object.assign({ 'Content-Type': 'application/json' }, config === null || config === void 0 ? void 0 : config.headers),
|
|
145
158
|
body: JSON.stringify(data)
|
|
146
159
|
});
|
|
147
|
-
return { data:
|
|
148
|
-
},
|
|
149
|
-
post:
|
|
150
|
-
const response =
|
|
160
|
+
return { data: yield response.json() };
|
|
161
|
+
}),
|
|
162
|
+
post: (url, data, config) => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
const response = yield this.fetchWithAuth(url, {
|
|
151
164
|
method: 'POST',
|
|
152
165
|
headers: Object.assign({ 'Content-Type': 'application/json' }, config === null || config === void 0 ? void 0 : config.headers),
|
|
153
166
|
body: JSON.stringify(data)
|
|
154
167
|
});
|
|
155
|
-
return { data:
|
|
156
|
-
},
|
|
157
|
-
getAndSave:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
return { data: yield response.json() };
|
|
169
|
+
}),
|
|
170
|
+
getAndSave: function (url, config) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
var _a;
|
|
173
|
+
url = instance.processQueryParams(url, config);
|
|
174
|
+
const response = yield instance.fetchWithAuth(url, {
|
|
175
|
+
method: 'GET',
|
|
176
|
+
headers: config === null || config === void 0 ? void 0 : config.headers
|
|
177
|
+
});
|
|
178
|
+
const blob = yield response.blob();
|
|
179
|
+
// 文件名解析逻辑
|
|
180
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
181
|
+
let filename = (_a = config === null || config === void 0 ? void 0 : config.fileName) !== null && _a !== void 0 ? _a : ""; // 默认文件名
|
|
182
|
+
// 1. 优先使用响应头中的文件名
|
|
183
|
+
if (filename == "") {
|
|
184
|
+
if (contentDisposition) {
|
|
185
|
+
const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
|
|
186
|
+
if (utf8FilenameMatch) {
|
|
187
|
+
filename = decodeURIComponent(utf8FilenameMatch[1]);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
|
|
191
|
+
if (filenameMatch)
|
|
192
|
+
filename = filenameMatch[1];
|
|
193
|
+
}
|
|
174
194
|
}
|
|
175
195
|
else {
|
|
176
|
-
|
|
177
|
-
if (filenameMatch)
|
|
178
|
-
filename = filenameMatch[1];
|
|
196
|
+
filename = "file";
|
|
179
197
|
}
|
|
180
198
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
await instance.saveBlob(blob, filename);
|
|
186
|
-
return { data: blob };
|
|
187
|
-
},
|
|
188
|
-
getAndPreview: async function (url, config) {
|
|
189
|
-
var _a;
|
|
190
|
-
url = instance.processQueryParams(url, config);
|
|
191
|
-
const response = await instance.fetchWithAuth(url, {
|
|
192
|
-
method: 'GET',
|
|
199
|
+
yield instance.saveBlob(blob, filename);
|
|
200
|
+
return { data: blob };
|
|
193
201
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
},
|
|
203
|
+
getAndPreview: function (url, config) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
var _a;
|
|
206
|
+
url = instance.processQueryParams(url, config);
|
|
207
|
+
const response = yield instance.fetchWithAuth(url, {
|
|
208
|
+
method: 'GET',
|
|
209
|
+
});
|
|
210
|
+
const blob = yield response.blob();
|
|
211
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
212
|
+
// 解析文件名
|
|
213
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
214
|
+
let filename = (_a = config === null || config === void 0 ? void 0 : config.fileName) !== null && _a !== void 0 ? _a : "";
|
|
215
|
+
if (filename === "") {
|
|
216
|
+
if (contentDisposition) {
|
|
217
|
+
const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
|
|
218
|
+
if (utf8FilenameMatch) {
|
|
219
|
+
filename = decodeURIComponent(utf8FilenameMatch[1]);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
|
|
223
|
+
if (filenameMatch)
|
|
224
|
+
filename = filenameMatch[1];
|
|
225
|
+
}
|
|
204
226
|
}
|
|
205
227
|
else {
|
|
206
|
-
|
|
207
|
-
if (filenameMatch)
|
|
208
|
-
filename = filenameMatch[1];
|
|
228
|
+
filename = "file";
|
|
209
229
|
}
|
|
210
230
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
win.document.title = filename;
|
|
229
|
-
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
231
|
+
// 支持预览的文件类型
|
|
232
|
+
const previewableTypes = [
|
|
233
|
+
'image/jpeg', 'image/png', 'image/gif', 'image/svg+xml',
|
|
234
|
+
'application/pdf',
|
|
235
|
+
'text/plain', 'application/json', 'text/csv', 'text/xml',
|
|
236
|
+
'video/mp4', 'audio/mpeg'
|
|
237
|
+
];
|
|
238
|
+
if (previewableTypes.some(type => contentType.includes(type))) {
|
|
239
|
+
const previewUrl = URL.createObjectURL(blob);
|
|
240
|
+
if (contentType.includes('image')) {
|
|
241
|
+
// 图片预览 - 直接在新窗口打开 blob URL
|
|
242
|
+
const win = window.open(previewUrl, '_blank');
|
|
243
|
+
if (win) {
|
|
244
|
+
win.document.title = filename;
|
|
245
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
246
|
+
}
|
|
247
|
+
return { data: blob };
|
|
230
248
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
249
|
+
else if (contentType.includes('pdf')) {
|
|
250
|
+
// PDF预览 - 直接在新窗口打开 blob URL
|
|
251
|
+
const win = window.open(previewUrl, '_blank');
|
|
252
|
+
if (win) {
|
|
253
|
+
win.document.title = filename;
|
|
254
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
255
|
+
}
|
|
256
|
+
return { data: blob };
|
|
239
257
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
258
|
+
else if (contentType.includes('text') || contentType.includes('json') || contentType.includes('xml') || contentType.includes('csv')) {
|
|
259
|
+
// 文本文件预览 - 创建下载链接并自动点击
|
|
260
|
+
const text = yield blob.text();
|
|
261
|
+
const blobObj = new Blob([text], { type: contentType });
|
|
262
|
+
const url = URL.createObjectURL(blobObj);
|
|
263
|
+
const a = document.createElement('a');
|
|
264
|
+
a.href = url;
|
|
265
|
+
a.target = '_blank';
|
|
266
|
+
a.style.display = 'none';
|
|
267
|
+
document.body.appendChild(a);
|
|
268
|
+
a.click();
|
|
269
|
+
setTimeout(() => {
|
|
270
|
+
document.body.removeChild(a);
|
|
271
|
+
URL.revokeObjectURL(url);
|
|
272
|
+
}, 100);
|
|
273
|
+
return { data: blob };
|
|
274
|
+
}
|
|
275
|
+
else if (contentType.includes('video') || contentType.includes('audio')) {
|
|
276
|
+
// 视频/音频预览 - 直接在新窗口打开 blob URL
|
|
277
|
+
const win = window.open(previewUrl, '_blank');
|
|
278
|
+
if (win) {
|
|
279
|
+
win.document.title = filename;
|
|
280
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
281
|
+
}
|
|
282
|
+
return { data: blob };
|
|
265
283
|
}
|
|
266
|
-
return { data: blob };
|
|
267
284
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
285
|
+
// 不支持的预览类型或preview=false时,直接下载
|
|
286
|
+
yield instance.saveBlob(blob, filename);
|
|
287
|
+
return { data: blob };
|
|
288
|
+
});
|
|
272
289
|
},
|
|
273
|
-
upload:
|
|
274
|
-
return new Promise((resolve,
|
|
290
|
+
upload: (url, option) => __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
return new Promise((resolve, _reject) => {
|
|
275
292
|
const button = document.createElement("input");
|
|
276
293
|
button.type = "file";
|
|
277
294
|
button.style.display = "none";
|
|
278
295
|
button.multiple = (option === null || option === void 0 ? void 0 : option.multiple) || false;
|
|
279
296
|
document.body.appendChild(button);
|
|
280
297
|
button.click(); // 手动触发点击
|
|
281
|
-
button.onchange =
|
|
298
|
+
button.onchange = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
282
299
|
const files = e.target.files;
|
|
283
300
|
if (files && files.length > 0) {
|
|
284
301
|
const formData = new FormData();
|
|
@@ -293,21 +310,21 @@ class WebPlatform {
|
|
|
293
310
|
for (let key in option === null || option === void 0 ? void 0 : option["data"]) {
|
|
294
311
|
formData.append(key, option["data"][key]);
|
|
295
312
|
}
|
|
296
|
-
const response =
|
|
313
|
+
const response = yield instance.fetchWithAuth(url, {
|
|
297
314
|
method: 'POST',
|
|
298
315
|
body: formData
|
|
299
316
|
});
|
|
300
317
|
button.remove();
|
|
301
|
-
resolve({ data:
|
|
318
|
+
resolve({ data: yield response.json() });
|
|
302
319
|
}
|
|
303
320
|
else {
|
|
304
321
|
button.remove();
|
|
305
322
|
resolve({ data: { Error: "没有选择文件" } });
|
|
306
323
|
}
|
|
307
|
-
};
|
|
324
|
+
});
|
|
308
325
|
});
|
|
309
|
-
},
|
|
310
|
-
getAsSse: (url, fn,
|
|
326
|
+
}),
|
|
327
|
+
getAsSse: (url, fn, _config) => {
|
|
311
328
|
return new Promise((resolve, reject) => {
|
|
312
329
|
instance.streamWithAuth(url, {
|
|
313
330
|
method: 'GET',
|
|
@@ -335,17 +352,19 @@ class WebPlatform {
|
|
|
335
352
|
setTitle(title) {
|
|
336
353
|
document.title = title;
|
|
337
354
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
355
|
+
saveBase64(base64, filename) {
|
|
356
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
357
|
+
const byteCharacters = atob(base64);
|
|
358
|
+
const byteNumbers = new Array(byteCharacters.length);
|
|
359
|
+
for (let i = 0; i < byteCharacters.length; i++) {
|
|
360
|
+
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
|
361
|
+
}
|
|
362
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
363
|
+
const blob = new Blob([byteArray], {
|
|
364
|
+
type: "application/octet-stream",
|
|
365
|
+
});
|
|
366
|
+
return this.saveBlob(blob, filename);
|
|
347
367
|
});
|
|
348
|
-
return this.saveBlob(blob, filename);
|
|
349
368
|
}
|
|
350
369
|
saveBlob(blob, filename) {
|
|
351
370
|
return new Promise((resolve, reject) => {
|
|
@@ -372,10 +391,10 @@ class WebPlatform {
|
|
|
372
391
|
navigator.vibrate(time || 200);
|
|
373
392
|
}
|
|
374
393
|
}
|
|
375
|
-
showInDeviceManager(
|
|
394
|
+
showInDeviceManager(_deviceId, _type) {
|
|
376
395
|
return Promise.resolve();
|
|
377
396
|
}
|
|
378
|
-
reloadGroup(
|
|
397
|
+
reloadGroup(_key) {
|
|
379
398
|
// No implementation in web platform
|
|
380
399
|
}
|
|
381
400
|
getGeo() {
|
|
@@ -395,16 +414,16 @@ class WebPlatform {
|
|
|
395
414
|
}
|
|
396
415
|
});
|
|
397
416
|
}
|
|
398
|
-
setResult(
|
|
417
|
+
setResult(_name, _value) {
|
|
399
418
|
// No implementation in web platform
|
|
400
419
|
}
|
|
401
|
-
setResultAs(
|
|
420
|
+
setResultAs(_name, _value, _type) {
|
|
402
421
|
// No implementation in web platform
|
|
403
422
|
}
|
|
404
423
|
setError(message) {
|
|
405
424
|
console.error(message);
|
|
406
425
|
}
|
|
407
|
-
setProgress(
|
|
426
|
+
setProgress(_precentage) {
|
|
408
427
|
// No implementation in web platform
|
|
409
428
|
}
|
|
410
429
|
}
|
package/dist/windows_platform.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.WindwosMiniAppPlatform = void 0;
|
|
4
13
|
class WindwosMiniAppPlatform {
|
|
5
14
|
constructor() {
|
|
15
|
+
// private messagePort?: MessagePort;
|
|
6
16
|
this.sseCallbacks = {};
|
|
7
17
|
this.token = "";
|
|
8
18
|
this.appCode = "";
|
|
@@ -17,9 +27,9 @@ class WindwosMiniAppPlatform {
|
|
|
17
27
|
getToken() {
|
|
18
28
|
return "";
|
|
19
29
|
}
|
|
20
|
-
setToken(
|
|
30
|
+
setToken(_token) {
|
|
21
31
|
}
|
|
22
|
-
setSelectedFarm(
|
|
32
|
+
setSelectedFarm(_farm) {
|
|
23
33
|
throw new Error("Method not implemented.");
|
|
24
34
|
}
|
|
25
35
|
setSelectedUnit(unit) {
|
|
@@ -72,11 +82,11 @@ class WindwosMiniAppPlatform {
|
|
|
72
82
|
const reader = new FileReader();
|
|
73
83
|
return new Promise((resolve, reject) => {
|
|
74
84
|
reader.readAsDataURL(blob);
|
|
75
|
-
reader.onloadend =
|
|
85
|
+
reader.onloadend = () => __awaiter(this, void 0, void 0, function* () {
|
|
76
86
|
const base64 = reader.result;
|
|
77
|
-
|
|
87
|
+
yield this.saveBase64(base64, filename);
|
|
78
88
|
resolve();
|
|
79
|
-
};
|
|
89
|
+
});
|
|
80
90
|
reader.onerror = (err) => {
|
|
81
91
|
reject(err);
|
|
82
92
|
};
|
package/factory_gateway.ts
CHANGED
|
@@ -24,7 +24,7 @@ export class FactoryGateway extends Object {
|
|
|
24
24
|
//获得工厂的单元信息
|
|
25
25
|
async unit(id: number): Promise<any> {
|
|
26
26
|
var axios = await this.context.ready;
|
|
27
|
-
const response = await axios.get(`/api/v1/
|
|
27
|
+
const response = await axios.get(`/api/v1/unit/${id}`);
|
|
28
28
|
return response.data;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -154,7 +154,7 @@ export class FactoryGateway extends Object {
|
|
|
154
154
|
//支持以下三个name:'capacity'(规模),'used_capacity'(存栏量),'workshop_count'(栋舍/车间数量),'manager'(负责人),'electric'/'water'/'feed' (电耗/水耗/饲料耗)
|
|
155
155
|
async entry(factory: Factory, name: string): Promise<any> {
|
|
156
156
|
var axios = await this.context.ready;
|
|
157
|
-
if (["electric", "water", "feed"].
|
|
157
|
+
if (["electric", "water", "feed"].indexOf(name) !== -1) {
|
|
158
158
|
const response = await axios.post(
|
|
159
159
|
`/api/v1/pigfarm/consumption/${factory.id}`,
|
|
160
160
|
{
|
package/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { AssistantGateway } from "./assistant_gateway";
|
|
|
8
8
|
import { EnergyGateway } from "./energy_gateway";
|
|
9
9
|
import { CameraGateway } from "./camera_gateway";
|
|
10
10
|
import { PigfarmGateway } from "./pigfarm_gateway";
|
|
11
|
-
import {
|
|
11
|
+
import { Factory, MyAxiosInstance, Unit } from "./types";
|
|
12
12
|
import { UnitGateway } from "./unit_gateway";
|
|
13
13
|
import { ChickenFarmGateway } from "./chickenfarm_gateway";
|
|
14
14
|
import { CarGateway } from "./car_gateway";
|
|
@@ -324,7 +324,7 @@ export class Cpzxrobot {
|
|
|
324
324
|
const localDomains = ["localhost", "127.0.0.1", "0.0.0.0"];
|
|
325
325
|
|
|
326
326
|
// 检查当前域名是否在本地开发域名列表中
|
|
327
|
-
return localDomains.
|
|
327
|
+
return localDomains.indexOf(domain) !== -1;
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
setTitle(title: string) {
|
|
@@ -335,7 +335,7 @@ export class Cpzxrobot {
|
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
addMessage(message: any){
|
|
338
|
+
addMessage(message: any) {
|
|
339
339
|
if (this.platform) {
|
|
340
340
|
this.platform.addMessage(message);
|
|
341
341
|
} else {
|