状态显示 代码调整

This commit is contained in:
joylink_cuiweidong 2021-04-22 16:28:57 +08:00
parent c1356549ec
commit 85de91411e
5 changed files with 539 additions and 463 deletions

View File

@ -42,12 +42,12 @@ class JMap {
this.draw = opts.draw; this.draw = opts.draw;
// 实例化zr // 实例化zr
this.$zr = zrender.init(opts.dom, { renderer, devicePixelRatio, width, height, ...utils.deepClone(opts.config||{})}); this.$zr = zrender.init(opts.dom, { renderer, devicePixelRatio, width, height, ...utils.deepClone(opts.config || {})});
this.$zr.dom.setAttribute('tabIndex', -1); this.$zr.dom.setAttribute('tabIndex', -1);
this.$zr.dom.style.cursor = 'auto'; this.$zr.dom.style.cursor = 'auto';
// 实例化缩放偏移缩放参数 // 实例化缩放偏移缩放参数
this.$option = new Option({ scaleRate: 1, offsetX: 0, offsetY: 0, ...utils.deepClone(opts.option||{})}, (dataZoom) => { this.$controller.trigger(events.DataZoom, dataZoom); }); // 缩放 this.$option = new Option({ scaleRate: 1, offsetX: 0, offsetY: 0, ...utils.deepClone(opts.option || {})}, (dataZoom) => { this.$controller.trigger(events.DataZoom, dataZoom); }); // 缩放
// 实例化绘图模块 // 实例化绘图模块
this.$painter = new Painter(this); this.$painter = new Painter(this);
@ -75,11 +75,11 @@ class JMap {
}; };
// 加载插件 // 加载插件
this.plugins = opts.plugins||[]; this.plugins = opts.plugins || [];
this.plugins.forEach(el => { this.use(el); }); this.plugins.forEach(el => { this.use(el); });
} }
setMap(templates=[], source={}, eventOpts={}) { setMap(templates = [], source = {}, eventOpts = {}) {
// 清楚数据 // 清楚数据
this.$shapeFactory.clear(); this.$shapeFactory.clear();
this.$painter.clear(); this.$painter.clear();
@ -91,7 +91,7 @@ class JMap {
this.$painter.updateTransform(this.$option); this.$painter.updateTransform(this.$option);
// 解析模板 // 解析模板
this.$shapeFactory.parseTemplates(templates) this.$shapeFactory.parseTemplates(templates);
// 数据加载完成 回调 // 数据加载完成 回调
this.$eventEmitter.trigger(events.DataLoaded); this.$eventEmitter.trigger(events.DataLoaded);
@ -116,8 +116,8 @@ class JMap {
return this; return this;
} }
setOption(opts={}) { setOption(opts = {}) {
this.$option.update(opts.type == this.events.__Zoom? pullBack(this.$zr, this.$option, opts):opts); this.$option.update(opts.type == this.events.__Zoom ? pullBack(this.$zr, this.$option, opts) : opts);
this.$painter.updateTransform(this.$option); this.$painter.updateTransform(this.$option);
this.$controller.disable(); this.$controller.disable();
@ -142,41 +142,41 @@ class JMap {
return this; return this;
} }
setCursorStyle(cursorStyle='auto') { setCursorStyle(cursorStyle = 'auto') {
this.$zr.setCursorStyle(cursorStyle); this.$zr.setCursorStyle(cursorStyle);
return this; return this;
} }
repaint(source={}) { repaint(source = {}) {
this.$shapeFactory.parse(source, shape => { this.$shapeFactory.parse(source, shape => {
if (shape) { if (shape) {
this.$painter.add(shape) this.$painter.add(shape);
} }
}); });
return this; return this;
} }
render(list=[]) { render(list = []) {
list.forEach(({model, action}) => { list.forEach(({model, action}) => {
let updateModel = this.isDrawing() ? this.$shapeFactory.updateSource(model, action): model; let updateModel = this.isDrawing() ? this.$shapeFactory.updateSource(model, action) : model;
let curShape = this.$shapeFactory.getShapeByCode(updateModel.code); let curShape = this.$shapeFactory.getShapeByCode(updateModel.code);
let deps = null; let deps = null;
let oldShape = null let oldShape = null;
let newShape = null; let newShape = null;
if (updateModel) { if (updateModel) {
this.$controller.clear(); this.$controller.clear();
switch(action.order) { switch (action.order) {
case orders.Binding: case orders.Binding:
case orders.Add: case orders.Add:
newShape = this.$shapeFactory.createShape(updateModel, action.shapeType); newShape = this.$shapeFactory.createShape(updateModel, action.shapeType);
this.$shapeFactory.addShape(newShape) this.$shapeFactory.addShape(newShape);
this.$painter.add(newShape); this.$painter.add(newShape);
break; break;
case orders.Delete: case orders.Delete:
deps = curShape.getDepShapes(); deps = curShape.getDepShapes();
deps.forEach(el => { deps.forEach(el => {
updateModel = this.isDrawing() ? this.$shapeFactory.updateSource(el, {...action, shapeType: el.shapeType}): el; updateModel = this.isDrawing() ? this.$shapeFactory.updateSource(el, {...action, shapeType: el.shapeType}) : el;
if (updateModel) { if (updateModel) {
curShape = this.$shapeFactory.getShapeByCode(updateModel.code); curShape = this.$shapeFactory.getShapeByCode(updateModel.code);
oldShape = this.$shapeFactory.removeShape(curShape); oldShape = this.$shapeFactory.removeShape(curShape);
@ -188,7 +188,7 @@ class JMap {
oldShape = this.$shapeFactory.removeShape(curShape); oldShape = this.$shapeFactory.removeShape(curShape);
this.$painter.remove(oldShape); this.$painter.remove(oldShape);
newShape = this.$shapeFactory.createShape(updateModel, action.shapeType); newShape = this.$shapeFactory.createShape(updateModel, action.shapeType);
this.$shapeFactory.addShape(newShape) this.$shapeFactory.addShape(newShape);
this.$painter.add(newShape); this.$painter.add(newShape);
break; break;
case orders.Unbinding: case orders.Unbinding:
@ -197,6 +197,12 @@ class JMap {
this.$shapeFactory.addShape(oldShape); this.$shapeFactory.addShape(oldShape);
this.$painter.add(oldShape); this.$painter.add(oldShape);
break; break;
case orders.changeStatus:
debugger;
break;
case orders.ResetStatus:
debugger;
break;
} }
} }
}); });
@ -205,7 +211,7 @@ class JMap {
return this; return this;
} }
update(list=[]) { update(list = []) {
this.$painter.update(this.$stateHandle.update(this.$shapeFactory, list)); this.$painter.update(this.$stateHandle.update(this.$shapeFactory, list));
this.$eventEmitter.trigger(events.StateUpdate, list); this.$eventEmitter.trigger(events.StateUpdate, list);
return this; return this;
@ -272,11 +278,11 @@ class JMap {
this.$shapeFactory.clear(); this.$shapeFactory.clear();
this.$controller.clear(); this.$controller.clear();
this.$painter.clear(); this.$painter.clear();
this.$zr.refresh() this.$zr.refresh();
} }
use(el) { use(el) {
this.plugins.includes(el)||this.plugins.push(el) this.plugins.includes(el) || this.plugins.push(el);
el.install(this); el.install(this);
} }
@ -289,7 +295,7 @@ class JMap {
this.$zr && this.$zr.dispose(); this.$zr && this.$zr.dispose();
this.plugins.forEach(el => { this.plugins.forEach(el => {
el.uninstall(this); el.uninstall(this);
}) });
this.plugins = []; this.plugins = [];
} }
@ -390,7 +396,7 @@ class JMap {
} }
} }
function pullBack(zr, option={}, payload={}) { function pullBack(zr, option = {}, payload = {}) {
const zrWidth = zr.getWidth(); const zrWidth = zr.getWidth();
const zrHeight = zr.getHeight(); const zrHeight = zr.getHeight();
const originX = payload.originX || zrWidth / 2; const originX = payload.originX || zrWidth / 2;

View File

@ -4,4 +4,6 @@ export default {
Update: '&UPT', Update: '&UPT',
Binding: '&Binding', Binding: '&Binding',
Unbinding: '&Unbinding', Unbinding: '&Unbinding',
} ChangeStatus:'&ChangeStatus',
ResetStatus:'&ResetStatus'
};

View File

@ -66,7 +66,7 @@
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="success" size="mini" @click="modifyStatus(scope.$index,scope.row)">编辑状态组合</el-button> <el-button type="success" size="mini" @click="modifyStatus(scope.$index,scope.row)">编辑状态组合</el-button>
<el-button type="danger" size="mini" style="margin-top:5px;" @click="deleteStatus(scope.$index,scope.row)">删除</el-button> <el-button type="danger" size="mini" style="margin-top:5px;" @click="deleteStatus(scope.$index,scope.row)">删除</el-button>
<el-button type="primary" size="mini" style="margin-top:5px;" @click="previewStatus(scope.$index,scope.row)">预览</el-button> <!-- <el-button type="primary" size="mini" style="margin-top:5px;" @click="previewStatus(scope.$index,scope.row)">预览</el-button> -->
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -333,25 +333,25 @@ export default {
}); });
} }
}, }
previewStatus(index, row) { // previewStatus(index, row) {
// const that = this; // // const that = this;
// if(needDefault) // // if(needDefault)
const list = Object.values(row.covertStatusList); // const list = Object.values(row.covertStatusList);
list.forEach(each=>{ // list.forEach(each=>{
if (each.loop) { // if (each.loop) {
} else { // } else {
const frameList = each.frameList; // const frameList = each.frameList;
frameList.forEach(frame=>{ // frameList.forEach(frame=>{
// frame.name; // // frame.name;
// frame.status; // // frame.status;
// this.$iscs. // // this.$iscs.
}); // });
} // }
}); // });
// this.show = false; // // this.show = false;
} // }
} }
}; };
</script> </script>

