refactor(types): 将自动门相关状态字段从deviceStatus统一重命名为doorStatus以提升语义清晰度

This commit is contained in:
xudan 2025-12-04 17:50:09 +08:00
parent 3794e6477b
commit cb3f82b711
6 changed files with 34 additions and 34 deletions

View File

@ -32,7 +32,7 @@ export interface MapPointInfo {
associatedStorageLocations?: string[]; // 库位名称 associatedStorageLocations?: string[]; // 库位名称
deviceId?: string; // 设备ID deviceId?: string; // 设备ID
enabled?: 0 | 1; // 是否启用(充电点/停靠点使用0=禁用1=启用) enabled?: 0 | 1; // 是否启用(充电点/停靠点使用0=禁用1=启用)
deviceStatus?: number; // 设备状态仅自动门点使用0=关门1=开门) doorStatus?: number; // 设备状态仅自动门点使用0=关门1=开门)
isConnected?: boolean; // 连接状态仅自动门点使用true=已连接false=未连接) isConnected?: boolean; // 连接状态仅自动门点使用true=已连接false=未连接)
active?: boolean; // 是否激活状态,用于控制光圈显示 active?: boolean; // 是否激活状态,用于控制光圈显示
} }
@ -48,7 +48,7 @@ export interface MapRouteInfo {
c2?: Point; // 控制点2 c2?: Point; // 控制点2
// 门区域:绑定设备与状态(可选) // 门区域:绑定设备与状态(可选)
deviceId?: string; deviceId?: string;
deviceStatus?: number; // 0=关门1=开门 doorStatus?: number; // 0=关门1=开门
isConnected?: boolean; // true=已连接false=未连接 isConnected?: boolean; // true=已连接false=未连接
} }
//#endregion //#endregion
@ -62,7 +62,7 @@ export interface MapAreaInfo {
inoutflag?: 1 | 2; // 进出限制 inoutflag?: 1 | 2; // 进出限制
// 门区域:绑定设备与状态(可选) // 门区域:绑定设备与状态(可选)
doorDeviceId?: string; doorDeviceId?: string;
deviceStatus?: number; // 0=关门1=开门 doorStatus?: number; // 0=关门1=开门
isConnected?: boolean; // true=已连接false=未连接 isConnected?: boolean; // true=已连接false=未连接
} }
//#endregion //#endregion

View File

