代码调整
This commit is contained in:
parent
d8af8fb70a
commit
34a20d3475
@ -7,13 +7,13 @@ function traverse(group, map) {
|
||||
} else {
|
||||
map[el.name] = el;
|
||||
}
|
||||
})
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
class Animate {
|
||||
constructor(state) {
|
||||
this._state = {...state}
|
||||
this._state = {...state};
|
||||
this._sum = 0;
|
||||
this._count = 0;
|
||||
this._first = true;
|
||||
@ -22,9 +22,9 @@ class Animate {
|
||||
|
||||
run(interval) {
|
||||
this._sum = this._sum + interval;
|
||||
const total = this._state.time + (this._first? this._state.delay: 0)
|
||||
const total = this._state.time + (this._first ? this._state.delay : 0);
|
||||
if (this._sum > total) {
|
||||
this.animate(this)
|
||||
this.animate(this);
|
||||
this._count = this._count + 1;
|
||||
this._sum = 0;
|
||||
this._first = false;
|
||||
@ -48,7 +48,7 @@ class Animate {
|
||||
}
|
||||
|
||||
getIndex(index = 0) {
|
||||
return index? index: this._count%this._state.frameList.length;
|
||||
return index || this._count % this._state.frameList.length;
|
||||
}
|
||||
|
||||
getFrame(index = 0) {
|
||||
@ -64,14 +64,14 @@ class Animate {
|
||||
const mapView = traverse(shape, {});
|
||||
if (this.isNeedDefault()) {
|
||||
Object.keys(mapShape).forEach(name => {
|
||||
const state = mapShape[name]
|
||||
const state = mapShape[name];
|
||||
const view = mapView[name];
|
||||
if (view) {
|
||||
shape.setInvisible(shape.model.base.hide);
|
||||
view.attr({shape: state.default.shape, style: state.default.style});
|
||||
view.dirty();
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
Object.keys(frame).forEach(name => {
|
||||
@ -82,7 +82,7 @@ class Animate {
|
||||
view.attr({shape: model.shape, style: model.style});
|
||||
view.dirty();
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,4 +115,4 @@ class AnimateHandle {
|
||||
}
|
||||
}
|
||||
|
||||
export default AnimateHandle
|
||||
export default AnimateHandle;
|
||||
|
@ -197,14 +197,14 @@ class JMap {
|
||||
this.$shapeFactory.addShape(oldShape);
|
||||
this.$painter.add(oldShape);
|
||||
break;
|
||||
case orders.changeStatus:
|
||||
// model
|
||||
this.$painter.update(this.$stateHandle.update(this.$shapeFactory, []));
|
||||
debugger;
|
||||
break;
|
||||
case orders.ResetStatus:
|
||||
debugger;
|
||||
break;
|
||||
// case orders.changeStatus:
|
||||
// // model
|
||||
// this.$painter.update(this.$stateHandle.update(this.$shapeFactory, []));
|
||||
// debugger;
|
||||
// break;
|
||||
// case orders.ResetStatus:
|
||||
// debugger;
|
||||
// break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -9,7 +9,8 @@ export default class StateHandle {
|
||||
const mapTemplate = shapeFactory.getMapTemplate();
|
||||
const template = mapTemplate[state.type];
|
||||
const templateState = template.mapState[state.status] || {};
|
||||
const frameList = templateState.frameList||[];
|
||||
// const frameList = templateState.frameList||[];
|
||||
const frameList = Object.values(templateState.covertStatusList) || [];
|
||||
|
||||
// 增加第一帧初始数据
|
||||
// if (templateState &&
|
||||
@ -27,23 +28,25 @@ export default class StateHandle {
|
||||
mapShape: template.mapShape,
|
||||
shape: shapeFactory.getShapeByCode(state.code),
|
||||
frameList: frameList.map(frame => {
|
||||
return Object.fromEntries(frame.map(el => {
|
||||
// return Object.fromEntries(frame.map(el => {
|
||||
return Object.fromEntries(frame.frameList.map((el, index) => {
|
||||
const mapState = template.mapShape[el.name] || {};
|
||||
const state = mapState[el.status] || {};
|
||||
return [el.name, {
|
||||
return [el.name || index, {
|
||||
loop:frame.loop,
|
||||
...el,
|
||||
...state
|
||||
}]
|
||||
}];
|
||||
}));
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
update(shapeFactory, states = []) {
|
||||
return states.reduce((list, state) => {
|
||||
return [
|
||||
...list,
|
||||
this.parse(shapeFactory, state), // 测试只有自身
|
||||
this.parse(shapeFactory, state) // 测试只有自身
|
||||
// this.updateState(this.parse(shapeFactory, state)), // 处理自身
|
||||
// this.updateState(this.parse(shapeFactory, state)) // 处理依赖
|
||||
];
|
||||
@ -51,10 +54,10 @@ export default class StateHandle {
|
||||
}
|
||||
|
||||
updateState(state = {}) {
|
||||
return {}
|
||||
return {};
|
||||
}
|
||||
|
||||
updateDepState(state = {}) {
|
||||
return {}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ export default class TransformHandle {
|
||||
|
||||
// 遍历view执行回调
|
||||
traverse(cb, context) {
|
||||
debugger
|
||||
this.traverseLayer(layer => {
|
||||
layer.eachChild(shape => {
|
||||
cb.call(context, shape);
|
||||
|
@ -55,7 +55,8 @@ export default {
|
||||
selected: null,
|
||||
statusTab:'',
|
||||
stateList:[],
|
||||
elementList:[]
|
||||
elementList:[],
|
||||
type:''
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
@ -67,49 +68,68 @@ export default {
|
||||
setData(data) {
|
||||
this.stateList = data.stateList;
|
||||
this.elementList = utils.deepClone(data.shapeList);
|
||||
this.type = data.type;
|
||||
},
|
||||
previewStatus(data) {
|
||||
// this.resetDefaultStatus();
|
||||
const that = this;
|
||||
const list = Object.values(data.covertStatusList);
|
||||
list.forEach(each=>{
|
||||
if (each.loop) {
|
||||
// ChangeStatus
|
||||
} else {
|
||||
const frameList = each.frameList;
|
||||
// this.$iscs.update([
|
||||
// { status: 's1', code: '100', type: 'Device' },
|
||||
// { status: 's2', code: '101', type: 'Device' }
|
||||
// ]);
|
||||
frameList.forEach(frame=>{
|
||||
const element = that.elementList.find(ele=>{ return ele.name == frame.name; });
|
||||
if (element) {
|
||||
const elementStyle = element.stateList.find(state=>{ return state.status == frame.status; });
|
||||
if (elementStyle) {
|
||||
const model = utils.deepClone(element);
|
||||
const style = elementStyle.style || {};
|
||||
// model.changeStyle =
|
||||
if (style && JSON.stringify(style) != '{}') {
|
||||
const keys = Object.keys(style);
|
||||
keys.forEach(eachKey=>{
|
||||
model.style[eachKey] = style[eachKey];
|
||||
});
|
||||
}
|
||||
const shape = elementStyle.shape || {};
|
||||
if (shape && JSON.stringify(shape) != '{}') {
|
||||
const keys = Object.keys(shape);
|
||||
keys.forEach(eachShape=>{
|
||||
model.shape[eachShape] = style[eachShape];
|
||||
});
|
||||
}
|
||||
// { status: 's1', code: '100', type: 'Device' },
|
||||
this.$refs.iscsCanvas.doAction([{model, action: {shapeType: shapeType.Element, order: orders.Update}}]);
|
||||
// covertStatusList: Object
|
||||
// description: "关闭"
|
||||
// id: 1
|
||||
// needDefault: true
|
||||
// status: "close"
|
||||
// weight: 1
|
||||
this.$iscs.update([
|
||||
{ status: data.status, code: '100', type: this.type }
|
||||
]);
|
||||
// const that = this;
|
||||
// const list = Object.values(data.covertStatusList);
|
||||
// list.forEach(each=>{
|
||||
// debugger;
|
||||
// if (each.loop) {
|
||||
// // ChangeStatus
|
||||
// } else {
|
||||
// const frameList = each.frameList;
|
||||
// // <模型类型>
|
||||
// // this.$iscs.update([
|
||||
// // { status: 's1', code: '100', type: 'Device' },
|
||||
// // { status: 's2', code: '101', type: 'Device' }
|
||||
// // ]);
|
||||
// frameList.forEach(frame=>{
|
||||
// const element = that.elementList.find(ele=>{ return ele.name == frame.name; });
|
||||
// if (element) {
|
||||
// const elementStyle = element.stateList.find(state=>{ return state.status == frame.status; });
|
||||
// if (elementStyle) {
|
||||
// const model = utils.deepClone(element);
|
||||
|
||||
// // this.$iscs.update([
|
||||
// // { status: 's1', code: '100', type: 'Device' },
|
||||
// // { status: 's2', code: '101', type: 'Device' }
|
||||
// // ]);
|
||||
|
||||
// // model.frameList = [];
|
||||
// // const style = elementStyle.style || {};
|
||||
// // // model.changeStyle =
|
||||
// // if (style && JSON.stringify(style) != '{}') {
|
||||
// // const keys = Object.keys(style);
|
||||
// // keys.forEach(eachKey=>{
|
||||
// // model.style[eachKey] = style[eachKey];
|
||||
// // });
|
||||
// // }
|
||||
// // const shape = elementStyle.shape || {};
|
||||
// // if (shape && JSON.stringify(shape) != '{}') {
|
||||
// // const keys = Object.keys(shape);
|
||||
// // keys.forEach(eachShape=>{
|
||||
// // model.shape[eachShape] = style[eachShape];
|
||||
// // });
|
||||
// // }
|
||||
// // { status: 's1', code: '100', type: 'Device' },
|
||||
// // this.$refs.iscsCanvas.doAction([{model, action: {shapeType: shapeType.Element, order: orders.Update}}]);
|
||||
// this.$refs.iscsCanvas.doAction([{model, action: {shapeType: shapeType.Element, order: orders.ChangeStatus}}]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
},
|
||||
resetDefaultStatus() {
|
||||
this.elementList.forEach(element=>{
|
||||
|
@ -101,7 +101,7 @@ export default {
|
||||
if (this.$route.query.id) {
|
||||
setTimeout(_ => {
|
||||
Idb.select('composeTemplateList', this.$route.query.id).then(resp => {
|
||||
this.$iscs.setMap([], {
|
||||
this.$iscs.setMap([resp], {
|
||||
elementList: resp.shapeList || [],
|
||||
composeList: resp.composeList || []
|
||||
}, option);
|
||||
|
Loading…
Reference in New Issue
Block a user