@7365admin1/layer-common 4.30.0 → 4.32.0
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/CHANGELOG.md +16 -4
- package/assets/css/robot-hero.css +489 -1
- package/components/Robot/BuildingMap.vue +403 -0
- package/components/Robot/Detail.vue +445 -0
- package/components/Robot/Fleet.vue +3 -1
- package/components/Robot/FloorPlan.vue +43 -0
- package/components/Robot/LiftQueue.vue +247 -0
- package/components/Robot/LivePlan.vue +59 -0
- package/components/Robot/MapEditor.vue +233 -0
- package/components/Robot/Mark.vue +17 -0
- package/components/Robot/MiniMap.vue +120 -0
- package/components/Robot/PatrolRoutes.vue +48 -0
- package/components/Robot/SiteFleet.vue +266 -0
- package/components/Robot/SiteHeader.vue +64 -0
- package/components/Robot/SiteScreen.vue +195 -0
- package/components/Robot/Table.vue +4 -1
- package/composables/useRobotBuilding.ts +66 -0
- package/composables/useRobotLive.ts +18 -0
- package/composables/useRobots.ts +52 -1
- package/package.json +2 -2
- package/utils/robot-building.ts +521 -0
- package/utils/robot-display.ts +520 -9
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
3D BUILDING MAP (README §4): the site's floors as stacked planes seen in
|
|
4
|
+
CSS 3D, robots as status-colour squares with a pin and an upright name,
|
|
5
|
+
patrol routes for security, the lift shafts through every floor. Drag to
|
|
6
|
+
rotate, shift/right/middle-drag to pan, wheel to zoom; ISO/TOP/SIDE/UNDER
|
|
7
|
+
presets and a floor filter. "Edit map" (set-up permitted) swaps in the
|
|
8
|
+
2D editor, which saves through the building-map API.
|
|
9
|
+
-->
|
|
10
|
+
<div class="hero-head">
|
|
11
|
+
<div>
|
|
12
|
+
<button v-if="backToNetwork" type="button" class="hero-back hero-back--sm" @click="emit('network')">‹ Network</button>
|
|
13
|
+
<div class="hero-kicker hero-kicker--accent">{{ clientName || names.clientName }}</div>
|
|
14
|
+
<h2 class="hero-title">{{ siteLabel }} · building map</h2>
|
|
15
|
+
</div>
|
|
16
|
+
<span class="hero-head__spacer" />
|
|
17
|
+
<v-btn variant="outlined" class="hero-btn-icon" @click="fullscreen(editing ? editor?.root : viewer)">
|
|
18
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" /></svg>
|
|
19
|
+
Full screen
|
|
20
|
+
</v-btn>
|
|
21
|
+
<v-btn v-if="canEditMap" :variant="editing ? 'outlined' : 'flat'" :color="editing ? undefined : 'primary'" @click="editing = !editing">
|
|
22
|
+
{{ editing ? "Exit edit mode" : "Edit map" }}
|
|
23
|
+
</v-btn>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div v-if="error" class="hero-notice" role="alert">{{ error }}</div>
|
|
27
|
+
<div v-else-if="!loading && emptyNote" class="hero-notice">{{ emptyNote }}</div>
|
|
28
|
+
|
|
29
|
+
<RobotMapEditor
|
|
30
|
+
v-if="editing && canEditMap"
|
|
31
|
+
ref="editor"
|
|
32
|
+
:map="map"
|
|
33
|
+
:floors="floors"
|
|
34
|
+
:site-name="siteLabel"
|
|
35
|
+
:owner-robot-id="ownerRobotId"
|
|
36
|
+
:start-floor="startFloor"
|
|
37
|
+
@saved="onSaved"
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
<div v-else class="hero-split hero-bmap">
|
|
41
|
+
<div
|
|
42
|
+
ref="viewer"
|
|
43
|
+
class="hero-bmap__viewer"
|
|
44
|
+
:class="{ 'hero-bmap__viewer--grab': !drag, 'hero-bmap__viewer--pan': drag?.mode === 'pan', 'hero-bmap__viewer--rotate': drag?.mode === 'rotate' }"
|
|
45
|
+
@mousedown="onDown"
|
|
46
|
+
@mousemove="onMove"
|
|
47
|
+
@mouseup="drag = null"
|
|
48
|
+
@mouseleave="drag = null"
|
|
49
|
+
@wheel.prevent="cam = { ...cam, zoom: wheelZoom(cam.zoom, $event.deltaY) }"
|
|
50
|
+
@contextmenu.prevent
|
|
51
|
+
>
|
|
52
|
+
<span class="hero-plan__scan" aria-hidden="true" />
|
|
53
|
+
|
|
54
|
+
<div class="hero-bmap__zoom">
|
|
55
|
+
<button type="button" title="Zoom in" aria-label="Zoom in" @click="cam = { ...cam, zoom: zoomIn(cam.zoom) }">+</button>
|
|
56
|
+
<button type="button" title="Zoom out" aria-label="Zoom out" @click="cam = { ...cam, zoom: zoomOut(cam.zoom) }">−</button>
|
|
57
|
+
<button type="button" title="Reset view" aria-label="Reset view" @click="cam = resetCamera(cam)">
|
|
58
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M3 12a9 9 0 1 0 3-6.7L3 8" /><path d="M3 3v5h5" /></svg>
|
|
59
|
+
</button>
|
|
60
|
+
<button
|
|
61
|
+
type="button"
|
|
62
|
+
:title="cam.orbit ? 'Stop auto-orbit' : 'Start auto-orbit'"
|
|
63
|
+
:aria-label="cam.orbit ? 'Stop auto-orbit' : 'Start auto-orbit'"
|
|
64
|
+
:aria-pressed="cam.orbit"
|
|
65
|
+
:class="{ 'hero-bmap__orbit--on': cam.orbit }"
|
|
66
|
+
@click="cam = toggleOrbit(cam)"
|
|
67
|
+
>
|
|
68
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><ellipse cx="12" cy="12" rx="10" ry="4" /><circle cx="12" cy="12" r="2.5" fill="currentColor" /></svg>
|
|
69
|
+
</button>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div class="hero-bmap__bar">
|
|
73
|
+
<div class="hero-bmap__seg" role="group" aria-label="View angle">
|
|
74
|
+
<button v-for="(a, id) in MAP_ANGLES" :key="id" type="button" :aria-pressed="cam.angle === id" @click="cam = presetCamera(cam, id)">{{ a.label }}</button>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="hero-bmap__seg" role="group" aria-label="Floor">
|
|
77
|
+
<button type="button" :aria-pressed="focus === null" @click="focus = null">All</button>
|
|
78
|
+
<button v-for="f in floors" :key="f" type="button" :aria-pressed="focus === f" @click="focus = f">{{ floorName(f) }}</button>
|
|
79
|
+
</div>
|
|
80
|
+
<span class="hero-bmap__readout">{{ cameraReadout(cam) }}</span>
|
|
81
|
+
<span class="hero-bmap__readout">Drag to rotate · shift+drag or right-drag to pan · scroll to zoom</span>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
<div class="hero-bmap__live"><span class="hero-live__dot" :class="{ 'hero-live__dot--off': !connected }" aria-hidden="true" />Live telemetry</div>
|
|
85
|
+
|
|
86
|
+
<div v-if="loading" class="hero-bmap__loading" role="status">
|
|
87
|
+
<span v-for="i in 3" :key="i" class="hero-skel__row" />
|
|
88
|
+
<span class="hero-muted">Loading the building map…</span>
|
|
89
|
+
</div>
|
|
90
|
+
<RobotReconnecting v-else-if="!connected" />
|
|
91
|
+
|
|
92
|
+
<div class="hero-bmap__view" :style="{ transform: `translate(${cam.panX}px, ${cam.panY}px) scale(${cam.zoom})`, transition: drag ? 'none' : 'transform .25s ease' }">
|
|
93
|
+
<div
|
|
94
|
+
class="hero-bmap__stack"
|
|
95
|
+
:style="{
|
|
96
|
+
'--shift': `${stack.shift}px`,
|
|
97
|
+
transform: `rotateX(${cam.tilt}deg) rotateZ(${cam.turn}deg) translateZ(${stack.shift}px)`,
|
|
98
|
+
transition: drag ? 'none' : 'transform .6s ease',
|
|
99
|
+
animation: orbiting ? 'heroOrbit 18s ease-in-out infinite' : 'none',
|
|
100
|
+
}"
|
|
101
|
+
>
|
|
102
|
+
<div
|
|
103
|
+
v-for="(f, i) in floors3d"
|
|
104
|
+
:key="f.floorNo"
|
|
105
|
+
class="hero-bmap__floor"
|
|
106
|
+
:style="{ transform: `translateZ(${i * FLOOR_GAP_PX}px)`, opacity: f.dim, '--hero-fill': look.fill }"
|
|
107
|
+
>
|
|
108
|
+
<span class="hero-bmap__room" style="left: 8%; top: 10%; width: 34%; height: 30%" aria-hidden="true" />
|
|
109
|
+
<span class="hero-bmap__room" style="left: 58%; top: 10%; width: 34%; height: 44%" aria-hidden="true" />
|
|
110
|
+
<span class="hero-bmap__room" style="left: 8%; top: 62%; width: 60%; height: 28%" aria-hidden="true" />
|
|
111
|
+
<template v-if="!map">
|
|
112
|
+
<span class="hero-bmap__door" style="left: 42%; top: 22%" aria-hidden="true" />
|
|
113
|
+
<span class="hero-bmap__door" style="left: 58%; top: 30%" aria-hidden="true" />
|
|
114
|
+
</template>
|
|
115
|
+
<svg v-if="f.shapes.length" class="hero-plan__svg" viewBox="0 0 100 100" preserveAspectRatio="none" aria-hidden="true">
|
|
116
|
+
<template v-for="s in f.shapes" :key="s.id">
|
|
117
|
+
<polygon v-if="s.kind === 'zone'" class="hero-bmap__zone" :points="svgPoints(s)" vector-effect="non-scaling-stroke" />
|
|
118
|
+
<line v-else-if="s.kind === 'wall'" class="hero-bmap__wall" :x1="s.points[0]!.x" :y1="s.points[0]!.y" :x2="s.points[1]!.x" :y2="s.points[1]!.y" vector-effect="non-scaling-stroke" />
|
|
119
|
+
<line v-else-if="s.kind === 'door'" class="hero-bmap__doorline" :x1="s.points[0]!.x" :y1="s.points[0]!.y" :x2="s.points[1]!.x" :y2="s.points[1]!.y" vector-effect="non-scaling-stroke" />
|
|
120
|
+
</template>
|
|
121
|
+
</svg>
|
|
122
|
+
|
|
123
|
+
<template v-if="type === 'security'">
|
|
124
|
+
<svg class="hero-plan__svg" viewBox="0 0 400 300" preserveAspectRatio="none" aria-hidden="true">
|
|
125
|
+
<path v-for="r in f.routes" :key="r.id" class="hero-plan__route hero-plan__route--anim" :d="routePathD(r.checkpoints)" vector-effect="non-scaling-stroke" />
|
|
126
|
+
</svg>
|
|
127
|
+
<div v-for="t in routeTags(f.routes)" :key="`t-${t.key}`" class="hero-bmap__anchor" :style="{ left: t.left, top: t.top }">
|
|
128
|
+
<div class="hero-bmap__routetag" :style="{ transform: `translateZ(30px) ${unskew}` }">{{ t.name }}</div>
|
|
129
|
+
</div>
|
|
130
|
+
<div v-for="m in routeMarks(f.routes)" :key="`m-${m.key}`" class="hero-bmap__anchor" :style="{ left: m.left, top: m.top }">
|
|
131
|
+
<div class="hero-bmap__cp">{{ m.n }}</div>
|
|
132
|
+
<div class="hero-bmap__cplabel" :style="{ transform: `translateZ(8px) ${unskew}` }">{{ m.label }}</div>
|
|
133
|
+
</div>
|
|
134
|
+
</template>
|
|
135
|
+
|
|
136
|
+
<div
|
|
137
|
+
v-for="r in f.robots"
|
|
138
|
+
:key="r.id"
|
|
139
|
+
class="hero-bmap__anchor hero-bmap__bot"
|
|
140
|
+
:style="{ left: r.left, top: r.top, transition: `left ${tickMs}ms linear, top ${tickMs}ms linear`, '--hero-bot': toneColor(r) }"
|
|
141
|
+
>
|
|
142
|
+
<span class="hero-bmap__ping" aria-hidden="true" />
|
|
143
|
+
<span class="hero-bmap__body" aria-hidden="true" />
|
|
144
|
+
<span class="hero-bmap__pin" :style="{ height: `${look.pinH}px` }" aria-hidden="true" />
|
|
145
|
+
<span class="hero-bmap__pin hero-bmap__pin--y" :style="{ height: `${look.pinH}px` }" aria-hidden="true" />
|
|
146
|
+
<button type="button" class="hero-bmap__name" :style="{ transform: `translateZ(${look.pinZ}px) ${unskew}` }" @click.stop="emit('open', r.id)" @mousedown.stop>
|
|
147
|
+
{{ r.name }}
|
|
148
|
+
</button>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<div class="hero-bmap__floorlabel" :style="{ transform: `translateZ(6px) ${unskew}` }">{{ floorName(f.floorNo) }}</div>
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<div
|
|
155
|
+
v-for="s in shafts"
|
|
156
|
+
:key="s.id"
|
|
157
|
+
class="hero-bmap__shaft"
|
|
158
|
+
:style="{ left: `${s.x}%`, top: `${s.y}%`, transform: `translateZ(${s.z}px)`, opacity: look.shaftOpacity }"
|
|
159
|
+
>
|
|
160
|
+
<span class="hero-bmap__shaftwall" :style="{ width: `${s.w}px`, height: `${s.h}px` }" />
|
|
161
|
+
<span class="hero-bmap__shaftwall hero-bmap__shaftwall--y" :style="{ width: `${s.h}px`, height: `${s.d}px` }" />
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<div class="hero-bmap__legend">
|
|
167
|
+
<span><i class="hero-bmap__key hero-bmap__key--door" />Door</span>
|
|
168
|
+
<span><i class="hero-bmap__key hero-bmap__key--shaft" />Lift shaft</span>
|
|
169
|
+
<span><i class="hero-bmap__key hero-bmap__key--bot" />Robot (live)</span>
|
|
170
|
+
<span v-if="type === 'security'"><i class="hero-bmap__key hero-bmap__key--route" />Patrol route · numbered checkpoints</span>
|
|
171
|
+
</div>
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
<aside class="hero-bmap__aside">
|
|
175
|
+
<div class="hero-aside__title hero-bmap__asidetitle">Floors · top down</div>
|
|
176
|
+
<div v-for="f in legend" :key="f.floorNo" class="hero-bmap__legendrow">
|
|
177
|
+
<b>{{ floorName(f.floorNo) }}</b>
|
|
178
|
+
<div class="hero-bmap__chips">
|
|
179
|
+
<button v-for="r in f.robots" :key="r.id" type="button" class="hero-bmap__chip" @click="emit('open', r.id)"><span :class="`hero-tone--${tone(r)}`">{{ r.name }}</span></button>
|
|
180
|
+
<span v-if="!f.robots.length" class="hero-muted">—</span>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
<div v-if="unplaced.length" class="hero-bmap__tray">
|
|
184
|
+
<div class="hero-aside__title">Floor unknown</div>
|
|
185
|
+
<div class="hero-bmap__chips">
|
|
186
|
+
<button v-for="r in unplaced" :key="String(r._id)" type="button" class="hero-bmap__chip" @click="emit('open', String(r._id))"><span :class="`hero-tone--${unplacedTone(r)}`">{{ r.name }}</span></button>
|
|
187
|
+
</div>
|
|
188
|
+
<div class="hero-bmap__traytext">{{ unplacedLine }}</div>
|
|
189
|
+
</div>
|
|
190
|
+
</aside>
|
|
191
|
+
</div>
|
|
192
|
+
</template>
|
|
193
|
+
|
|
194
|
+
<script setup lang="ts">
|
|
195
|
+
import { computed, onBeforeUnmount, ref, toRef, watch } from "vue";
|
|
196
|
+
import RobotMapEditor from "./MapEditor.vue";
|
|
197
|
+
import RobotReconnecting from "./Reconnecting.vue";
|
|
198
|
+
import useRobotBuilding from "../../composables/useRobotBuilding";
|
|
199
|
+
import useRobotLive, { siteStatesFeed } from "../../composables/useRobotLive";
|
|
200
|
+
import {
|
|
201
|
+
brandName,
|
|
202
|
+
floorName,
|
|
203
|
+
mapFloors,
|
|
204
|
+
mapRobots,
|
|
205
|
+
pickFloor,
|
|
206
|
+
robotStatus,
|
|
207
|
+
routeMarks,
|
|
208
|
+
routePathD,
|
|
209
|
+
routeTags,
|
|
210
|
+
rowStatus,
|
|
211
|
+
unplacedRobots,
|
|
212
|
+
unplacedText,
|
|
213
|
+
type TMapRobot,
|
|
214
|
+
type TPatrolRouteView,
|
|
215
|
+
} from "../../utils/robot-display";
|
|
216
|
+
import {
|
|
217
|
+
buildingFloors,
|
|
218
|
+
cameraReadout,
|
|
219
|
+
defaultCamera,
|
|
220
|
+
dragCamera,
|
|
221
|
+
dragMode,
|
|
222
|
+
floorOpacity,
|
|
223
|
+
FLOOR_GAP_PX,
|
|
224
|
+
MAP_ANGLES,
|
|
225
|
+
planeLook,
|
|
226
|
+
presetCamera,
|
|
227
|
+
resetCamera,
|
|
228
|
+
shapeBox,
|
|
229
|
+
shapesFromMap,
|
|
230
|
+
stackMetrics,
|
|
231
|
+
startDrag,
|
|
232
|
+
toggleOrbit,
|
|
233
|
+
wheelZoom,
|
|
234
|
+
zoomIn,
|
|
235
|
+
zoomOut,
|
|
236
|
+
type TEditorShape,
|
|
237
|
+
type TMapCamera,
|
|
238
|
+
} from "../../utils/robot-building";
|
|
239
|
+
|
|
240
|
+
const props = withDefaults(
|
|
241
|
+
defineProps<{
|
|
242
|
+
organization: string;
|
|
243
|
+
site: string;
|
|
244
|
+
siteName?: string;
|
|
245
|
+
clientName?: string;
|
|
246
|
+
type?: "cleaning" | "security";
|
|
247
|
+
/** Edit map: set-up permitted AND allowed to change robots (the API saves on update-robot). */
|
|
248
|
+
canEditMap?: boolean;
|
|
249
|
+
backToNetwork?: boolean;
|
|
250
|
+
/** One telemetry tick; positions glide across it. */
|
|
251
|
+
tickMs?: number;
|
|
252
|
+
}>(),
|
|
253
|
+
{ siteName: "", clientName: "", type: "cleaning", canEditMap: false, backToNetwork: false, tickMs: 4000 },
|
|
254
|
+
);
|
|
255
|
+
const emit = defineEmits<{
|
|
256
|
+
open: [id: string];
|
|
257
|
+
network: [];
|
|
258
|
+
status: [status: { connected: boolean; faults: number; siteName: string; clientName: string }];
|
|
259
|
+
}>();
|
|
260
|
+
|
|
261
|
+
const { rows, map, names, loading, error, reload } = useRobotBuilding(
|
|
262
|
+
toRef(props, "organization"),
|
|
263
|
+
toRef(props, "site"),
|
|
264
|
+
toRef(props, "type"),
|
|
265
|
+
);
|
|
266
|
+
const siteLabel = computed(() => props.siteName || names.value.siteName || "This site");
|
|
267
|
+
|
|
268
|
+
/* ---- live states + patrol routes of the robots on screen ---- */
|
|
269
|
+
const ids = computed(() => rows.value.map((r) => String(r._id)));
|
|
270
|
+
const { states, connected } = useRobotLive(ids, siteStatesFeed());
|
|
271
|
+
const routes = ref<Record<string, TPatrolRouteView[]>>({});
|
|
272
|
+
const { getPatrolRoutes, getRobotBrands } = useRobots();
|
|
273
|
+
watch(ids, async (list) => {
|
|
274
|
+
if (props.type !== "security") return void (routes.value = {});
|
|
275
|
+
const next: Record<string, TPatrolRouteView[]> = {};
|
|
276
|
+
await Promise.allSettled(list.map(async (id) => {
|
|
277
|
+
const res = await getPatrolRoutes(id);
|
|
278
|
+
if (res?.supported) next[id] = res.routes ?? [];
|
|
279
|
+
}));
|
|
280
|
+
routes.value = next;
|
|
281
|
+
});
|
|
282
|
+
const brands = ref<Array<Record<string, any>>>([]);
|
|
283
|
+
getRobotBrands().then((res: any) => (brands.value = res?.items ?? []), () => undefined);
|
|
284
|
+
|
|
285
|
+
/* ---- floors, features, robots per floor ---- */
|
|
286
|
+
const shapes = computed<TEditorShape[]>(() => shapesFromMap(map.value));
|
|
287
|
+
const floors = computed(() => buildingFloors(mapFloors(ids.value, states.value), map.value));
|
|
288
|
+
const focus = ref<number | null>(null);
|
|
289
|
+
watch(floors, (f) => {
|
|
290
|
+
if (focus.value !== null && !f.includes(focus.value)) focus.value = null;
|
|
291
|
+
});
|
|
292
|
+
const floorRoutes = (floorNo: number) => {
|
|
293
|
+
const seen = new Map<string, TPatrolRouteView>();
|
|
294
|
+
for (const id of ids.value) {
|
|
295
|
+
const st = states.value[id];
|
|
296
|
+
for (const r of routes.value[id] ?? []) {
|
|
297
|
+
const f = r.floorNo ?? (st?.floorKnown ? st.floorNo : null);
|
|
298
|
+
if (f === floorNo && !seen.has(r.id)) seen.set(r.id, r);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return [...seen.values()];
|
|
302
|
+
};
|
|
303
|
+
const floors3d = computed(() =>
|
|
304
|
+
floors.value.map((floorNo) => ({
|
|
305
|
+
floorNo,
|
|
306
|
+
dim: floorOpacity(cam.value.tilt, focus.value, floorNo),
|
|
307
|
+
shapes: shapes.value.filter((s) => s.kind !== "lift" && s.floorNo === floorNo),
|
|
308
|
+
routes: props.type === "security" ? floorRoutes(floorNo) : [],
|
|
309
|
+
robots: mapRobots(rows.value, states.value, floorNo),
|
|
310
|
+
})),
|
|
311
|
+
);
|
|
312
|
+
const legend = computed(() => [...floors3d.value].reverse());
|
|
313
|
+
/** The editor opens on the busiest floor (the handoff's "best floor"). */
|
|
314
|
+
const startFloor = computed(() => pickFloor(floors.value, null, ids.value, states.value));
|
|
315
|
+
|
|
316
|
+
/** Each saved lift shaft: two red walls from its lowest served floor to its highest. */
|
|
317
|
+
const shafts = computed(() =>
|
|
318
|
+
shapes.value
|
|
319
|
+
.filter((s) => s.kind === "lift")
|
|
320
|
+
.map((s) => {
|
|
321
|
+
const served = (s.floors ?? []).map((f) => floors.value.indexOf(f)).filter((i) => i >= 0);
|
|
322
|
+
const lo = served.length ? Math.min(...served) : 0;
|
|
323
|
+
const hi = served.length ? Math.max(...served) : floors.value.length - 1;
|
|
324
|
+
const b = shapeBox(s);
|
|
325
|
+
return { id: s.id, x: b.x, y: b.y, z: lo * FLOOR_GAP_PX, w: Math.max(12, (b.w / 100) * 400), d: Math.max(12, (b.h / 100) * 260), h: (hi - lo) * FLOOR_GAP_PX + 8 };
|
|
326
|
+
}),
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
const unplaced = computed(() => unplacedRobots(rows.value, states.value));
|
|
330
|
+
const unplacedLine = computed(() => unplacedText(unplaced.value.map((r) => brandName(r.brand, brands.value))) ?? "");
|
|
331
|
+
|
|
332
|
+
const emptyNote = computed(() => {
|
|
333
|
+
if (!rows.value.length) return `No ${props.type === "security" ? "security" : "cleaning"} robots at this site yet - robots appear on their floor as soon as they report one.`;
|
|
334
|
+
if (!map.value) return props.canEditMap ? "No building map saved yet. Edit map to draw walls, zones, doors and lift shafts on each floor." : "No building map saved yet. A manager can draw one with Edit map.";
|
|
335
|
+
return "";
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
/* ---- tones ---- */
|
|
339
|
+
const tone = (r: TMapRobot) => robotStatus(r.mode, r.type).tone;
|
|
340
|
+
function unplacedTone(row: Record<string, any>) {
|
|
341
|
+
const st = rowStatus(row, states.value[String(row._id)] ?? null);
|
|
342
|
+
return st.kind === "live" ? robotStatus(st.mode, row.type).tone : "error";
|
|
343
|
+
}
|
|
344
|
+
const TONE: Record<string, string> = {
|
|
345
|
+
success: "rgb(var(--v-theme-success))",
|
|
346
|
+
warning: "rgb(var(--v-theme-warning))",
|
|
347
|
+
info: "rgb(var(--v-theme-info))",
|
|
348
|
+
error: "rgb(var(--v-theme-error))",
|
|
349
|
+
accent: "var(--hero-accent)",
|
|
350
|
+
ink: "var(--hero-text)",
|
|
351
|
+
};
|
|
352
|
+
const toneColor = (r: TMapRobot) => TONE[tone(r)] ?? TONE.ink;
|
|
353
|
+
|
|
354
|
+
/* ---- camera ---- */
|
|
355
|
+
const cam = ref<TMapCamera>(defaultCamera());
|
|
356
|
+
const drag = ref<{ mode: "pan" | "rotate"; x: number; y: number; start: TMapCamera } | null>(null);
|
|
357
|
+
const look = computed(() => planeLook(cam.value.tilt));
|
|
358
|
+
const stack = computed(() => stackMetrics(floors.value.length));
|
|
359
|
+
const orbiting = computed(() => cam.value.orbit && cam.value.angle === "iso" && !drag.value);
|
|
360
|
+
/** Keeps tags and labels upright whatever the view angle. */
|
|
361
|
+
const unskew = computed(() => `rotateZ(${-cam.value.turn}deg) rotateX(${-cam.value.tilt}deg)`);
|
|
362
|
+
|
|
363
|
+
function onDown(e: MouseEvent) {
|
|
364
|
+
if ((e.target as HTMLElement).closest("button")) return;
|
|
365
|
+
const mode = dragMode(e);
|
|
366
|
+
cam.value = startDrag(cam.value, mode);
|
|
367
|
+
drag.value = { mode, x: e.clientX, y: e.clientY, start: cam.value };
|
|
368
|
+
}
|
|
369
|
+
function onMove(e: MouseEvent) {
|
|
370
|
+
const d = drag.value;
|
|
371
|
+
if (d) cam.value = dragCamera(d.start, d.mode, e.clientX - d.x, e.clientY - d.y);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const svgPoints = (s: TEditorShape) => s.points.map((p) => `${p.x},${p.y}`).join(" ");
|
|
375
|
+
|
|
376
|
+
/* ---- full screen + edit ---- */
|
|
377
|
+
const viewer = ref<HTMLElement | null>(null);
|
|
378
|
+
const editor = ref<InstanceType<typeof RobotMapEditor> | null>(null);
|
|
379
|
+
function fullscreen(el?: HTMLElement | null) {
|
|
380
|
+
if (document.fullscreenElement) document.exitFullscreen?.();
|
|
381
|
+
else el?.requestFullscreen?.();
|
|
382
|
+
}
|
|
383
|
+
const editing = ref(false);
|
|
384
|
+
watch(() => props.canEditMap, (can) => {
|
|
385
|
+
if (!can) editing.value = false;
|
|
386
|
+
});
|
|
387
|
+
/** The robot a first save is attached to (maps are stored per robot): one of this site's. */
|
|
388
|
+
const ownerRobotId = computed(() => String(map.value?.robotId ?? rows.value[0]?._id ?? ""));
|
|
389
|
+
function onSaved() {
|
|
390
|
+
reload();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/* ---- header status (live + faults) ---- */
|
|
394
|
+
watch(
|
|
395
|
+
[connected, () => rows.value.filter((r) => r.fault).length, () => names.value.siteName, () => names.value.clientName],
|
|
396
|
+
([up, faults, siteName, clientName]) => emit("status", { connected: up, faults, siteName, clientName }),
|
|
397
|
+
{ immediate: true },
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
onBeforeUnmount(() => {
|
|
401
|
+
if (document.fullscreenElement) document.exitFullscreen?.();
|
|
402
|
+
});
|
|
403
|
+
</script>
|