66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
import * as zrUtil from 'zrender/src/core/util';
|
|
import systemGraphType from '../constant/systemGraphType';
|
|
import systemGraphRender from '../constant/systemGraphRender';
|
|
import Vue from 'vue';
|
|
import { deepClone } from '@/utils/index';
|
|
|
|
export function deviceFactory(type, elem, showConfig) {
|
|
return {...systemGraphRender[type], ...elem, ...showConfig};
|
|
}
|
|
|
|
export function createDevice(type, elem, propConvert, showConfig) {
|
|
const device = deviceFactory(type, Object.assign(elem, { _type: type } ), showConfig);
|
|
return propConvert ? propConvert.initPrivateProps(device) : device;
|
|
}
|
|
|
|
export function parser(data, skinCode, showConfig) {
|
|
var mapDevice = {};
|
|
var propConvert = skinCode ? Vue.prototype.$theme.loadPropConvert(skinCode) : null;
|
|
if (data) {
|
|
zrUtil.each(data.lineList || [], elem => {
|
|
mapDevice[elem.code] = createDevice(systemGraphType.Line, elem, propConvert, showConfig);
|
|
}, this);
|
|
|
|
zrUtil.each(data.textList || [], elem => {
|
|
mapDevice[elem.code] = createDevice(systemGraphType.Text, elem, propConvert, showConfig);
|
|
}, this);
|
|
|
|
zrUtil.each(data.rectList || [], elem => {
|
|
mapDevice[elem.code] = createDevice(systemGraphType.Rect, elem, propConvert, showConfig);
|
|
}, this);
|
|
|
|
}
|
|
|
|
return mapDevice;
|
|
}
|
|
|
|
// 同步绘制数据到原始数据
|
|
export function updateForList(model, state, lstName) {
|
|
const list = state.map[lstName];
|
|
if (list && list instanceof Array) {
|
|
const i = list.findIndex(elem => elem.code == model.code );
|
|
if (i < 0) {
|
|
list.push(deepClone(model)); // 新增
|
|
} else {
|
|
if (model._dispose) {
|
|
list.splice(i, 1);
|
|
} else {
|
|
list.splice(i, 1, deepClone(model));
|
|
}
|
|
}
|
|
state.map[lstName] = [...list];
|
|
} else {
|
|
state.map[lstName] = [model];
|
|
}
|
|
}
|
|
|
|
export function updateMapData(state, model) {
|
|
if (state.map && model) {
|
|
switch (model._type) {
|
|
case systemGraphType.Line: updateForList(model, state, 'lineList'); break;
|
|
case systemGraphType.Text: updateForList(model, state, 'textList'); break;
|
|
case systemGraphType.Rect: updateForList(model, state, 'rectList'); break;
|
|
}
|
|
}
|
|
}
|