View File

@ -2,22 +2,37 @@
<transition name="el-zoom-in-center"> <transition name="el-zoom-in-center">
<div class="mapPaint"> <div class="mapPaint">
<div class="map-view"> <div class="map-view">
<iscs-canvas ref="iscsCanvas" @selected="onSelected" /> <iscs-canvas ref="iscsCanvas" @selected="onSelected" @setData="setData" />
</div> </div>
<div class="right-card"> <div class="right-card">
<!-- :class="{'hide': draftShow}" --> <!-- :class="{'hide': draftShow}" -->
<el-card type="border-card" class="heightClass"> <el-card type="border-card" class="heightClass">
<div slot="header" class="clearfix"> <div slot="header" class="clearfix">
<!-- 组件id为{{ $route.query.id }} --> <!-- 组件id为{{ $route.query.id }} -->
状态编辑 状态预览
<!-- -->
<el-button
type="text"
style="float: right; padding: 3px 0; margin-right: 5px;"
@click="resetDefaultStatus"
>重置状态</el-button>
</div> </div>
<div class="stateList"> <div class="stateList">
<el-tabs v-model="statusTab" class="card" type="card" @tab-click="onSelectTab"> <!-- <el-card style="margin-top:10px;height:100%"> -->
<el-tab-pane v-for="(composeElem,index) in composeElemList" :key="index" :label="composeElem.name" :name="composeElem.code" :lazy="true"> <div v-for="(state,index) in stateList" :key="index" class="eachStatus">
<div>状态属性{{ state.status }}</div>
<div>状态描述{{ state.description }}</div>
<div>状态权重{{ state.weight }}</div>
<div>状态是否可以初始化{{ state.needDefault?'是':'否' }}</div>
<el-button type="primary" size="mini" style="margin-top:5px;" @click="previewStatus(state)">预览</el-button>
</div>
<!-- </el-card> -->
<!-- <el-tabs v-model="statusTab" class="card" type="card" @tab-click="onSelectTab"> -->
<!-- <el-tab-pane v-for="(composeElem,index) in composeElemList" :key="index" :label="composeElem.name" :name="composeElem.code" :lazy="true"> -->
<!-- <table-form :ref="'tableform'+composeElem.code" :compose-elem="composeElem" /> --> <!-- <table-form :ref="'tableform'+composeElem.code" :compose-elem="composeElem" /> -->
<!-- stateList --> <!-- stateList -->
</el-tab-pane> <!-- </el-tab-pane> -->
</el-tabs> <!-- </el-tabs> -->
</div> </div>
</el-card> </el-card>
</div> </div>
@ -25,8 +40,10 @@
</transition> </transition>
</template> </template>
<script> <script>
import * as utils from '@/iscs_new/utils/utils';
import iscsCanvas from './iscsCanvas'; import iscsCanvas from './iscsCanvas';
import { EventBus } from '@/scripts/event-bus'; import orders from '@/iscs_new/utils/orders';
import shapeType from '@/iscs_new/constant/shapeType.js';
export default { export default {
name:'IscsPreview', name:'IscsPreview',
components: { components: {
@ -37,55 +54,89 @@ export default {
draftShow: false, draftShow: false,
selected: null, selected: null,
statusTab:'', statusTab:'',
composeElemList:[] stateList:[],
elementList:[]
}; };
}, },
mounted() { mounted() {
EventBus.$on('getComposeElemList', () => {
this.getComposeElemList();
});
}, },
methods:{ methods:{
onSelectTab() { onSelectTab() {
}, },
getComposeElemList() { setData(data ) {
const source = this.$iscs.getSource(); this.stateList = data.stateList;
if (source && this.elementList = utils.deepClone(data.shapeList);
source.elementList &&
source.elementList.length) {
this.composeElemList = source.elementList;
this.statusTab = this.composeElemList[0].code;
} else {
this.composeElemList = [];
}
}, },
onSelected(em) { previewStatus(data) {
// if (em.model) { this.resetDefaultStatus();
// this.selected = JSON.parse(JSON.stringify(em.model)); const that = this;
// const elem = this.elementList.find(el => el.type == this.selected.type); const list = Object.values(data.covertStatusList);
// if (elem) { list.forEach(each=>{
// elem.model = this.selected; if (each.loop) {
// this.enabledTab = this.selected.type; debugger;
// this.cardTab = 'first'; // ChangeStatus
} else {
const frameList = each.frameList;
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];
// });
// }
// this.$refs.iscsCanvas.doAction([{model, action: {shapeType: shapeType.Element, order: orders.ChangeStatus}}]);
}
}
});
}
});
},
resetDefaultStatus() {
this.elementList.forEach(element=>{
const model = utils.deepClone(element);
// this.$refs.iscsCanvas.doAction([{model, action: {shapeType: shapeType.Element, order: orders.ResetStatus}}]);
});
},
// getComposeElemList() {
// const source = this.$iscs.getSource();
// if (source &&
// source.elementList &&
// source.elementList.length) {
// this.composeElemList = source.elementList;
// this.statusTab = this.composeElemList[0].code;
// } else { // } else {
// this.selected = null; // this.composeElemList = [];
// this.clear(this.enabledTab);
// } // }
// },
onSelected(em) {
} }
} }
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.mapPaint{ .mapPaint{
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
width:100%; width:100%;
position:absolute; position:absolute;
left:0;top:0; left:0;top:0;
} }
.right-card{ .right-card{
width: 500px; width: 500px;
height: 100%; height: 100%;
position: absolute; position: absolute;
@ -94,5 +145,22 @@ export default {
transition: all 0.5s; transition: all 0.5s;
background: #fff; background: #fff;
z-index: 9; z-index: 9;
} }
.heightClass{height:100%;overflow:hidden;display:flex;width: 100%;flex-direction: column;}
.eachStatus{
padding: 15px 30px;
border-bottom: 1px #ccc solid;
line-height: 150%;
}
.statelist{
height: 100%;
overflow: auto;
}
</style>
<style lang="scss">
.heightClass .el-card__body{
flex:1;
height: 100%;
overflow: hidden;
}
</style> </style>

View File

@ -97,22 +97,22 @@ export default {
selecting: false, selecting: false,
selectable: false, selectable: false,
reflect: true reflect: true
} };
if (this.$route.query.id) { if (this.$route.query.id) {
setTimeout(_ => { setTimeout(_ => {
Idb.select('composeList', this.$route.query.id).then(resp => { Idb.select('composeTemplateList', this.$route.query.id).then(resp => {
this.$iscs.setMap([], { this.$iscs.setMap([], {
elementList: resp.elementList||[], elementList: resp.shapeList || [],
composeList: resp.composeList||[] composeList: resp.composeList || []
}, option); }, option);
EventBus.$emit('getComposeElemList'); this.$emit('setData', resp);
}).catch(error => { }).catch(error => {
this.$iscs.setMap([], { this.$iscs.setMap([], {
elementList: [], elementList: [],
composeList: [] composeList: []
}, option); }, option);
}) });
}, 1000) }, 1000);
} else { } else {
this.$iscs.setMap([], { this.$iscs.setMap([], {
elementList: [], elementList: [],
@ -138,14 +138,14 @@ export default {
console.log(hook); console.log(hook);
}, },
// //
onClick(em={}) { onClick(em = {}) {
this.$emit('selected', em); this.$emit('selected', em);
}, },
onReflect(em={}) { onReflect(em = {}) {
this.$emit('selected', this.$iscs.getShapeByCode(em.code)); this.$emit('selected', this.$iscs.getShapeByCode(em.code));
}, },
// //
onContextMenu(em={}) { onContextMenu(em = {}) {
this.$emit('contextMenu', em.model); this.$emit('contextMenu', em.model);
}, },
// //
@ -169,7 +169,7 @@ export default {
this.$iscs = null; this.$iscs = null;
Vue.prototype.$iscs = null; Vue.prototype.$iscs = null;
} }
}, }
} }
}; };
</script> </script>