From 3026eed3655f3a95c9f3ae5b36c1c8ee565c10b7 Mon Sep 17 00:00:00 2001 From: ival <160568032@qq.com> Date: Sun, 4 Apr 2021 02:16:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/iscs_new/animateHandle.js | 3 ++- src/iscs_new/factory/templateParser.js | 9 +++++---- src/iscs_new/stateHandle.js | 11 +++++++++++ src/iscs_new/utils/utils.js | 9 +++++---- src/views/test/index.vue | 20 ++++++++++---------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/iscs_new/animateHandle.js b/src/iscs_new/animateHandle.js index 0a0c3067f..9b66d3e88 100644 --- a/src/iscs_new/animateHandle.js +++ b/src/iscs_new/animateHandle.js @@ -45,7 +45,8 @@ class Animate { const mapView = traverse(shape, {}); if(shape && frameList) { const size = frameList.length; - const frame = frameList[this.count%size]; + const index = this.count%size; + const frame = frameList[index]; Object.keys(frame).forEach(name => { const view = mapView[name]; const model = frame[name]; diff --git a/src/iscs_new/factory/templateParser.js b/src/iscs_new/factory/templateParser.js index 93dd0b04c..b26a89a28 100644 --- a/src/iscs_new/factory/templateParser.js +++ b/src/iscs_new/factory/templateParser.js @@ -1,4 +1,5 @@ -const defStatus = 'defStatus'; +import * as utils from '../utils/utils'; + class TemplateParser { constructor() { } @@ -17,10 +18,10 @@ class TemplateParser { parseShape(list=[], map={}) { list.forEach(el => { - const shapeMap = map[el.name] = {}; - shapeMap[defStatus] = { status: defStatus, style: el.style, shape: el.shape }; + const mapShape = map[el.name] = {}; + mapShape[utils.defStatus] = { status: utils.defStatus, style: el.style, shape: el.shape }; (el.stateList||[]).forEach(it => { - shapeMap[it.status] = it; + mapShape[it.status] = it; }) }) return map; diff --git a/src/iscs_new/stateHandle.js b/src/iscs_new/stateHandle.js index 338f79036..28b3aae70 100644 --- a/src/iscs_new/stateHandle.js +++ b/src/iscs_new/stateHandle.js @@ -1,3 +1,4 @@ +import * as utils from './utils/utils'; export default class StateHandle { constructor(map) { @@ -9,6 +10,16 @@ export default class StateHandle { const template = mapTemplate[state.type]; const templateState = template.mapState[state.status]; + if (templateState.needDefault) { + templateState.frameList.unshift( + Object.entries(template.mapShape).map(el => { + return { name: el[0], ...el[1][utils.defStatus]}; + }) + ); + } + + console.log(Object.entries(template.mapShape)) + return { ...state, ...templateState, diff --git a/src/iscs_new/utils/utils.js b/src/iscs_new/utils/utils.js index d6453e533..d3e948d37 100644 --- a/src/iscs_new/utils/utils.js +++ b/src/iscs_new/utils/utils.js @@ -1,12 +1,13 @@ import BoundingRect from 'zrender/src/core/BoundingRect'; import * as matrix from 'zrender/src/core/matrix'; -var base = 0; +// 默认状态标识 +export const defStatus = 'default'; // 获取一个UID -export function getUID(type) { - return [(type || ''), base++, Math.random().toFixed(5)].join('_'); -} +export const getUID =(function(base=0) { + return function(type) { return [(type || ''), base++, Math.random().toFixed(5)].join('_');} +})(); // 克隆一个对象 export function deepClone(obj) { diff --git a/src/views/test/index.vue b/src/views/test/index.vue index d08f9ef1d..dff11d677 100644 --- a/src/views/test/index.vue +++ b/src/views/test/index.vue @@ -286,17 +286,17 @@ export default { scale: [1, 1], position: [200, 0], rotation: 0, - // composeCode: '1000' + composeCode: '1000' }, - // { - // code: '1000', - // type: 'Device', - // scale: [1, 1], - // position: [0, 0], - // rotation: 0, - // elementCodes: ['100', '101'], - // composeCode: '' - // } + { + code: '1000', + type: 'Device', + scale: [1, 1], + position: [0, 0], + rotation: 0, + elementCodes: ['100', '101'], + composeCode: '' + } ] }, { panEnable: true,