新增模板 预览 修正部分语法

2.1
咬轮猫 4 years ago
parent 13e23fc4dc
commit 070af46c61

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

@ -182,7 +182,7 @@
"type": "TextSvg", "type": "TextSvg",
"title": "文字", "title": "文字",
"panel_class":"draggable", "panel_class":"draggable",
"template": "<text x=\"0\" y=\"0\" font-size=\"50\" :fill=\"prop_data.svgColor\">{{prop_data.title}}</text>", "template": "<text x=\"0\" y=\"0\" font-size=\"10\" :fill=\"prop_data.svgColor\">{{prop_data.title}}</text>",
"props": ["prop_data"], "props": ["prop_data"],
"default_attr":{ "default_attr":{
"color":"#FF0000" "color":"#FF0000"
@ -208,7 +208,7 @@
"type": "TransformerYSvg", "type": "TransformerYSvg",
"title": "电流互感器Y", "title": "电流互感器Y",
"panel_class":"draggable", "panel_class":"draggable",
"template": "<ellipse cx=\"0\" cy=\"0\" rx=\"10\" ry=\"10\" fill=\"none\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></ellipse> <line x1=\"-2\" y1=\"-6\" x2=\"-2\" y2=\"6\" fill=\"none\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></line> <line x1=\"-2\" y1=\"-6\" x2=\"4\" y2=\"0\" fill=\"none\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></line> <line x1=\"4\" y1=\"2\" x2=\"-2\" y2=\"6\" fill=\"none\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></line>", "template": "<ellipse cx=\"0\" cy=\"0\" rx=\"10\" ry=\"10\" fill=\"none\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></ellipse> <line x1=\"5\" y1=\"-5\" x2=\"0\" y2=\"0\" fill=\"none\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></line> <line x1=\"-5\" y1=\"-5\" x2=\"0\" y2=\"0\" fill=\"none\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></line> <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"5\" fill=\"none\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></line>",
"props": ["prop_data"], "props": ["prop_data"],
"default_attr":{ "default_attr":{
"color":"#FF0000" "color":"#FF0000"
@ -269,11 +269,37 @@
"create_type":"click", "create_type":"click",
"priview_img":"/VerticalLineSvg.png" "priview_img":"/VerticalLineSvg.png"
}, },
{
"type": "ConnHorizontalLineSvg",
"title": "连接线-横线",
"panel_class":"draw",
"template": "<line x1=\"0\" y1=\"0\" :x2=\"(prop_data.mPoint.endX-prop_data.mPoint.startX)\" y2=\"0\" :fill=\"prop_data.svgColor\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></line>",
"props": ["prop_data"],
"default_attr":{
"color":"#FF0000"
},
"data_type":"none",
"create_type":"click",
"priview_img":"/ConnHorizontalLineSvg.png"
},
{
"type": "ConnVerticalLineSvg",
"title": "连接线-竖线",
"panel_class":"draw",
"template": "<line x1=\"0\" y1=\"0\" x2=\"0\" :y2=\"(prop_data.mPoint.endY-prop_data.mPoint.startY)\" :fill=\"prop_data.svgColor\" :stroke=\"prop_data.svgColor\" stroke-width=\"2\"></line>",
"props": ["prop_data"],
"default_attr":{
"color":"#FF0000"
},
"data_type":"none",
"create_type":"click",
"priview_img":"/VerticalLineSvg.png"
},
{ {
"type": "EchartsPieSvg", "type": "EchartsPieSvg",
"title": "Echart饼图", "title": "Echart饼图",
"panel_class":"chart", "panel_class":"chart",
"template": "<foreignObject x=\"0\" y=\"0\" width=\"400\" height=\"400\"> <v-chart :option=\"prop_data.echarts_option\" /></foreignObject>", "template": "<foreignObject x=\"0\" y=\"0\" width=\"600\" height=\"500\"> <v-chart :option=\"prop_data.echartsOption\" /></foreignObject>",
"props": ["prop_data"], "props": ["prop_data"],
"default_attr":{ "default_attr":{
"color":"#000000", "color":"#000000",
@ -287,7 +313,7 @@
"type": "EchartsBasicBarSvg", "type": "EchartsBasicBarSvg",
"title": "Echart基础柱状图", "title": "Echart基础柱状图",
"panel_class":"chart", "panel_class":"chart",
"template": "<foreignObject x=\"0\" y=\"0\" width=\"400\" height=\"400\"> <v-chart :option=\"prop_data.echarts_option\" /></foreignObject>", "template": "<foreignObject x=\"0\" y=\"0\" width=\"400\" height=\"400\"> <v-chart :option=\"prop_data.echartsOption\" /></foreignObject>",
"props": ["prop_data"], "props": ["prop_data"],
"default_attr":{ "default_attr":{
"color":"#000000", "color":"#000000",

File diff suppressed because it is too large Load Diff

@ -24,7 +24,7 @@
<ul class="svg-nav-list"> <ul class="svg-nav-list">
<li v-for="item in drawComponentList" <li v-for="item in drawComponentList"
:key="item" :key="item"
:class="$store.state.CurrentlySelectedToolBar.CreateType==item.create_type?'toolbar-selected':''"> :class="$store.state.CurrentlySelectedToolBar.Type==item.type?'toolbar-selected':''">
<div class="title">{{item.title}}</div> <div class="title">{{item.title}}</div>
<img :title="item.title" <img :title="item.title"
@mousedown="Mousedown(item.type,item.title,item.default_attr,item.create_type)" @mousedown="Mousedown(item.type,item.title,item.default_attr,item.create_type)"

@ -36,6 +36,8 @@
@ok="versionModelHandleOk"> @ok="versionModelHandleOk">
<p>新增绘制组件</p> <p>新增绘制组件</p>
<p>新增图表</p> <p>新增图表</p>
<p>新增模板-加载模板后点击预览-点击模拟硬件-等待两秒查看效果</p>
<p>如果图片加载不出来请清空缓存刷新(F12右键刷新按钮-选择清空缓存并进行硬刷新)</p>
</a-modal> </a-modal>
<!-- <a-button type="primary" <!-- <a-button type="primary"
@ -46,6 +48,9 @@
<a-button type="danger" <a-button type="danger"
@click="versionModelVisible=true">当前为2.1版本</a-button> @click="versionModelVisible=true">当前为2.1版本</a-button>
<a-button type="primary"
@click="testA"
style="margin-left:20px">载入模板</a-button>
<a-button type="primary" <a-button type="primary"
@click="testH" @click="testH"
style="margin-left:20px">预览</a-button> style="margin-left:20px">预览</a-button>
@ -70,13 +75,18 @@
<a-button type="primary">在线绘图</a-button> <a-button type="primary">在线绘图</a-button>
</a> </a>
<a style="margin-left:20px" <a style="margin-left:20px"
href="https://github.com/yaolunmao/vue-webtopo-svgeditor"> href="https://www.cnblogs.com/Hero-/p/14784744.html"
target="_blank">
<a-button type="primary">帮助</a-button> <a-button type="primary">帮助</a-button>
</a> </a>
<a style="margin-left:20px"> <a style="margin-left:20px">
<a-button type="primary" <a-button type="primary"
@click="exportSvg">导出svg</a-button> @click="exportSvg">导出svg</a-button>
</a> </a>
<a style="margin-left:20px">
<a-button type="primary"
@click="exportData">导出数据</a-button>
</a>
</a-layout-header> </a-layout-header>
<span v-if="!shrink" <span v-if="!shrink"
@click="exitFullscreen" @click="exitFullscreen"
@ -85,25 +95,29 @@
<a-layout-sider class="leftNav"> <a-layout-sider class="leftNav">
<LeftToolBar :svgInfoData=svgInfoData></LeftToolBar> <LeftToolBar :svgInfoData=svgInfoData></LeftToolBar>
</a-layout-sider> </a-layout-sider>
<a-layout-content class="centerContain" <a-layout-content
:class="{ fixed: !shrink }"> :class="{ fixed: !shrink }"
style="transform: scale(1)">
<div class="canvas-content" <div class="canvas-content"
id="canvas" ref="canvas"
@mousemove="MouseMove" @mousemove="MouseMove"
@mousedown="MousedownCanvas" @mousedown="MousedownCanvas"
@mouseup="MouseupCanvas" @mouseup="MouseupCanvas"
@dblclick="DblClick" @dblclick="DblClick"
@mousewheel="MouseWheel"> @mousewheel="MouseWheel">
<!--拖动辅助线--> <!--拖动辅助线-->
<div id="guide-x"></div> <div id="guide-x"
<div id="guide-y"></div> ref="guidex_dom"></div>
<div id="guide-y"
ref="guidey_dom"></div>
<!-- 画布 --> <!-- 画布 -->
<svg version="1.1" <svg version="1.1"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xlink="http://www.w3.org/1999/xlink"
style="background-color:#000000" style="background-color:#000000"
width="100%" width="1920"
height="100%" height="1080"
id="svgCanvas"> id="svgCanvas">
<defs /> <defs />
<filter x="0" <filter x="0"
@ -168,9 +182,6 @@ export default {
positionX: '', positionX: '',
positiony: '' positiony: ''
}, },
//线
guideX: '',
guideY: '',
selectSvg: { selectSvg: {
ID: '',//svg ID: '',//svg
Index: 0, Index: 0,
@ -200,9 +211,25 @@ export default {
this.versionModelVisible = false; this.versionModelVisible = false;
}, },
exportSvg () { exportSvg () {
var exportStr = document.querySelector("#svgCanvas").outerHTML; let exportStr = document.querySelector("#svgCanvas").outerHTML;
exportStr = exportStr.replace('width="100%"', 'width="1920"').replace('height="100%"', 'height="1080"');
let datastr = 'data:text;charset=utf-8,' + encodeURIComponent(exportStr)
let download = document.createElement('a')
download.setAttribute('href', datastr)
download.setAttribute('download', 'download.html')
download.click()
download.remove()
console.log(exportStr); console.log(exportStr);
alert("请使用F12查看consolo面板"); },
exportData () {
localStorage.setItem('svginfo', JSON.stringify(this.svgLists));
let datastr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(this.svgLists))
let download = document.createElement('a')
download.setAttribute('href', datastr)
download.setAttribute('download', 'download.json')
download.click()
download.remove()
console.log(JSON.stringify(this.svgLists));
}, },
MouseMove (e) { MouseMove (e) {
let _this = this; let _this = this;
@ -247,22 +274,22 @@ export default {
return list.svgPositionX === svgPositionX return list.svgPositionX === svgPositionX
}); });
if (exitsNowX.length > 0) { if (exitsNowX.length > 0) {
_this.guideY.style.setProperty('left', svgPositionX - 1 + 'px'); _this.$refs.guidey_dom.style.setProperty('left', svgPositionX - 1 + 'px');
_this.guideY.style.display = 'inline'; _this.$refs.guidey_dom.style.display = 'inline';
} }
else { else {
_this.guideY.style.display = 'none'; _this.$refs.guidey_dom.style.display = 'none';
} }
//y //y
let exitsNowY = anyPositionList.filter(function (list) { let exitsNowY = anyPositionList.filter(function (list) {
return list.svgPositionY === svgPositionY return list.svgPositionY === svgPositionY
}); });
if (exitsNowY.length > 0) { if (exitsNowY.length > 0) {
_this.guideX.style.setProperty('top', svgPositionY + 'px'); _this.$refs.guidex_dom.style.setProperty('top', svgPositionY + 'px');
_this.guideX.style.display = 'inline'; _this.$refs.guidex_dom.style.display = 'inline';
} }
else { else {
_this.guideX.style.display = 'none'; _this.$refs.guidex_dom.style.display = 'none';
} }
}, 1); }, 1);
} }
@ -324,8 +351,8 @@ export default {
if (this.mouseStatus == 0) { if (this.mouseStatus == 0) {
return; return;
} }
this.guideX.style.display = 'none'; this.$refs.guidex_dom.style.display = 'none';
this.guideY.style.display = 'none'; this.$refs.guidey_dom.style.display = 'none';
// if (this.$store.state.CurrentlySelectedToolBar.Type != '') { // if (this.$store.state.CurrentlySelectedToolBar.Type != '') {
// return; // return;
// } // }
@ -365,6 +392,18 @@ export default {
this.selectSvgInfo = ''; this.selectSvgInfo = '';
this.$store.clearCurrentlySelectedToolBarAction(); this.$store.clearCurrentlySelectedToolBarAction();
}, },
testA () {
let _this = this;
//
this.$axios.get('/example.json')
.then(function (response) {
_this.svgLists = response.data;
// console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
},
testD () { testD () {
alert(JSON.stringify(this.svgLists)); alert(JSON.stringify(this.svgLists));
}, },
@ -413,35 +452,35 @@ export default {
}, },
mounted () { mounted () {
let _this = this; let _this = this;
let canvasdiv = document.querySelector('#canvas'); this.$nextTick(() => {
_this.guideX = document.querySelector('#guide-x');//线x let canvasdiv = _this.$refs.canvas;
_this.guideY = document.querySelector('#guide-y');//线y canvasdiv.addEventListener("dragover", function (e) {
canvasdiv.addEventListener("dragover", function (e) { e.preventDefault();
e.preventDefault(); }, false);
}, false); canvasdiv.addEventListener("drop", function (e) {
canvasdiv.addEventListener("drop", function (e) { e.preventDefault();
e.preventDefault(); if (_this.$store.state.CurrentlySelectedToolBar.Type == '' || _this.$store.state.CurrentlySelectedToolBar.CreateType != 'draggable') {
if (_this.$store.state.CurrentlySelectedToolBar.Type == '' || _this.$store.state.CurrentlySelectedToolBar.CreateType != 'draggable') { return;
return; }
} let eChartsOption = _this.$store.state.CurrentlySelectedToolBar.EChartsOption;
let eChartsOption = _this.$store.state.CurrentlySelectedToolBar.EChartsOption; //
// let svgItem = {
let svgItem = { id: _this.$UCore.GenUUid(),
id: _this.$UCore.GenUUid(), title: _this.$store.state.CurrentlySelectedToolBar.Title,
title: _this.$store.state.CurrentlySelectedToolBar.Title, type: _this.$store.state.CurrentlySelectedToolBar.Type,
type: _this.$store.state.CurrentlySelectedToolBar.Type, typeName: _this.$store.state.CurrentlySelectedToolBar.TypeName,
typeName: _this.$store.state.CurrentlySelectedToolBar.TypeName, svgColor: _this.$store.state.CurrentlySelectedToolBar.Color,
svgColor: _this.$store.state.CurrentlySelectedToolBar.Color, svgPositionX: e.offsetX,
svgPositionX: e.offsetX, svgPositionY: e.offsetY,
svgPositionY: e.offsetY, echartsOption: eChartsOption ? JSON.parse(eChartsOption) : "",
echarts_option: eChartsOption ? JSON.parse(eChartsOption) : "", size: 1,
size: 1, angle: 0
angle: 0 //translate:`translate(${this.mousePosition.positionX},${this.mousePosition.positionY})`
//translate:`translate(${this.mousePosition.positionX},${this.mousePosition.positionY})` };
}; _this.svgLists.push(svgItem);
_this.svgLists.push(svgItem); _this.selectSvgInfo = svgItem;
_this.selectSvgInfo = svgItem; }, false);
}, false); })
}, },
created () { created () {
let _this = this; let _this = this;
@ -571,6 +610,11 @@ export default {
.canvas-content { .canvas-content {
width: 1920px; width: 1920px;
height: 1080px; height: 1080px;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none;
} }
.btns-content { .btns-content {
position: fixed; position: fixed;
@ -631,13 +675,6 @@ export default {
left: 100px; left: 100px;
top: 0px; top: 0px;
} }
#canvas {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none;
}
.ant-slider { .ant-slider {
margin-bottom: 16px; margin-bottom: 16px;
} }

@ -19,12 +19,12 @@
</g> </g>
</svg> </svg>
</div> </div>
<!-- <div class="btns-content"> <div class="btns-content">
<a-button type="primary" <a-button type="primary"
@click="testF">模拟硬件</a-button> @click="testF">模拟硬件</a-button>
<a-button type="primary" <a-button type="primary"
@click="testG">取消模拟硬件</a-button> @click="testG">取消模拟硬件</a-button>
</div> --> </div>
</div> </div>
</template> </template>
<script> <script>
@ -41,20 +41,20 @@ export default {
} }
}, },
methods: { methods: {
/**
* @description: 此方法仅为演示使用 真正修改组件数据请判断data_type属性
* @param {*}
* @return {*}
*/
testF () { testF () {
// //
let anyCircuitBreakerList = this.svgLists.filter(f => f.type == 'CircuitBreakerSvg'); let anyCircuitBreakerList = this.svgLists.filter(f => f.type == 'CircuitBreakerSvg');
//线 //线
let anyWireBreakList = this.svgLists.filter(f => f.type == 'WireConnectionSvg' || f.type == 'WireBreakOffSvg'); let anyWireBreakList = this.svgLists.filter(f => f.type == 'WireBreakOnSvg' || f.type == 'WireBreakOffSvg');
// //
let anyTable = this.svgLists.filter(f => f.type == 'TableSvg')[0]; let anyEchartsPieList = this.svgLists.filter(f => f.type == 'EchartsPieSvg');
let anyTableList; //
if (anyTable == 'undefined' || anyTable == null) { let anyEchartsBasicBarSvgList = this.svgLists.filter(f => f.type == 'EchartsBasicBarSvg');
anyTableList = [];
}
else {
anyTableList = anyTable.tableData.map(m => m.cols);
}
this.analogDataTimer = setInterval(function () { this.analogDataTimer = setInterval(function () {
anyCircuitBreakerList.forEach(anyCircuitBreaker => { anyCircuitBreakerList.forEach(anyCircuitBreaker => {
// //
@ -70,23 +70,28 @@ export default {
// //
let random = Math.round(Math.random() * 10); let random = Math.round(Math.random() * 10);
if (random < 5) { if (random < 5) {
anyWireBreak.type = 'WireConnectionSvg'; anyWireBreak.type = 'WireBreakOnSvg';
anyWireBreak.svgColor = "#FF0000" anyWireBreak.svgColor = "#00FF00"
} }
else { else {
anyWireBreak.type = 'WireBreakOffSvg'; anyWireBreak.type = 'WireBreakOffSvg';
anyWireBreak.svgColor = "#FF0000"
} }
}); });
anyTableList.forEach(anyTables => { anyEchartsPieList.forEach(anyEchartsPie => {
anyTables.forEach(anyTable => { anyEchartsPie.echartsOption.series[0].data.forEach(f => {
if (anyTable.type == 'ff85bc7f-3b69-454f-8cf8-21c9f1903dd6' || anyTable.id == 'f8271273-d07d-4033-8b6c-6b52c04fe3e5' //
|| anyTable.id == 'dc5931bc-7e8e-47f4-b28e-5bc42fb207da' || anyTable.id == '560f5404-6539-422f-8fb9-77bac641e72b') { let random = Math.round(Math.random() * 100);
// f.value = random;
let random = Math.round(Math.random() * 100);
anyTable.val = random;
}
}); });
});
})
anyEchartsBasicBarSvgList.forEach(anyEchartsBasicBar => {
let data_arr=[Math.round(Math.random() * 300),Math.round(Math.random() * 300),Math.round(Math.random() * 300),Math.round(Math.random() * 300),Math.round(Math.random() * 300),Math.round(Math.random() * 300),Math.round(Math.random() * 300)];
anyEchartsBasicBar.echartsOption.series[0].data=data_arr;
})
}, 2000) }, 2000)
}, },
@ -96,12 +101,14 @@ export default {
}, },
created () { created () {
let _this = this; let _this = this;
_this.svgLists = JSON.parse(localStorage.getItem('svginfo'));
// //
this.$axios.get('/InterfaceReturn.json') this.$axios.get('/InterfaceReturn.json')
.then(function (response) { .then(function (response) {
_this.svgInfoData = response.data; _this.svgInfoData = response.data;
console.log(response.data); console.log(response.data);
//
_this.svgLists = JSON.parse(localStorage.getItem('svginfo'));
}) })
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);

Loading…
Cancel
Save