@ -16,7 +16,7 @@ const editor = inject(props.token)!;
// / // /
const areasTick = computed<string>(() => const areasTick = computed<string>(() =>
editor.value.areas.value editor.value.areas.value
.map((v: any) => `${v.id}:${v?.area?.deviceStatus ?? ''}:${v?.area?.isConnected ?? ''}`) .map((v: any) => `${v.id}:${v?.area?.doorStatus ?? ''}:${v?.area?.isConnected ?? ''}`)
.join('|'), .join('|'),
); );
@ -170,7 +170,7 @@ watch(area, (newArea) => {
<a-flex :gap="8" vertical> <a-flex :gap="8" vertical>
<a-typography-text type="secondary">{{ $t('门状态') }}</a-typography-text> <a-typography-text type="secondary">{{ $t('门状态') }}</a-typography-text>
<a-typography-text> <a-typography-text>
{{ area.deviceStatus === 1 ? $t('开门') : area.deviceStatus === 0 ? $t('关门') : $t('无') }} {{ area.doorStatus === 1 ? $t('开门') : area.doorStatus === 0 ? $t('关门') : $t('无') }}
</a-typography-text> </a-typography-text>
</a-flex> </a-flex>
</a-list-item> </a-list-item>

View File

@ -405,7 +405,7 @@ const monitorScene = async () => {
canStop: null, canStop: null,
canControl: true, canControl: true,
targetPoint: null, targetPoint: null,
deviceStatus: doorMockStatus, doorStatus: doorMockStatus,
x: 0, x: 0,
y: 0, y: 0,
active: true, active: true,

View File

@ -73,7 +73,7 @@ interface AutoDoorStatusData {
targetPoint: null; targetPoint: null;
deviceStatus: 0 | 1; // 设备状态0=关门1=开门 doorStatus: 0 | 1; // 设备状态0=关门1=开门
x: number; x: number;
@ -125,7 +125,7 @@ export interface AutoDoorWebSocketData {
targetPoint: null; targetPoint: null;
deviceStatus: 0 | 1; // 设备状态0=关门1=开门 doorStatus: 0 | 1; // 设备状态0=关门1=开门
x: number; x: number;
@ -174,7 +174,7 @@ export class AutoDoorService {
private latestAutoDoorData = new Map< private latestAutoDoorData = new Map<
string, string,
{ deviceId: string; deviceStatus: number; active: boolean; isConnected: boolean } { deviceId: string; doorStatus: number; active: boolean; isConnected: boolean }
>(); >();
// 设备ID到自动门点ID列表的映射缓存支持同一设备绑定多个点位 // 设备ID到自动门点ID列表的映射缓存支持同一设备绑定多个点位
@ -413,11 +413,11 @@ export class AutoDoorService {
handleWebSocketData(data: AutoDoorWebSocketData): void { handleWebSocketData(data: AutoDoorWebSocketData): void {
// 兼容不同字段:优先使用 id 作为设备ID退回 label // 兼容不同字段:优先使用 id 作为设备ID退回 label
const deviceId = (data as any)?.id || (data as any)?.label; const deviceId = (data as any)?.id || (data as any)?.label;
const deviceStatus = (data as any)?.deviceStatus; const doorStatus = (data as any)?.doorStatus;
const active = (data as any)?.active ?? true; const active = (data as any)?.active ?? true;
const isConnected = (data as any)?.isConnected ?? true; const isConnected = (data as any)?.isConnected ?? true;
if (!deviceId || deviceStatus === undefined) { if (!deviceId || doorStatus === undefined) {
console.warn('⚠️ 自动门点数据格式不正确', data); console.warn('⚠️ 自动门点数据格式不正确', data);
return; return;
@ -425,10 +425,10 @@ export class AutoDoorService {
// 缓存最新数据 // 缓存最新数据
this.latestAutoDoorData.set(deviceId, { deviceId, deviceStatus, active, isConnected }); this.latestAutoDoorData.set(deviceId, { deviceId, doorStatus, active, isConnected });
this.debugLog('handleWebSocketData -> buffered', { this.debugLog('handleWebSocketData -> buffered', {
deviceId, deviceId,
deviceStatus, doorStatus,
active, active,
isConnected, isConnected,
bufferSize: this.latestAutoDoorData.size, bufferSize: this.latestAutoDoorData.size,
@ -436,7 +436,7 @@ export class AutoDoorService {
// console.log( // console.log(
// `🚪 收到自动门点WebSocket数据: ${deviceStatus === 0 ? '关门(红色)' : '开门(蓝色)'} (deviceId: ${deviceId})`, // `🚪 收到自动门点WebSocket数据: ${doorStatus === 0 ? '关门(红色)' : '开门(蓝色)'} (deviceId: ${deviceId})`,
// ); // );
} }
@ -492,7 +492,7 @@ export class AutoDoorService {
const updates = pointIds.map((pid) => ({ const updates = pointIds.map((pid) => ({
id: pid, id: pid,
deviceId: data.deviceId, deviceId: data.deviceId,
deviceStatus: data.deviceStatus, doorStatus: data.doorStatus,
isConnected: data.isConnected, isConnected: data.isConnected,
active: data.active, active: data.active,
})); }));
@ -500,7 +500,7 @@ export class AutoDoorService {
updates.forEach((update) => { updates.forEach((update) => {
this.editorService!.updateAutoDoorByDeviceId( this.editorService!.updateAutoDoorByDeviceId(
update.deviceId, update.deviceId,
update.deviceStatus, update.doorStatus,
update.isConnected, update.isConnected,
update.active, update.active,
update.id, update.id,
@ -516,7 +516,7 @@ export class AutoDoorService {
this.debugLog('sync to routes -> count:', routes.length); this.debugLog('sync to routes -> count:', routes.length);
routes.forEach((r: any) => { routes.forEach((r: any) => {
const patch = { deviceStatus: data.deviceStatus, isConnected: data.isConnected } as any; const patch = { doorStatus: data.doorStatus, isConnected: data.isConnected } as any;
this.editorService!.updateRoute(r.id, patch); this.editorService!.updateRoute(r.id, patch);
this.debugLog('route updated ->', r.id, patch); this.debugLog('route updated ->', r.id, patch);
}); });
@ -540,7 +540,7 @@ export class AutoDoorService {
this.debugLog('sync to door areas -> count:', areas.length, 'deviceId:', data.deviceId); this.debugLog('sync to door areas -> count:', areas.length, 'deviceId:', data.deviceId);
areas.forEach((a: any) => { areas.forEach((a: any) => {
const patch = { deviceStatus: data.deviceStatus, isConnected: data.isConnected } as any; const patch = { doorStatus: data.doorStatus, isConnected: data.isConnected } as any;
this.editorService!.updateArea(a.id, patch); this.editorService!.updateArea(a.id, patch);
this.debugLog('door area updated ->', a.id, patch); this.debugLog('door area updated ->', a.id, patch);
}); });
@ -615,11 +615,11 @@ export class AutoDoorService {
* @param label * @param label
* @param deviceStatus * @param doorStatus
*/ */
private createMockData(deviceId: string, label: string, deviceStatus: 0 | 1): AutoDoorStatusData { private createMockData(deviceId: string, label: string, doorStatus: 0 | 1): AutoDoorStatusData {
return { return {
gid: '', gid: '',
@ -647,7 +647,7 @@ export class AutoDoorService {
targetPoint: null, targetPoint: null,
deviceStatus, doorStatus,
x: 0, x: 0,

View File

@ -312,7 +312,7 @@ export class EditorService extends Meta2d {
maxSpeed, maxSpeed,
// 门区域扩展字段 // 门区域扩展字段
deviceId: (v as any).deviceId, deviceId: (v as any).deviceId,
deviceStatus: (v as any).deviceStatus, doorStatus: (v as any).doorStatus,
isConnected: (v as any).isConnected, isConnected: (v as any).isConnected,
}, },
}, },
@ -393,7 +393,7 @@ export class EditorService extends Meta2d {
inoutflag, inoutflag,
// 门区域扩展字段 // 门区域扩展字段
doorDeviceId: (v as any).doorDeviceId, doorDeviceId: (v as any).doorDeviceId,
deviceStatus: (v as any).deviceStatus, doorStatus: (v as any).doorStatus,
isConnected: (v as any).isConnected, isConnected: (v as any).isConnected,
}, },
}, },
@ -448,7 +448,7 @@ export class EditorService extends Meta2d {
#mapSceneRoute(pen?: MapPen): StandardSceneRoute | null { #mapSceneRoute(pen?: MapPen): StandardSceneRoute | null {
if (!pen?.id || pen.anchors?.length !== 2 || isEmpty(pen?.route)) return null; if (!pen?.id || pen.anchors?.length !== 2 || isEmpty(pen?.route)) return null;
const { id, anchors, desc, properties } = pen; const { id, anchors, desc, properties } = pen;
const { type, direction = 1, pass, c1, c2, maxSpeed, deviceId, deviceStatus, isConnected } = pen.route as any; const { type, direction = 1, pass, c1, c2, maxSpeed, deviceId, doorStatus, isConnected } = pen.route as any;
const [p1, p2] = anchors.map((v) => this.getPenById(v.connectTo!)); const [p1, p2] = anchors.map((v) => this.getPenById(v.connectTo!));
if (isNil(p1) || isNil(p2)) return null; if (isNil(p1) || isNil(p2)) return null;
const route: StandardSceneRoute = { const route: StandardSceneRoute = {
@ -464,7 +464,7 @@ export class EditorService extends Meta2d {
}; };
// 门区域扩展字段:保持到顶层,便于后端识别 // 门区域扩展字段:保持到顶层,便于后端识别
(route as any).deviceId = deviceId; (route as any).deviceId = deviceId;
(route as any).deviceStatus = deviceStatus; (route as any).doorStatus = doorStatus;
(route as any).isConnected = isConnected; (route as any).isConnected = isConnected;
const { x: x1, y: y1 } = this.getPointRect(p1)!; const { x: x1, y: y1 } = this.getPointRect(p1)!;
const { x: x2, y: y2 } = this.getPointRect(p2)!; const { x: x2, y: y2 } = this.getPointRect(p2)!;
@ -492,7 +492,7 @@ export class EditorService extends Meta2d {
#mapSceneArea(pen: MapPen): StandardSceneArea | null { #mapSceneArea(pen: MapPen): StandardSceneArea | null {
if (!pen.id || isEmpty(pen.area)) return null; if (!pen.id || isEmpty(pen.area)) return null;
const { id, label, desc, properties } = pen; const { id, label, desc, properties } = pen;
const { type, points, routes, maxAmr, inoutflag, doorDeviceId, deviceStatus, isConnected } = pen.area as any; const { type, points, routes, maxAmr, inoutflag, doorDeviceId, doorStatus, isConnected } = pen.area as any;
const { x, y, width, height } = this.getPenRect(pen); const { x, y, width, height } = this.getPenRect(pen);
// 进行坐标转换:左上角原点 -> 中心点原点同时应用ratio缩放 // 进行坐标转换:左上角原点 -> 中心点原点同时应用ratio缩放
const transformedCoords = this.#transformCoordinate(x, y); const transformedCoords = this.#transformCoordinate(x, y);
@ -511,7 +511,7 @@ export class EditorService extends Meta2d {
// 门区域扩展字段 // 门区域扩展字段
(area as any).routes = routes; (area as any).routes = routes;
(area as any).doorDeviceId = doorDeviceId; (area as any).doorDeviceId = doorDeviceId;
(area as any).deviceStatus = deviceStatus; (area as any).doorStatus = doorStatus;
(area as any).isConnected = isConnected; (area as any).isConnected = isConnected;
if (type === MapAreaType.) { if (type === MapAreaType.) {
area.maxAmr = maxAmr; area.maxAmr = maxAmr;
@ -989,14 +989,14 @@ export class EditorService extends Meta2d {
/** /**
* ID更新自动门点状态 * ID更新自动门点状态
* @param deviceId ID * @param deviceId ID
* @param deviceStatus 0=1= * @param doorStatus 0=1=
* @param isConnected true=false= * @param isConnected true=false=
* @param active * @param active
* @param pointId ID使 * @param pointId ID使
*/ */
public updateAutoDoorByDeviceId( public updateAutoDoorByDeviceId(
deviceId: string, deviceId: string,
deviceStatus: number, doorStatus: number,
isConnected: boolean, isConnected: boolean,
active = true, active = true,
pointId?: string, pointId?: string,
@ -1034,7 +1034,7 @@ export class EditorService extends Meta2d {
{ {
point: { point: {
...autoDoorPoint.point, ...autoDoorPoint.point,
deviceStatus, doorStatus,
isConnected, isConnected,
active, active,
}, },

View File

@ -16,7 +16,7 @@ export function drawPoint(ctx: CanvasRenderingContext2D, pen: MapPen): void {
const theme = sTheme.editor; const theme = sTheme.editor;
const { active, iconSize: r = 0, fontSize = 14, lineHeight = 1.5, fontFamily } = pen.calculative ?? {}; const { active, iconSize: r = 0, fontSize = 14, lineHeight = 1.5, fontFamily } = pen.calculative ?? {};
const { x = 0, y = 0, width: w = 0, height: h = 0 } = pen.calculative?.worldRect ?? {}; const { x = 0, y = 0, width: w = 0, height: h = 0 } = pen.calculative?.worldRect ?? {};
const { type, isConnected, deviceStatus, active: pointActive } = pen.point ?? {}; const { type, isConnected, doorStatus, active: pointActive } = pen.point ?? {};
const { label = '', statusStyle } = pen ?? {}; const { label = '', statusStyle } = pen ?? {};
ctx.save(); ctx.save();
@ -40,7 +40,7 @@ export function drawPoint(ctx: CanvasRenderingContext2D, pen: MapPen): void {
ctx.fillStyle = colorConfig.getColor('autoDoor.strokeClosed') || '#fe5a5ae0'; ctx.fillStyle = colorConfig.getColor('autoDoor.strokeClosed') || '#fe5a5ae0';
} else { } else {
// 已连接根据门状态显示颜色0=关门-浅红1=开门-蓝色) // 已连接根据门状态显示颜色0=关门-浅红1=开门-蓝色)
if (deviceStatus === 0) { if (doorStatus === 0) {
ctx.fillStyle = colorConfig.getColor('autoDoor.fillClosed') || '#cddc39'; ctx.fillStyle = colorConfig.getColor('autoDoor.fillClosed') || '#cddc39';
} else { } else {
ctx.fillStyle = colorConfig.getColor('autoDoor.fillOpen') || '#1890FF'; ctx.fillStyle = colorConfig.getColor('autoDoor.fillOpen') || '#1890FF';
@ -312,8 +312,8 @@ export function drawArea(ctx: CanvasRenderingContext2D, pen: MapPen): void {
// 门区域图标背景:根据设备连接与开关状态绘制淡化图标 // 门区域图标背景:根据设备连接与开关状态绘制淡化图标
if ((type as any) === DOOR_AREA_TYPE) { if ((type as any) === DOOR_AREA_TYPE) {
const isConnected = (pen.area as any)?.isConnected; const isConnected = (pen.area as any)?.isConnected;
const deviceStatus = (pen.area as any)?.deviceStatus; const doorStatus = (pen.area as any)?.doorStatus;
const img = isConnected === false ? __doorImgClosed : deviceStatus === 1 ? __doorImgOpen : __doorImgClosed; const img = isConnected === false ? __doorImgClosed : doorStatus === 1 ? __doorImgOpen : __doorImgClosed;
if (img && img.complete) { if (img && img.complete) {
const padding = Math.max(2, Math.min(10, Math.min(w, h) * 0.02)); const padding = Math.max(2, Math.min(10, Math.min(w, h) * 0.02));
const availW = Math.max(0, w - padding * 2); const availW = Math.max(0, w - padding * 2);