@7365admin1/layer-common 4.21.4-staging.347 → 4.21.4-staging.349
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/components/Robot/Fleet.vue +360 -0
- package/components/Robot/Form.vue +170 -0
- package/components/Robot/Map3D.vue +382 -0
- package/composables/useRobots.ts +125 -0
- package/package.json +2 -2
- package/utils/building-map.ts +366 -0
- package/utils/robot-display.ts +123 -0
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<AppCard class="pa-0">
|
|
3
|
+
<CardToolbar>
|
|
4
|
+
<template #left>
|
|
5
|
+
<AppSelect
|
|
6
|
+
v-model="selectedFloor"
|
|
7
|
+
:items="floorOptions"
|
|
8
|
+
item-title="title"
|
|
9
|
+
item-value="value"
|
|
10
|
+
label="Level"
|
|
11
|
+
density="compact"
|
|
12
|
+
hide-details
|
|
13
|
+
style="max-width: 180px"
|
|
14
|
+
:disabled="loading || !floorOptions.length"
|
|
15
|
+
/>
|
|
16
|
+
<span v-if="wallCount" class="text-caption text-medium-emphasis ml-4">
|
|
17
|
+
{{ wallCount }} walls found
|
|
18
|
+
</span>
|
|
19
|
+
</template>
|
|
20
|
+
<template #right>
|
|
21
|
+
<AppButton
|
|
22
|
+
variant="icon"
|
|
23
|
+
icon="mdi-rotate-left"
|
|
24
|
+
aria-label="Rotate left"
|
|
25
|
+
:disabled="loading"
|
|
26
|
+
@click="rotate(-1)"
|
|
27
|
+
/>
|
|
28
|
+
<AppButton
|
|
29
|
+
variant="icon"
|
|
30
|
+
icon="mdi-rotate-right"
|
|
31
|
+
aria-label="Rotate right"
|
|
32
|
+
:disabled="loading"
|
|
33
|
+
@click="rotate(1)"
|
|
34
|
+
/>
|
|
35
|
+
<AppButton
|
|
36
|
+
variant="icon"
|
|
37
|
+
:icon="tilted ? 'mdi-cube-outline' : 'mdi-floor-plan'"
|
|
38
|
+
:aria-label="tilted ? 'Show as a flat plan' : 'Show in 3D'"
|
|
39
|
+
:disabled="loading"
|
|
40
|
+
@click="toggleTilt"
|
|
41
|
+
/>
|
|
42
|
+
</template>
|
|
43
|
+
</CardToolbar>
|
|
44
|
+
|
|
45
|
+
<div ref="stage" class="robot-map3d">
|
|
46
|
+
<canvas ref="canvasEl" class="robot-map3d__canvas" />
|
|
47
|
+
|
|
48
|
+
<div v-if="loading" class="robot-map3d__overlay">
|
|
49
|
+
<v-progress-circular indeterminate size="28" />
|
|
50
|
+
<p class="text-body-2 mt-3 mb-0">Building the layout…</p>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<!--
|
|
54
|
+
A failure is named rather than left as an empty canvas. An empty canvas
|
|
55
|
+
and a failed load look identical, and they need opposite actions from
|
|
56
|
+
the person looking at the screen.
|
|
57
|
+
-->
|
|
58
|
+
<div v-else-if="error" class="robot-map3d__overlay">
|
|
59
|
+
<v-icon size="36" class="mb-2">mdi-map-marker-off-outline</v-icon>
|
|
60
|
+
<p class="text-body-2 mb-3">{{ error }}</p>
|
|
61
|
+
<AppButton size="small" variant="outlined" @click="load">Try again</AppButton>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div v-else-if="!wallCount" class="robot-map3d__overlay">
|
|
65
|
+
<v-icon size="36" class="mb-2">mdi-floor-plan</v-icon>
|
|
66
|
+
<p class="text-body-2 mb-0">
|
|
67
|
+
No walls could be found in this floor plan.
|
|
68
|
+
</p>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</AppCard>
|
|
72
|
+
</template>
|
|
73
|
+
|
|
74
|
+
<script lang="ts" setup>
|
|
75
|
+
/**
|
|
76
|
+
* The building, in 3D, generated from the robot's own floor plan.
|
|
77
|
+
*
|
|
78
|
+
* Nobody draws walls. The robot's map image is a SLAM occupancy grid — walls
|
|
79
|
+
* are already dark pixels — so it is fetched into a canvas, thresholded, traced
|
|
80
|
+
* into wall segments and extruded. Open-RMF does the same thing from an
|
|
81
|
+
* annotated plan; this skips the annotation because the robot has surveyed the
|
|
82
|
+
* building already.
|
|
83
|
+
*
|
|
84
|
+
* ## Why the image is fetched every time
|
|
85
|
+
*
|
|
86
|
+
* The vendor signs its map URLs for about an hour. A URL kept in a record is a
|
|
87
|
+
* URL that stops working, so it is asked for at the moment of display — the
|
|
88
|
+
* same trap the Virtual Patrol camera addresses hit.
|
|
89
|
+
*
|
|
90
|
+
* ## Why there is no 3D engine
|
|
91
|
+
*
|
|
92
|
+
* The scene is extruded boxes on flat floors. A parallel projection and a
|
|
93
|
+
* back-to-front draw order render that correctly, and `layer-common` is
|
|
94
|
+
* consumed by eleven web apps — an engine is a large thing to put in all of
|
|
95
|
+
* them for a shape this simple.
|
|
96
|
+
*
|
|
97
|
+
* ponytail: painter's algorithm, fixed camera, flat shading by face angle. No
|
|
98
|
+
* lighting model, no textures, no orbit. Swap Three.js in behind `levelSolids`
|
|
99
|
+
* and `projectPoint` if those ever matter; the geometry does not change.
|
|
100
|
+
*/
|
|
101
|
+
import {
|
|
102
|
+
depthOf,
|
|
103
|
+
fitView,
|
|
104
|
+
gridFromImageData,
|
|
105
|
+
levelSolids,
|
|
106
|
+
projectPoint,
|
|
107
|
+
wallCorners,
|
|
108
|
+
wallsFromOccupancyGrid,
|
|
109
|
+
type TView,
|
|
110
|
+
type TWallSolid,
|
|
111
|
+
} from "../../utils/building-map";
|
|
112
|
+
import { robotErrorMessage } from "../../utils/robot-display";
|
|
113
|
+
|
|
114
|
+
const props = defineProps<{
|
|
115
|
+
/** The robot whose maps describe this building. */
|
|
116
|
+
robotId: string;
|
|
117
|
+
/** Drawn on the plan when its position and floor are both known. */
|
|
118
|
+
robotState?: Record<string, any> | null;
|
|
119
|
+
}>();
|
|
120
|
+
|
|
121
|
+
const { getRobotMaps, getRobotMapImages } = useRobots();
|
|
122
|
+
|
|
123
|
+
const stage = ref<HTMLElement | null>(null);
|
|
124
|
+
const canvasEl = ref<HTMLCanvasElement | null>(null);
|
|
125
|
+
|
|
126
|
+
const maps = ref<Array<Record<string, any>>>([]);
|
|
127
|
+
const selectedFloor = ref<number | null>(null);
|
|
128
|
+
const solids = ref<TWallSolid[]>([]);
|
|
129
|
+
const imageHeight = ref(0);
|
|
130
|
+
const loading = ref(true);
|
|
131
|
+
const error = ref("");
|
|
132
|
+
const rotation = ref(Math.PI / 5);
|
|
133
|
+
const tilted = ref(true);
|
|
134
|
+
|
|
135
|
+
const wallCount = computed(() => solids.value.length);
|
|
136
|
+
|
|
137
|
+
const floorOptions = computed(() =>
|
|
138
|
+
maps.value
|
|
139
|
+
.map((m) => ({ title: m.mapName?.trim() || `Floor ${m.floorNo}`, value: m.floorNo }))
|
|
140
|
+
.sort((a, b) => a.value - b.value),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const currentMap = computed(() =>
|
|
144
|
+
maps.value.find((m) => m.floorNo === selectedFloor.value) ?? null,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
/* ------------------------------------------------------------------ load */
|
|
148
|
+
|
|
149
|
+
async function load() {
|
|
150
|
+
loading.value = true;
|
|
151
|
+
error.value = "";
|
|
152
|
+
try {
|
|
153
|
+
if (!maps.value.length) {
|
|
154
|
+
const res = await getRobotMaps(props.robotId);
|
|
155
|
+
maps.value = res?.items ?? [];
|
|
156
|
+
if (!maps.value.length) {
|
|
157
|
+
error.value = "This robot has no floor maps yet.";
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
selectedFloor.value = floorOptions.value[0]?.value ?? null;
|
|
161
|
+
}
|
|
162
|
+
await buildLevel();
|
|
163
|
+
} catch (e) {
|
|
164
|
+
error.value = robotErrorMessage(e, "Could not load this building's floor plan.");
|
|
165
|
+
} finally {
|
|
166
|
+
loading.value = false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Fetch this floor's plan, trace its walls, and extrude them. */
|
|
171
|
+
async function buildLevel() {
|
|
172
|
+
const map = currentMap.value;
|
|
173
|
+
solids.value = [];
|
|
174
|
+
if (!map?.backgroundFileKey) {
|
|
175
|
+
error.value = "This floor has no plan image.";
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const files = await getRobotMapImages(props.robotId, [map.backgroundFileKey]);
|
|
180
|
+
const url = files?.items?.find((f: any) => f.fileKey === map.backgroundFileKey)?.url;
|
|
181
|
+
if (!url) {
|
|
182
|
+
error.value = "The floor plan image could not be fetched.";
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const image = await loadImage(url);
|
|
187
|
+
imageHeight.value = image.height;
|
|
188
|
+
|
|
189
|
+
const work = document.createElement("canvas");
|
|
190
|
+
work.width = image.width;
|
|
191
|
+
work.height = image.height;
|
|
192
|
+
const wctx = work.getContext("2d", { willReadFrequently: true });
|
|
193
|
+
if (!wctx) {
|
|
194
|
+
error.value = "This browser could not read the floor plan image.";
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
wctx.drawImage(image, 0, 0);
|
|
198
|
+
|
|
199
|
+
const { data } = wctx.getImageData(0, 0, image.width, image.height);
|
|
200
|
+
const grid = gridFromImageData(data, image.width, image.height);
|
|
201
|
+
const { vertices, walls } = wallsFromOccupancyGrid(grid, { minRunPx: 6 });
|
|
202
|
+
|
|
203
|
+
solids.value = levelSolids(
|
|
204
|
+
{
|
|
205
|
+
name: map.mapName ?? `L${map.floorNo}`,
|
|
206
|
+
elevationM: 0,
|
|
207
|
+
scaleMPerPx: Number(map.resolution) || 0.05,
|
|
208
|
+
originXM: Number(map.originX) || 0,
|
|
209
|
+
originYM: Number(map.originY) || 0,
|
|
210
|
+
vertices,
|
|
211
|
+
walls,
|
|
212
|
+
},
|
|
213
|
+
image.height,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
draw();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* `crossOrigin` is set because the pixels are read back, and a canvas tainted
|
|
221
|
+
* by a cross-origin image throws on `getImageData` — which would look like a
|
|
222
|
+
* broken floor plan rather than a CORS rule.
|
|
223
|
+
*/
|
|
224
|
+
function loadImage(url: string): Promise<HTMLImageElement> {
|
|
225
|
+
return new Promise((resolve, reject) => {
|
|
226
|
+
const img = new Image();
|
|
227
|
+
img.crossOrigin = "anonymous";
|
|
228
|
+
img.onload = () => resolve(img);
|
|
229
|
+
img.onerror = () => reject(new Error("The floor plan image could not be loaded."));
|
|
230
|
+
img.src = url;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* ------------------------------------------------------------------ draw */
|
|
235
|
+
|
|
236
|
+
function draw() {
|
|
237
|
+
const canvas = canvasEl.value;
|
|
238
|
+
const host = stage.value;
|
|
239
|
+
if (!canvas || !host) return;
|
|
240
|
+
|
|
241
|
+
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
242
|
+
const width = host.clientWidth;
|
|
243
|
+
const height = host.clientHeight;
|
|
244
|
+
canvas.width = width * dpr;
|
|
245
|
+
canvas.height = height * dpr;
|
|
246
|
+
canvas.style.width = `${width}px`;
|
|
247
|
+
canvas.style.height = `${height}px`;
|
|
248
|
+
|
|
249
|
+
const ctx = canvas.getContext("2d");
|
|
250
|
+
if (!ctx) return;
|
|
251
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
252
|
+
ctx.clearRect(0, 0, width, height);
|
|
253
|
+
|
|
254
|
+
const view: TView = fitView(solids.value, { width, height }, {
|
|
255
|
+
rotation: rotation.value,
|
|
256
|
+
tilt: tilted.value ? 0.95 : 0,
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// Painter's algorithm: with no depth buffer, draw order IS the depth test.
|
|
260
|
+
const ordered = [...solids.value].sort(
|
|
261
|
+
(a, b) => depthOf(a.centre, view) - depthOf(b.centre, view),
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
for (const solid of ordered) drawBox(ctx, solid, view);
|
|
265
|
+
drawRobot(ctx, view);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** The three visible faces of a box: top, and two sides. */
|
|
269
|
+
function drawBox(ctx: CanvasRenderingContext2D, solid: TWallSolid, view: TView) {
|
|
270
|
+
const c = wallCorners(solid).map((p) => projectPoint(p.x, p.y, p.z, view));
|
|
271
|
+
// wallCorners emits the bottom four then the top four, in the same order.
|
|
272
|
+
const faces: Array<{ idx: number[]; shade: number }> = [
|
|
273
|
+
{ idx: [4, 5, 6, 7], shade: 1 }, // top, lit
|
|
274
|
+
{ idx: [0, 1, 5, 4], shade: 0.78 },
|
|
275
|
+
{ idx: [1, 2, 6, 5], shade: 0.62 },
|
|
276
|
+
{ idx: [2, 3, 7, 6], shade: 0.78 },
|
|
277
|
+
{ idx: [3, 0, 4, 7], shade: 0.62 },
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
for (const face of faces) {
|
|
281
|
+
ctx.beginPath();
|
|
282
|
+
face.idx.forEach((i, n) => (n === 0 ? ctx.moveTo(c[i].x, c[i].y) : ctx.lineTo(c[i].x, c[i].y)));
|
|
283
|
+
ctx.closePath();
|
|
284
|
+
const v = Math.round(150 * face.shade + 60);
|
|
285
|
+
ctx.fillStyle = `rgb(${v},${v + 4},${v + 8})`;
|
|
286
|
+
ctx.fill();
|
|
287
|
+
ctx.strokeStyle = "rgba(20,28,38,0.22)";
|
|
288
|
+
ctx.lineWidth = 0.6;
|
|
289
|
+
ctx.stroke();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* The robot, only when its position AND its floor are both known.
|
|
295
|
+
*
|
|
296
|
+
* The vendor's tracking stream carries no floor, so drawing it on whichever
|
|
297
|
+
* level happens to be selected would put it on a storey nobody confirmed — and
|
|
298
|
+
* a robot shown in the wrong place is worse than one not shown.
|
|
299
|
+
*/
|
|
300
|
+
function drawRobot(ctx: CanvasRenderingContext2D, view: TView) {
|
|
301
|
+
const state = props.robotState;
|
|
302
|
+
const pos = state?.position;
|
|
303
|
+
if (!pos || state?.floorKnown !== true) return;
|
|
304
|
+
if (state.floorNo !== selectedFloor.value) return;
|
|
305
|
+
|
|
306
|
+
const base = projectPoint(pos.x, pos.y, 0, view);
|
|
307
|
+
const top = projectPoint(pos.x, pos.y, 0.9, view);
|
|
308
|
+
|
|
309
|
+
ctx.beginPath();
|
|
310
|
+
ctx.moveTo(base.x, base.y);
|
|
311
|
+
ctx.lineTo(top.x, top.y);
|
|
312
|
+
ctx.strokeStyle = "#FF5A1F";
|
|
313
|
+
ctx.lineWidth = 2;
|
|
314
|
+
ctx.stroke();
|
|
315
|
+
|
|
316
|
+
ctx.beginPath();
|
|
317
|
+
ctx.arc(top.x, top.y, 6, 0, Math.PI * 2);
|
|
318
|
+
ctx.fillStyle = "#FF5A1F";
|
|
319
|
+
ctx.fill();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/* --------------------------------------------------------------- controls */
|
|
323
|
+
|
|
324
|
+
function rotate(direction: number) {
|
|
325
|
+
rotation.value += (direction * Math.PI) / 12;
|
|
326
|
+
draw();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function toggleTilt() {
|
|
330
|
+
tilted.value = !tilted.value;
|
|
331
|
+
draw();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
watch(selectedFloor, async () => {
|
|
335
|
+
if (!maps.value.length) return;
|
|
336
|
+
loading.value = true;
|
|
337
|
+
error.value = "";
|
|
338
|
+
try {
|
|
339
|
+
await buildLevel();
|
|
340
|
+
} catch (e) {
|
|
341
|
+
error.value = robotErrorMessage(e, "Could not load this floor.");
|
|
342
|
+
} finally {
|
|
343
|
+
loading.value = false;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
watch(() => props.robotState, draw, { deep: true });
|
|
348
|
+
|
|
349
|
+
let onResize: (() => void) | undefined;
|
|
350
|
+
onMounted(() => {
|
|
351
|
+
load();
|
|
352
|
+
onResize = () => draw();
|
|
353
|
+
window.addEventListener("resize", onResize);
|
|
354
|
+
});
|
|
355
|
+
onBeforeUnmount(() => {
|
|
356
|
+
if (onResize) window.removeEventListener("resize", onResize);
|
|
357
|
+
});
|
|
358
|
+
</script>
|
|
359
|
+
|
|
360
|
+
<style scoped>
|
|
361
|
+
.robot-map3d {
|
|
362
|
+
position: relative;
|
|
363
|
+
width: 100%;
|
|
364
|
+
height: 460px;
|
|
365
|
+
background: linear-gradient(180deg, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.06));
|
|
366
|
+
}
|
|
367
|
+
.robot-map3d__canvas {
|
|
368
|
+
display: block;
|
|
369
|
+
width: 100%;
|
|
370
|
+
height: 100%;
|
|
371
|
+
}
|
|
372
|
+
.robot-map3d__overlay {
|
|
373
|
+
position: absolute;
|
|
374
|
+
inset: 0;
|
|
375
|
+
display: flex;
|
|
376
|
+
flex-direction: column;
|
|
377
|
+
align-items: center;
|
|
378
|
+
justify-content: center;
|
|
379
|
+
text-align: center;
|
|
380
|
+
padding: 24px;
|
|
381
|
+
}
|
|
382
|
+
</style>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cleaning robots at a site.
|
|
3
|
+
*
|
|
4
|
+
* Two halves, matching the API. `/api/robots` manages the RECORD — register a
|
|
5
|
+
* robot, list an estate's robots. `/api/robots/:id/*` manages the ROBOT itself,
|
|
6
|
+
* and every one of those calls reaches the vendor's cloud, so they are slower
|
|
7
|
+
* and they can fail for reasons that have nothing to do with us (the robot is
|
|
8
|
+
* off, the cloud is unreachable, the credentials were rotated). Screens should
|
|
9
|
+
* show what the failure was rather than an empty list.
|
|
10
|
+
*
|
|
11
|
+
* `appSlug` is sent on the reads so the API narrows the result to the robot
|
|
12
|
+
* types this application presents: a cleaning app never sees a security patrol.
|
|
13
|
+
* It is a visibility rule, not a security boundary — the boundary is the session
|
|
14
|
+
* and the permission — but sending it consistently is what keeps the screens
|
|
15
|
+
* honest.
|
|
16
|
+
*/
|
|
17
|
+
export default function useRobots() {
|
|
18
|
+
const appSlug = useRuntimeConfig().public?.appSlug as string | undefined;
|
|
19
|
+
|
|
20
|
+
/** The estate's robots. Credentials are never in this response. */
|
|
21
|
+
async function getRobots({
|
|
22
|
+
organization = "",
|
|
23
|
+
site = "",
|
|
24
|
+
search = "",
|
|
25
|
+
page = 1,
|
|
26
|
+
limit = 10,
|
|
27
|
+
type = "",
|
|
28
|
+
} = {}) {
|
|
29
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
30
|
+
`/api/robots/organization/${organization}/site/${site}`,
|
|
31
|
+
{ method: "GET", query: { search, page, limit, type, appSlug } },
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Register a robot.
|
|
37
|
+
*
|
|
38
|
+
* `appKey` and `appToken` are the vendor cloud credentials. They go up once,
|
|
39
|
+
* are never returned by any read, and must never be put into a query string,
|
|
40
|
+
* a log line or a toast.
|
|
41
|
+
*/
|
|
42
|
+
function createRobot(payload: {
|
|
43
|
+
name: string;
|
|
44
|
+
appKey: string;
|
|
45
|
+
appToken: string;
|
|
46
|
+
type?: "cleaning" | "security";
|
|
47
|
+
robotSn?: string;
|
|
48
|
+
metadata: { orgId: string; siteId: string; administratorId?: string };
|
|
49
|
+
}) {
|
|
50
|
+
return useNuxtApp().$api<Record<string, any>>("/api/robots", {
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: payload,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Live state — mode, online, whether it can take a job right now. */
|
|
57
|
+
function getRobotState(id: string) {
|
|
58
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
59
|
+
`/api/robots/${id}/state`,
|
|
60
|
+
{ method: "GET", query: { appSlug } },
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The robot's floors, their areas and their metre/pixel transform. */
|
|
65
|
+
function getRobotMaps(id: string) {
|
|
66
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
67
|
+
`/api/robots/${id}/maps`,
|
|
68
|
+
{ method: "GET", query: { appSlug } },
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Signed image URLs for a map's layers.
|
|
74
|
+
*
|
|
75
|
+
* Fetched at the moment of display and never stored: the vendor signs them for
|
|
76
|
+
* about an hour, so a URL kept in a record is a URL that stops working. If a
|
|
77
|
+
* floor plan has gone blank, ask for the URLs again rather than caching harder.
|
|
78
|
+
*/
|
|
79
|
+
function getRobotMapImages(id: string, fileKeys: string[]) {
|
|
80
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
81
|
+
`/api/robots/${id}/map-images`,
|
|
82
|
+
{ method: "POST", query: { appSlug }, body: { fileKeys } },
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The cleaning schedule the vendor cloud holds for this robot. */
|
|
87
|
+
function getRobotPlans(id: string) {
|
|
88
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
89
|
+
`/api/robots/${id}/plans`,
|
|
90
|
+
{ method: "GET", query: { appSlug } },
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Send the robot to work, or bring it home.
|
|
96
|
+
*
|
|
97
|
+
* The API accepts exactly one outstanding job per robot and returns no job id,
|
|
98
|
+
* so a screen cannot track a command after sending it — it re-reads the state.
|
|
99
|
+
* A robot that is not idle is refused by the server with a readable reason;
|
|
100
|
+
* show that reason rather than a generic failure.
|
|
101
|
+
*/
|
|
102
|
+
function sendRobotCommand(
|
|
103
|
+
id: string,
|
|
104
|
+
command:
|
|
105
|
+
| { kind: "return" }
|
|
106
|
+
| { kind: "full"; cleanTimes?: number; modeFlag?: number; subModeFlag?: number; levelFlag?: number }
|
|
107
|
+
| { kind: "area"; areas: string[]; cleanTimes?: number; modeFlag?: number; subModeFlag?: number; levelFlag?: number }
|
|
108
|
+
| { kind: "spot"; points: Array<{ x: number; y: number }>; cleanTimes?: number; modeFlag?: number; subModeFlag?: number; levelFlag?: number },
|
|
109
|
+
) {
|
|
110
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
111
|
+
`/api/robots/${id}/command`,
|
|
112
|
+
{ method: "POST", query: { appSlug }, body: command },
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
getRobots,
|
|
118
|
+
createRobot,
|
|
119
|
+
getRobotState,
|
|
120
|
+
getRobotMaps,
|
|
121
|
+
getRobotMapImages,
|
|
122
|
+
getRobotPlans,
|
|
123
|
+
sendRobotCommand,
|
|
124
|
+
};
|
|
125
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "4.21.4-staging.
|
|
5
|
+
"version": "4.21.4-staging.349",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"build": "nuxt build .playground",
|
|
37
37
|
"generate": "nuxt generate .playground",
|
|
38
38
|
"preview": "nuxt preview .playground",
|
|
39
|
-
"test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
39
|
+
"test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && esbuild utils/robot-display.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-display.mjs --log-level=error && esbuild utils/building-map.ts --bundle --platform=node --format=esm --outfile=test/.build/building-map.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
|
|
40
40
|
"test:units": "node --experimental-strip-types --test \"utils/*.test.ts\"",
|
|
41
41
|
"release": "yarn run build && changeset publish"
|
|
42
42
|
},
|