461d64afe1
问题: 1.绘制哈尔滨传输信号机 2.处理传输信号机的逻辑处理问题
42 lines
1015 B
JavaScript
42 lines
1015 B
JavaScript
import deviceType from '../constant/deviceType';
|
|
|
|
// 默认策略
|
|
function executeStrategy(strategy, value) { return strategy? strategy(): value };
|
|
|
|
// 适配转换虚拟设备为正式设备
|
|
export function adapterAsDevice(device, mapDevice) {
|
|
if (!device) return device;
|
|
const strategyMap = {
|
|
[deviceType.Signal]: _ => {
|
|
return device.type == 'TRANSMISSION'? mapDevice[device.linkSignalCode]: device;
|
|
}
|
|
}
|
|
|
|
return executeStrategy(strategyMap[device._type], device);
|
|
}
|
|
|
|
// 获取当前可显示适配设备
|
|
export function adapterByDevice(device, mapDevice) {
|
|
if (!device) return device;
|
|
|
|
const strategyMap = {
|
|
[deviceType.Signal]: _ => {
|
|
if (device.aliasCodes) {
|
|
for(var code of device.aliasCodes) {
|
|
let it = mapDevice[code];
|
|
if (it &&
|
|
it.type == 'TRANSMISSION' &&
|
|
it.instance &&
|
|
it.instance.isShowShape) {
|
|
console.log(it.instance);
|
|
return it;
|
|
}
|
|
}
|
|
}
|
|
return device;
|
|
}
|
|
}
|
|
|
|
return executeStrategy(strategyMap[device._type], device);
|
|
}
|