feat: Enhance equipment components with pin functionality and constraint management
- Added pin support to MechanicalButton, enabling pin-click events and componentId handling. - Updated Pin component to manage constraint states and colors dynamically. - Integrated SMT_LED with pin functionality, allowing LED state to respond to constraints. - Enhanced Wire component to reflect constraint colors and manage wire states based on pin connections. - Introduced wireManager for managing wire states and constraints. - Implemented a constraints store for managing and notifying constraint state changes across components. - Updated component configuration to remove appearance options and clarify constraint descriptions. - Improved ProjectView to handle optional chaining for props and ensure robust data handling. - Initialized constraint communication in main application entry point.
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
/* eslint-disable */
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
import { batchSetConstraintStates, notifyConstraintChange } from './stores/constraints';
|
||||
import type { ConstraintLevel } from './stores/constraints';
|
||||
|
||||
export class Client {
|
||||
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
|
||||
private baseUrl: string;
|
||||
@@ -866,4 +869,57 @@ function throwException(message: string, status: number, response: string, heade
|
||||
throw result;
|
||||
else
|
||||
throw new ApiException(message, status, response, headers, null);
|
||||
}
|
||||
}
|
||||
|
||||
// 约束通信相关方法
|
||||
export function receiveConstraintUpdates(constraints: Record<string, ConstraintLevel>) {
|
||||
// 批量更新约束状态
|
||||
batchSetConstraintStates(constraints);
|
||||
}
|
||||
|
||||
export function sendConstraintUpdate(constraint: string, level: ConstraintLevel) {
|
||||
// 向后端发送约束状态变化
|
||||
console.log(`发送约束 ${constraint} 状态变化为 ${level}`);
|
||||
|
||||
// TODO: 实际的WebSocket或HTTP请求发送约束变化
|
||||
// 例如:
|
||||
// socket.emit('constraintUpdate', { constraint, level });
|
||||
// 或
|
||||
// fetch('/api/constraints', {
|
||||
// method: 'POST',
|
||||
// body: JSON.stringify({ constraint, level }),
|
||||
// headers: { 'Content-Type': 'application/json' }
|
||||
// });
|
||||
}
|
||||
|
||||
// 初始化约束通信
|
||||
export function initConstraintCommunication() {
|
||||
// 监听服务器发来的约束状态变化
|
||||
// 示例:
|
||||
// socket.on('constraintUpdates', (data) => {
|
||||
// receiveConstraintUpdates(data);
|
||||
// });
|
||||
|
||||
// 模拟接收一些初始约束状态
|
||||
setTimeout(() => {
|
||||
receiveConstraintUpdates({
|
||||
'A1': 'high',
|
||||
'A2': 'low',
|
||||
'A3': 'undefined'
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// 覆盖全局notifyConstraintChange,加入发送逻辑
|
||||
const originalNotifyConstraintChange = notifyConstraintChange;
|
||||
const wrappedNotifyConstraintChange = (constraint: string, level: ConstraintLevel) => {
|
||||
// 调用原始方法更新本地状态
|
||||
originalNotifyConstraintChange(constraint, level);
|
||||
|
||||
// 向后端发送更新
|
||||
sendConstraintUpdate(constraint, level);
|
||||
};
|
||||
|
||||
// 替换全局方法
|
||||
(window as any).__notifyConstraintChange = notifyConstraintChange;
|
||||
(window as any).notifyConstraintChange = wrappedNotifyConstraintChange;
|
||||
Reference in New Issue
Block a user