2020-01-03 17:17:09 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
|
.chartBox {
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
float:left;
|
2020-02-03 21:30:07 +08:00
|
|
|
|
padding: 0 10px 10px 10px;
|
2020-03-20 18:47:51 +08:00
|
|
|
|
/*position:relative;*/
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
.noData{
|
|
|
|
|
|
text-align: center
|
|
|
|
|
|
}
|
2020-01-10 17:13:41 +08:00
|
|
|
|
.list-width{
|
2020-03-04 21:27:41 +08:00
|
|
|
|
width: calc(100% - 14px);
|
2020-02-14 17:57:15 +08:00
|
|
|
|
overflow-x:hidden;/*避免鼠标第一次放到曲线时,x轴出现滚动条后消失*/
|
2020-01-10 17:13:41 +08:00
|
|
|
|
}
|
2020-03-28 09:57:51 +08:00
|
|
|
|
.drag-chart-class{
|
|
|
|
|
|
cursor:move !important;
|
|
|
|
|
|
/*
|
2020-03-25 09:21:23 +08:00
|
|
|
|
border:solid 2px yellow;
|
|
|
|
|
|
color:yellow;
|
2020-03-28 09:57:51 +08:00
|
|
|
|
background-color:yellow !important;
|
|
|
|
|
|
*/
|
2020-03-23 21:23:50 +08:00
|
|
|
|
/*background-color:red;
|
|
|
|
|
|
opacity:1*/
|
|
|
|
|
|
}
|
2020-03-28 09:57:51 +08:00
|
|
|
|
.choose-class{
|
|
|
|
|
|
cursor:move;
|
|
|
|
|
|
/* border:solid 2px purple;
|
2020-03-25 09:21:23 +08:00
|
|
|
|
color:purple;
|
|
|
|
|
|
background-color:purple;*/
|
|
|
|
|
|
}
|
2020-03-28 09:57:51 +08:00
|
|
|
|
.chosen-class .chartTitle{
|
2020-03-25 09:21:23 +08:00
|
|
|
|
}
|
2020-03-23 21:23:50 +08:00
|
|
|
|
.fallback-class{
|
2020-03-25 09:21:23 +08:00
|
|
|
|
cursor:move;
|
2020-03-23 21:23:50 +08:00
|
|
|
|
/*background-color:green;
|
|
|
|
|
|
cursor:pointer;*/
|
|
|
|
|
|
}
|
2020-03-28 09:57:51 +08:00
|
|
|
|
.chart-ghost {
|
|
|
|
|
|
/*
|
2020-03-25 09:21:23 +08:00
|
|
|
|
opacity: 1;
|
|
|
|
|
|
border:solid 2px green;
|
2020-03-28 09:57:51 +08:00
|
|
|
|
*/
|
2020-03-25 09:21:23 +08:00
|
|
|
|
}
|
2020-03-20 18:47:51 +08:00
|
|
|
|
|
2020-01-03 17:17:09 +08:00
|
|
|
|
</style>
|
|
|
|
|
|
<template>
|
|
|
|
|
|
|
2020-03-20 18:47:51 +08:00
|
|
|
|
<div class="list-width" id="listContainer"><!--v-drag-->
|
|
|
|
|
|
<!--
|
|
|
|
|
|
draggable="true"
|
|
|
|
|
|
@dragstart="handleDragStart($event, item)"
|
|
|
|
|
|
@dragover.prevent="handleDragOver($event, item)"
|
|
|
|
|
|
@dragenter="handleDragEnter($event, item)"
|
2020-03-28 09:57:51 +08:00
|
|
|
|
@dragend="handleDragEnd($event, item)"
|
|
|
|
|
|
@mousedown="dragPosition($event,item)"
|
|
|
|
|
|
<draggable v-model="dataList" @chang="change" @start="start" @end="end" :move="move" @choose="choose"
|
|
|
|
|
|
@add="add" @clone="clone" @update="update" @remove="remove" @sort="sort"
|
2020-03-25 09:21:23 +08:00
|
|
|
|
:scroll-sensitivity="150"
|
2020-03-23 21:23:50 +08:00
|
|
|
|
:options="{
|
2020-03-28 09:57:51 +08:00
|
|
|
|
group:{name:'chartGroup',pull:'false'},
|
|
|
|
|
|
dragClass:'drag-chart-class',
|
2020-03-25 09:21:23 +08:00
|
|
|
|
fallbackClass:'fallback-class',
|
|
|
|
|
|
forceFallback:true,
|
2020-03-28 09:57:51 +08:00
|
|
|
|
ghostClass:'chart-ghost',
|
|
|
|
|
|
chosenClass:'choose-class',
|
|
|
|
|
|
scroll:true,
|
|
|
|
|
|
scrollFn:function(offsetX,offsetY,originalEvent,touchEvt,hoverTargetEI){},
|
|
|
|
|
|
animation:150,
|
|
|
|
|
|
handle:'.chartTitle',
|
|
|
|
|
|
}" >@clone="clone"
|
|
|
|
|
|
-->
|
|
|
|
|
|
<draggable v-model="dataList" @chang="change" @start="start" @end="end" :move="move" @choose="choose"
|
|
|
|
|
|
@add="add" @update="update" @remove="remove" @sort="sort"
|
|
|
|
|
|
:scroll-sensitivity="150"
|
|
|
|
|
|
:options="{
|
|
|
|
|
|
group:{name:'chartGroup',pull:'false'},
|
|
|
|
|
|
dragClass:'drag-chart-class',
|
|
|
|
|
|
fallbackClass:'fallback-class',
|
|
|
|
|
|
forceFallback:true,
|
|
|
|
|
|
ghostClass:'chart-ghost',
|
|
|
|
|
|
chosenClass:'choose-class',
|
2020-03-25 09:21:23 +08:00
|
|
|
|
scroll:true,
|
|
|
|
|
|
scrollFn:function(offsetX,offsetY,originalEvent,touchEvt,hoverTargetEI){},
|
|
|
|
|
|
animation:150,
|
|
|
|
|
|
handle:'.chartTitle',
|
2020-03-23 21:23:50 +08:00
|
|
|
|
}" >
|
2020-03-28 09:57:51 +08:00
|
|
|
|
<div class="chartBox" v-for="(item, index) in dataList" :key="item.id" :id="item.title+'_'+item.id"
|
|
|
|
|
|
>
|
2020-03-20 18:47:51 +08:00
|
|
|
|
<line-chart-block v-if="item.type === 'line' || item.type === 'bar' ||item.type == 'stackArea' || item.type === 4" :key="'inner' + item.id"
|
|
|
|
|
|
ref="editChart"
|
|
|
|
|
|
@on-refresh-data="refreshChart"
|
|
|
|
|
|
@on-remove-chart-block="removeChart"
|
|
|
|
|
|
@on-drag-chart="editChartForDrag"
|
|
|
|
|
|
@on-edit-chart-block="editData"
|
|
|
|
|
|
:panel-id="filter.panelId"
|
|
|
|
|
|
:chart-index="index"
|
|
|
|
|
|
:editChartId="'editChartId' + item.id"></line-chart-block>
|
2020-01-03 17:17:09 +08:00
|
|
|
|
|
2020-03-20 18:47:51 +08:00
|
|
|
|
<chart-table v-if="item.type === 'table'" ref="editChart" :key="'inner' + item.id"
|
|
|
|
|
|
@on-refresh-data="refreshChart"
|
|
|
|
|
|
@on-search-data="searchData"
|
|
|
|
|
|
@on-remove-chart-block="removeChart"
|
|
|
|
|
|
@on-drag-chart="editChartForDrag"
|
|
|
|
|
|
@on-edit-chart-block="editData"
|
|
|
|
|
|
:panel-id="filter.panelId"
|
|
|
|
|
|
:chart-index="index"
|
|
|
|
|
|
:editChartId="'editChartId' + item.id"></chart-table>
|
2020-04-14 21:46:38 +08:00
|
|
|
|
|
|
|
|
|
|
<chart-url v-if="item.type === 'url'" ref="editChart" :key="'inner' + item.id"
|
|
|
|
|
|
@on-refresh-data="refreshChart"
|
|
|
|
|
|
@on-search-data="searchData"
|
|
|
|
|
|
@on-remove-chart-block="removeChart"
|
|
|
|
|
|
@on-drag-chart="editChartForDrag"
|
|
|
|
|
|
@on-edit-chart-block="editData"
|
|
|
|
|
|
:panel-id="filter.panelId"
|
|
|
|
|
|
:chart-index="index"
|
|
|
|
|
|
:editChartId="'editChartId' + item.id"></chart-url>
|
2020-03-20 18:47:51 +08:00
|
|
|
|
</div>
|
2020-03-28 09:57:51 +08:00
|
|
|
|
</draggable>
|
2020-01-03 17:17:09 +08:00
|
|
|
|
<el-row v-if="dataList.length === 0" class="noData"></el-row>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import axios from 'axios';
|
2020-01-08 16:44:41 +08:00
|
|
|
|
import bus from '../../libs/bus';
|
2020-01-03 17:17:09 +08:00
|
|
|
|
import lineChartBlock from './line-chart-block';
|
2020-01-07 17:12:48 +08:00
|
|
|
|
import chartTable from './chart-table';
|
2020-04-14 21:46:38 +08:00
|
|
|
|
import chartUrl from './chart-url';
|
2020-03-23 21:23:50 +08:00
|
|
|
|
import draggable from 'vuedraggable'
|
2020-01-03 17:17:09 +08:00
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: 'chartList',
|
|
|
|
|
|
props: {
|
|
|
|
|
|
},
|
|
|
|
|
|
components: {
|
|
|
|
|
|
lineChartBlock,
|
2020-01-07 17:12:48 +08:00
|
|
|
|
chartTable,
|
2020-04-14 21:46:38 +08:00
|
|
|
|
chartUrl,
|
2020-03-23 21:23:50 +08:00
|
|
|
|
draggable,
|
2020-01-03 17:17:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
filter: {},
|
|
|
|
|
|
dataList: [], // 看板中所有图表信息
|
2020-03-25 09:21:23 +08:00
|
|
|
|
//dataListDragTmp:[],
|
2020-01-03 17:17:09 +08:00
|
|
|
|
time: {
|
|
|
|
|
|
start: '',
|
|
|
|
|
|
end: '',
|
|
|
|
|
|
},
|
|
|
|
|
|
panelId: '',
|
|
|
|
|
|
timer: null,
|
2020-01-21 10:35:45 +08:00
|
|
|
|
dataTotalList:[],//懒加载:总记录数
|
|
|
|
|
|
isPage:true,//是否分页懒加载
|
|
|
|
|
|
currentRecordNum:0,//懒加载:本次取记录的index,第一次从0开始取,每次取3行
|
|
|
|
|
|
lineNum:3,//每页加载的行数
|
2020-03-20 18:47:51 +08:00
|
|
|
|
pagePanelId:'',//当前分页的panelId
|
|
|
|
|
|
dragging: null
|
2020-01-03 17:17:09 +08:00
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {},
|
|
|
|
|
|
watch: {},
|
|
|
|
|
|
methods: {
|
2020-03-20 18:47:51 +08:00
|
|
|
|
change (event) {
|
|
|
|
|
|
console.log('change', event)
|
|
|
|
|
|
},
|
|
|
|
|
|
start (event) {
|
2020-04-17 10:14:36 +08:00
|
|
|
|
console.log('start', event, this.dataList);
|
2020-03-25 09:21:23 +08:00
|
|
|
|
let item = event.item;
|
|
|
|
|
|
let chartTitle = item.querySelector('.chartTitle');
|
|
|
|
|
|
chartTitle.style.background = '#d8dce1';
|
|
|
|
|
|
console.log('start-title',chartTitle);
|
|
|
|
|
|
//this.dataListDragTmp = [...this.dataList];
|
2020-03-28 09:57:51 +08:00
|
|
|
|
let dragClass = document.querySelector('.drag-chart-class');//drag-chart-class:yellow chart-ghost:green fallback-class choose-class:purple
|
|
|
|
|
|
console.log('start---class', dragClass);
|
|
|
|
|
|
//dragClass.style.opacity = 1;
|
|
|
|
|
|
//dragClass.style.pointerEvents = 'auto';
|
|
|
|
|
|
/*
|
|
|
|
|
|
let canvas = item.querySelector('canvas');
|
|
|
|
|
|
console.log('start-canvas',canvas);
|
|
|
|
|
|
let canvasclone = event.clone.querySelector('canvas');
|
|
|
|
|
|
console.log('start-canvas-style',canvasclone.style);
|
|
|
|
|
|
canvasclone.style.border='solid 2px green !importmant';
|
|
|
|
|
|
console.log('start-canvas-style2',canvasclone.style);
|
|
|
|
|
|
if(canvas&&canvasclone) {
|
|
|
|
|
|
let ctx = canvas.getContext("2d");
|
|
|
|
|
|
let image = new Image();
|
|
|
|
|
|
image.src = canvas.toDataURL();
|
|
|
|
|
|
//var a = document.createElement("a");
|
|
|
|
|
|
//a.href=canvas.toDataURL();
|
|
|
|
|
|
//a.download="drcQrcode";
|
|
|
|
|
|
//a.click();
|
|
|
|
|
|
console.log('clone-image', image)
|
|
|
|
|
|
let ctxClone = canvasclone.getContext("2d");
|
|
|
|
|
|
image.onload = function () {
|
|
|
|
|
|
console.log('clone-image-load', image)
|
|
|
|
|
|
//ctxClone.drawImage(image, 0, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
2020-03-20 18:47:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
end (event) {
|
2020-03-25 09:21:23 +08:00
|
|
|
|
let item = event.item;
|
|
|
|
|
|
console.log('end', event, this.dataList);
|
|
|
|
|
|
/*
|
|
|
|
|
|
let len = this.dataListDragTmp.length;
|
|
|
|
|
|
let endIndex = len-1;
|
|
|
|
|
|
let oldIndex = event.oldIndex;
|
|
|
|
|
|
if(oldIndex===0){//挪动之前为第一个元素
|
|
|
|
|
|
let oldNextItem = this.dataListDragTmp[oldIndex+1];
|
|
|
|
|
|
let nextItem = this.dataList.find(item => item.id === oldNextItem.id);
|
|
|
|
|
|
nextItem.prev = 0;
|
|
|
|
|
|
}else if(oldIndex===endIndex){//挪动之前为最后一个元素
|
|
|
|
|
|
let oldPrevItem = this.dataListDragTmp[oldIndex-1];
|
|
|
|
|
|
let prevItem = this.dataList.find(item => item.id === oldPrevItem.id);
|
|
|
|
|
|
prevItem.next = -1;
|
|
|
|
|
|
}else{//挪动之前为中间元素
|
|
|
|
|
|
let oldPrevItem = this.dataListDragTmp[oldIndex-1];
|
|
|
|
|
|
let oldNextItem = this.dataListDragTmp[oldIndex+1];
|
|
|
|
|
|
let nextItem = this.dataList.find(item => item.id === oldNextItem.id);
|
|
|
|
|
|
let prevItem = this.dataList.find(item => item.id === oldPrevItem.id);
|
|
|
|
|
|
prevItem.next = oldNextItem.id;
|
|
|
|
|
|
nextItem.prev = oldPrevItem.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let newIndex = event.newIndex;
|
|
|
|
|
|
let newItem = this.dataList[newIndex];
|
|
|
|
|
|
if(newIndex===0){//挪动之后为第一个元素
|
|
|
|
|
|
let newNextItem = this.dataList[newIndex+1];
|
|
|
|
|
|
newNextItem.prev = newItem.id;
|
|
|
|
|
|
}else if(newIndex===endIndex){//挪动之后为最后一个元素
|
|
|
|
|
|
let newPrevItem = this.dataList[newIndex-1];
|
|
|
|
|
|
newPrevItem.next =newItem.id;
|
|
|
|
|
|
}else{//挪动之后为中间元素
|
|
|
|
|
|
let newPrevItem = this.dataList[newIndex-1];
|
|
|
|
|
|
let newNextItem = this.dataList[newIndex+1];
|
|
|
|
|
|
newPrevItem.next = newItem.id;
|
|
|
|
|
|
newNextItem.prev = newItem.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
let newIndex = event.newIndex;
|
|
|
|
|
|
let newItem = this.dataList[newIndex];
|
2020-03-28 09:57:51 +08:00
|
|
|
|
if(this.dataList.length===1){
|
|
|
|
|
|
newItem.prev = 0;
|
|
|
|
|
|
newItem.next = -1;
|
|
|
|
|
|
}else if(newIndex===0){//挪动之后为第一个元素
|
2020-03-25 09:21:23 +08:00
|
|
|
|
let newNextItem = this.dataList[newIndex+1];
|
|
|
|
|
|
newItem.prev = 0;
|
|
|
|
|
|
newItem.next = newNextItem.id;
|
|
|
|
|
|
}else if(newIndex===(this.dataList.length-1)){//挪动之后为最后一个元素
|
|
|
|
|
|
let newPrevItem = this.dataList[newIndex-1];
|
|
|
|
|
|
newItem.prev = newPrevItem.id;
|
|
|
|
|
|
newItem.next = -1;
|
|
|
|
|
|
}else{//挪动之后为中间元素
|
|
|
|
|
|
let newNextItem = this.dataList[newIndex+1];
|
|
|
|
|
|
let newPrevItem = this.dataList[newIndex-1];
|
|
|
|
|
|
newItem.prev = newPrevItem.id;
|
|
|
|
|
|
newItem.next = newNextItem.id;
|
|
|
|
|
|
}
|
|
|
|
|
|
//更新图表prev和next
|
|
|
|
|
|
const modifyParams = {
|
|
|
|
|
|
id:newItem.id,
|
|
|
|
|
|
span:newItem.span,
|
|
|
|
|
|
height:newItem.height,
|
|
|
|
|
|
prev:newItem.prev,
|
|
|
|
|
|
next:newItem.next,
|
2020-04-17 10:14:36 +08:00
|
|
|
|
};
|
2020-04-01 22:21:06 +08:00
|
|
|
|
if(this.dataList.length>1){
|
|
|
|
|
|
this.$put('panel/'+ this.pagePanelId+'/charts/modify',modifyParams).then(response => {
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
//let item = this.dataList.find(item => item.id === newItem.id);
|
2020-03-25 09:21:23 +08:00
|
|
|
|
}else {
|
2020-04-01 22:21:06 +08:00
|
|
|
|
if(response.msg){
|
|
|
|
|
|
this.$message.error(response.msg);
|
|
|
|
|
|
}else if(response.error){
|
|
|
|
|
|
this.$message.error(response.error);
|
|
|
|
|
|
}else {
|
|
|
|
|
|
this.$message.error(response);
|
|
|
|
|
|
}
|
2020-03-25 09:21:23 +08:00
|
|
|
|
}
|
2020-04-01 22:21:06 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2020-03-28 09:57:51 +08:00
|
|
|
|
|
|
|
|
|
|
let chartTitle = item.querySelector('.chartTitle');
|
|
|
|
|
|
chartTitle.style.background = '';
|
2020-03-20 18:47:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
move (event, orgin) {
|
2020-03-28 09:57:51 +08:00
|
|
|
|
console.log('move', event, orgin);
|
|
|
|
|
|
let dragClass = document.querySelector('.drag-chart-class');//drag-chart-class:yellow chart-ghost:green fallback-class choose-class:purple
|
|
|
|
|
|
console.log('move---class', dragClass);
|
|
|
|
|
|
//dragClass.style.opacity = 1;
|
|
|
|
|
|
//dragClass.style.pointerEvents = 'auto';//设置此属性,end事件里newIndex为 列表长度
|
|
|
|
|
|
|
|
|
|
|
|
let chartTitle = dragClass.querySelector('.chartTitle');
|
|
|
|
|
|
console.log('move-title',chartTitle);
|
|
|
|
|
|
chartTitle.style.background = '#d8dce1';
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
choose(event ){
|
|
|
|
|
|
console.log('choose', event);
|
|
|
|
|
|
let chartTitle = event.item.querySelector('.chartTitle');
|
2020-04-01 22:21:06 +08:00
|
|
|
|
//console.log('choose-title',chartTitle);
|
|
|
|
|
|
//chartTitle.style.background = '#d8dce1';
|
2020-03-28 09:57:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
clone(event){
|
|
|
|
|
|
console.log('clone',event );
|
|
|
|
|
|
let canvas = event.item.querySelector('canvas');
|
|
|
|
|
|
console.log('clone-canvas',canvas);
|
|
|
|
|
|
let canvasclone = event.clone.querySelector('canvas');
|
|
|
|
|
|
canvasclone.style.border='solid 1px yellow';
|
|
|
|
|
|
console.log('clone-canvasclone',canvasclone);
|
|
|
|
|
|
if(canvas&&canvasclone){
|
|
|
|
|
|
let ctx = canvas.getContext("2d");
|
|
|
|
|
|
let image = new Image();
|
|
|
|
|
|
image.src= canvas.toDataURL();
|
|
|
|
|
|
/*var a = document.createElement("a");
|
|
|
|
|
|
a.href=canvas.toDataURL();
|
|
|
|
|
|
a.download="drcQrcode";
|
|
|
|
|
|
a.click();*/
|
2020-04-17 10:14:36 +08:00
|
|
|
|
console.log('clone-image',image);
|
2020-03-28 09:57:51 +08:00
|
|
|
|
let ctxClone = canvasclone.getContext("2d");
|
|
|
|
|
|
//ctxClone.drawImage(image,0,0);
|
|
|
|
|
|
image.onload = function(){
|
2020-04-17 10:14:36 +08:00
|
|
|
|
console.log('clone-image-load',image);
|
2020-03-28 09:57:51 +08:00
|
|
|
|
ctxClone.drawImage(image,0,0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
add(event){
|
|
|
|
|
|
console.log('add',event );
|
|
|
|
|
|
},
|
|
|
|
|
|
update(event){
|
|
|
|
|
|
console.log('update',event );
|
|
|
|
|
|
},
|
|
|
|
|
|
remove(event){
|
|
|
|
|
|
console.log('remove',event );
|
|
|
|
|
|
},
|
|
|
|
|
|
sort(event){
|
|
|
|
|
|
console.log('sort',event );
|
|
|
|
|
|
},
|
|
|
|
|
|
dragPosition:function(e){
|
|
|
|
|
|
console.log('===',e.clientY,e.clientX);
|
|
|
|
|
|
let odiv=e;//目标元素e.target
|
|
|
|
|
|
console.log('odiv====',odiv);
|
|
|
|
|
|
//var targetDiv= document.getElementById('lineChartDiv'+this.chartIndex); //
|
|
|
|
|
|
//得到点击时该容器的:
|
|
|
|
|
|
var startY=e.clientY;
|
|
|
|
|
|
var startX=e.clientX;
|
|
|
|
|
|
var _this=this;
|
|
|
|
|
|
//鼠标相对元素的位置
|
|
|
|
|
|
var distY=e.clientY-odiv.offsetLeft;
|
|
|
|
|
|
var distX=e.clientX-odiv.offsetTop;
|
|
|
|
|
|
document.onmousemove=function(e){
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
console.log('===onmousemove',e.clientY,e.clientX);
|
|
|
|
|
|
//e.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
// var distY=Math.abs(e.clientY-startY);
|
|
|
|
|
|
// var distX=Math.abs(e.clientX-startX);
|
|
|
|
|
|
let left=e.clientX-distX;
|
|
|
|
|
|
let top=e.clientY-distY;
|
|
|
|
|
|
odiv.style.top=top+'px';
|
|
|
|
|
|
odiv.style.left=left+'px';
|
|
|
|
|
|
console.log('odiv====',odiv);
|
|
|
|
|
|
/*
|
|
|
|
|
|
//往上方拖动:
|
|
|
|
|
|
if( e.clientY < startY){
|
|
|
|
|
|
targetDiv.style.top=(startY-distY)+'px';
|
|
|
|
|
|
}
|
|
|
|
|
|
if( e.clientX < startX){
|
|
|
|
|
|
targetDiv.style.left=(startX-distX)+'px';
|
|
|
|
|
|
}
|
|
|
|
|
|
//往下方拖动:
|
|
|
|
|
|
if (e.clientY > startY) {
|
|
|
|
|
|
targetDiv.style.top=(startY+distY)+'px';
|
|
|
|
|
|
}
|
|
|
|
|
|
if (e.clientX > startX) {
|
|
|
|
|
|
targetDiv.style.left=(startX+distX)+'px';
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
2020-04-17 10:14:36 +08:00
|
|
|
|
};
|
2020-03-28 09:57:51 +08:00
|
|
|
|
|
|
|
|
|
|
document.onmouseup=function(){
|
|
|
|
|
|
document.onmousemove=null;
|
|
|
|
|
|
document.onmouseup = null;
|
|
|
|
|
|
}
|
2020-03-20 18:47:51 +08:00
|
|
|
|
},
|
|
|
|
|
|
handleDragStart(e,item){
|
|
|
|
|
|
this.dragging = item;
|
|
|
|
|
|
},
|
|
|
|
|
|
handleDragEnd(e,item){
|
|
|
|
|
|
this.dragging = null
|
|
|
|
|
|
},
|
|
|
|
|
|
//首先把div变成可以放置的元素,即重写dragenter/dragover
|
|
|
|
|
|
handleDragOver(e) {
|
|
|
|
|
|
e.dataTransfer.dropEffect = 'move'// e.dataTransfer.dropEffect="move";//在dragenter中针对放置目标来设置!
|
|
|
|
|
|
},
|
|
|
|
|
|
handleDragEnter(e,item){
|
2020-04-17 10:14:36 +08:00
|
|
|
|
e.dataTransfer.effectAllowed = "move";//为需要移动的元素设置dragstart事件
|
2020-03-20 18:47:51 +08:00
|
|
|
|
if(item === this.dragging){
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2020-04-17 10:14:36 +08:00
|
|
|
|
const newItems = [...this.dataList];
|
|
|
|
|
|
console.log(newItems);
|
|
|
|
|
|
const src = newItems.indexOf(this.dragging);
|
|
|
|
|
|
const dst = newItems.indexOf(item);
|
2020-03-20 18:47:51 +08:00
|
|
|
|
|
2020-04-17 10:14:36 +08:00
|
|
|
|
newItems.splice(dst, 0, ...newItems.splice(src, 1));
|
2020-03-20 18:47:51 +08:00
|
|
|
|
|
|
|
|
|
|
this.dataList = newItems
|
|
|
|
|
|
},
|
2020-01-21 10:35:45 +08:00
|
|
|
|
initCurrentRecordNum(){
|
|
|
|
|
|
this.currentRecordNum = 0;
|
|
|
|
|
|
},
|
|
|
|
|
|
cleanData(){
|
|
|
|
|
|
if (this.dataList.length > 0 && this.$refs.editChart) {
|
|
|
|
|
|
this.$refs.editChart.forEach((item) => {
|
|
|
|
|
|
item.clearData();
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
this.dataList = [];
|
|
|
|
|
|
},
|
2020-01-03 17:17:09 +08:00
|
|
|
|
initData(filter) {
|
|
|
|
|
|
this.dataList = [];
|
|
|
|
|
|
// 内含 panelId,开始时间,结束时间
|
|
|
|
|
|
this.filter = filter;
|
2020-01-21 10:35:45 +08:00
|
|
|
|
this.pagePanelId = this.filter.panelId;
|
2020-01-03 17:17:09 +08:00
|
|
|
|
this.getData(this.filter);
|
|
|
|
|
|
},
|
2020-01-21 10:35:45 +08:00
|
|
|
|
pageDataList(isAdd,panelId){
|
|
|
|
|
|
if(panelId!==this.pagePanelId){
|
|
|
|
|
|
this.currentRecordNum = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(this.dataTotalList && this.dataTotalList.length>0){
|
|
|
|
|
|
if(this.currentRecordNum>=this.dataTotalList.length){
|
|
|
|
|
|
//alert('数据加载完毕!');
|
|
|
|
|
|
}else {
|
|
|
|
|
|
let dataTmpList = [];
|
|
|
|
|
|
let spanSum = 0;
|
|
|
|
|
|
let line = 0;//行数
|
|
|
|
|
|
let isDataFull=false;
|
|
|
|
|
|
let curRecNum = this.currentRecordNum;
|
|
|
|
|
|
let len = this.dataTotalList.length;
|
|
|
|
|
|
for(let i=curRecNum;!isDataFull && i<len;i++){
|
|
|
|
|
|
if(line<this.lineNum){
|
|
|
|
|
|
let item = this.dataTotalList[i];
|
|
|
|
|
|
let span = item.span;
|
|
|
|
|
|
let sumTmp = spanSum+span;
|
|
|
|
|
|
if(sumTmp<=12){
|
|
|
|
|
|
spanSum =sumTmp;
|
|
|
|
|
|
}else{//大于12表示够1行了,
|
|
|
|
|
|
line = line +1;
|
|
|
|
|
|
spanSum = span;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(line<this.lineNum){
|
|
|
|
|
|
dataTmpList.push(item);
|
|
|
|
|
|
this.currentRecordNum = i+1;
|
|
|
|
|
|
}else{
|
2020-04-17 10:14:36 +08:00
|
|
|
|
this.currentRecordNum = i;
|
2020-01-21 10:35:45 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}else {//数据加载够了
|
|
|
|
|
|
isDataFull=true;
|
|
|
|
|
|
this.currentRecordNum = i;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(isAdd){
|
|
|
|
|
|
let oldDataListLen = this.dataList.length;
|
|
|
|
|
|
let dataListTmp = this.dataList;
|
|
|
|
|
|
this.dataList = dataListTmp.concat(dataTmpList);
|
|
|
|
|
|
this.dataSetFirst(dataTmpList,oldDataListLen);
|
|
|
|
|
|
}else {
|
|
|
|
|
|
this.dataList = dataTmpList;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2020-01-03 17:17:09 +08:00
|
|
|
|
// 获取panel详情数据,获取panel下所有chart列表
|
|
|
|
|
|
getData(params) {
|
|
|
|
|
|
//param 目前没有用
|
|
|
|
|
|
const param = {
|
|
|
|
|
|
panelId: params.panelId,
|
|
|
|
|
|
query: params.query,
|
|
|
|
|
|
};
|
|
|
|
|
|
if (!param.query) delete param.query;
|
|
|
|
|
|
//根据panelId获得panel下的所有图表
|
2020-01-08 16:44:41 +08:00
|
|
|
|
let searchTitleStr = '';
|
|
|
|
|
|
if(this.filter.searchName&&this.filter.searchName!=''){
|
|
|
|
|
|
searchTitleStr = '?title='+this.filter.searchName;
|
|
|
|
|
|
}
|
|
|
|
|
|
this.$get('panel/'+ params.panelId+'/charts'+searchTitleStr).then(response => {
|
2020-01-03 17:17:09 +08:00
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
if(response.data.list){
|
2020-01-21 10:35:45 +08:00
|
|
|
|
this.dataTotalList = response.data.list;
|
|
|
|
|
|
}else {
|
|
|
|
|
|
this.dataTotalList = response.data;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(this.isPage){
|
|
|
|
|
|
this.pageDataList();
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}else {
|
2020-01-21 10:35:45 +08:00
|
|
|
|
this.dataList = this.dataTotalList;
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}
|
2020-04-14 21:46:38 +08:00
|
|
|
|
console.log('0000==========',this.dataList);
|
2020-02-19 21:33:54 +08:00
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
if (this.dataList.length > 0 && this.$refs.editChart) {
|
|
|
|
|
|
this.$refs.editChart.forEach((item, i) => {
|
|
|
|
|
|
item.showLoad(this.dataList[i]);//之后要实现
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2020-01-03 17:17:09 +08:00
|
|
|
|
this.dataSetFirst(this.dataList);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
// arr: 该panel下图表list,生成该看板下所有图表
|
2020-01-21 10:35:45 +08:00
|
|
|
|
dataSetFirst(arr,oldDataListLen) {
|
2020-01-03 17:17:09 +08:00
|
|
|
|
if (arr.length) {
|
|
|
|
|
|
arr.forEach((item, index) => {
|
2020-01-21 10:35:45 +08:00
|
|
|
|
let realIndex = index;
|
|
|
|
|
|
if(oldDataListLen){
|
|
|
|
|
|
realIndex += oldDataListLen;
|
|
|
|
|
|
}
|
2020-04-14 21:46:38 +08:00
|
|
|
|
let chartType = item.type;
|
|
|
|
|
|
if(chartType!=='url'){
|
|
|
|
|
|
this.getChartData(item, realIndex);
|
|
|
|
|
|
}else {
|
|
|
|
|
|
this.setSize(item.span, realIndex); // 设置该图表宽度
|
|
|
|
|
|
}
|
2020-01-03 17:17:09 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 获取一个图表具体数据,图表信息,图表位置index
|
|
|
|
|
|
getChartData(chartInfo, pos, filterType) {
|
2020-01-06 17:10:57 +08:00
|
|
|
|
//alert(JSON.stringify(chartInfo));
|
2020-01-03 17:17:09 +08:00
|
|
|
|
const chartItem = chartInfo;
|
|
|
|
|
|
const index = pos; // 指标
|
|
|
|
|
|
const len = chartItem.elements.length;
|
2020-01-06 17:10:57 +08:00
|
|
|
|
this.setSize(chartItem.span, index); // 设置该图表宽度
|
2020-01-03 17:17:09 +08:00
|
|
|
|
// 没有数据的设置提示信息暂无数据-针对每一个图
|
|
|
|
|
|
if (len === 0) {
|
|
|
|
|
|
this.$nextTick(() => {
|
2020-02-22 18:44:01 +08:00
|
|
|
|
if(this.$refs.editChart[index]){
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, [], this.filter.panelId, this.filter);//????怎么设置的无数据??
|
|
|
|
|
|
}
|
2020-01-03 17:17:09 +08:00
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
let startTime = '';
|
|
|
|
|
|
let endTime = '';
|
2020-01-08 16:44:41 +08:00
|
|
|
|
if (filterType === 'refresh') {//刷新
|
2020-01-03 17:17:09 +08:00
|
|
|
|
const now = new Date();
|
|
|
|
|
|
const origin = new Date(this.filter.end_time);
|
|
|
|
|
|
const numInterval = now.getTime() - origin.getTime();
|
2020-01-08 16:44:41 +08:00
|
|
|
|
if (numInterval >= 60000) {//大于1分钟,则start、end均往后移numInterval,否则时间不变
|
2020-01-03 17:17:09 +08:00
|
|
|
|
startTime = this.getNewTime(this.filter.start_time, numInterval);
|
2020-01-08 16:44:41 +08:00
|
|
|
|
endTime = bus.timeFormate(now, 'yyyy-MM-dd hh:mm:ss');
|
2020-01-03 17:17:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
startTime = this.filter.start_time;
|
|
|
|
|
|
endTime = this.filter.end_time;
|
|
|
|
|
|
}
|
2020-02-19 21:33:54 +08:00
|
|
|
|
} else if(filterType==='showFullScreen'){//全屏时间查询
|
2020-01-16 16:56:28 +08:00
|
|
|
|
startTime = this.filter.start_time;
|
|
|
|
|
|
endTime = this.filter.end_time;
|
2020-02-19 21:33:54 +08:00
|
|
|
|
//this.$parent.refreshTime(startTime,endTime);全屏查询,不更新panel列表的时间条件
|
2020-01-16 16:56:28 +08:00
|
|
|
|
}else {
|
2020-01-08 16:44:41 +08:00
|
|
|
|
startTime = this.filter.start_time;
|
|
|
|
|
|
endTime = this.filter.end_time;
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}
|
2020-01-10 17:13:41 +08:00
|
|
|
|
let step = bus.getStep(startTime,endTime);
|
2020-01-03 17:17:09 +08:00
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
const axiosArr = chartItem.elements.map((ele) => {
|
|
|
|
|
|
const filterItem = ele;
|
2020-04-17 10:14:36 +08:00
|
|
|
|
let query = encodeURIComponent(filterItem.expression);
|
|
|
|
|
|
return this.$get('/prom/api/v1/query_range?query='+query+"&start="+startTime+"&end="+endTime+'&step='+step);
|
2020-01-03 17:17:09 +08:00
|
|
|
|
});
|
|
|
|
|
|
// 一个图表的所有element单独获取数据
|
|
|
|
|
|
axios.all(axiosArr).then((res) => {
|
|
|
|
|
|
if (res.length > 0) {
|
|
|
|
|
|
const series = [];
|
|
|
|
|
|
const legend = [];
|
|
|
|
|
|
const tableData = [];
|
|
|
|
|
|
const sumData = {
|
|
|
|
|
|
name: 'sum',
|
|
|
|
|
|
data: [],
|
|
|
|
|
|
visible: true,
|
|
|
|
|
|
threshold: null,
|
|
|
|
|
|
};
|
|
|
|
|
|
res.forEach((response, innerPos) => {
|
|
|
|
|
|
if (response.status === 'success') {
|
|
|
|
|
|
if (response.data.result) {
|
2020-03-04 09:58:19 +08:00
|
|
|
|
// console.log(response.data.result)
|
2020-01-03 17:17:09 +08:00
|
|
|
|
// 循环处理每个elements下获取的数据列
|
|
|
|
|
|
response.data.result.forEach((queryItem) => {
|
|
|
|
|
|
const seriesItem = {
|
|
|
|
|
|
theData: {
|
|
|
|
|
|
name: '',
|
2020-01-14 21:20:30 +08:00
|
|
|
|
symbol:'none', //去掉点
|
|
|
|
|
|
smooth:true, //曲线变平滑
|
2020-01-03 17:17:09 +08:00
|
|
|
|
data: [],
|
|
|
|
|
|
type:chartInfo.type,
|
|
|
|
|
|
//visible: true,
|
|
|
|
|
|
//threshold: null,
|
|
|
|
|
|
},
|
|
|
|
|
|
metric_name: '',
|
|
|
|
|
|
};
|
2020-03-12 17:41:04 +08:00
|
|
|
|
if(chartInfo.type === 'stackArea'){
|
|
|
|
|
|
seriesItem.theData.type='line';
|
2020-04-17 10:14:36 +08:00
|
|
|
|
seriesItem.theData.stack=chartInfo.title;
|
2020-03-12 17:41:04 +08:00
|
|
|
|
seriesItem.theData.areaStyle={};
|
|
|
|
|
|
}
|
2020-01-03 17:17:09 +08:00
|
|
|
|
// 图表中每条线的名字,后半部分
|
2020-01-19 10:07:34 +08:00
|
|
|
|
let host = '';//up,
|
|
|
|
|
|
if(queryItem.metric.__name__){
|
|
|
|
|
|
host = `${queryItem.metric.__name__}{`;//up,
|
|
|
|
|
|
}
|
2020-01-03 17:17:09 +08:00
|
|
|
|
const tagsArr = Object.keys(queryItem.metric);//["__name__","asset","idc","instance","job","module","project"]
|
|
|
|
|
|
// 设置时间-数据格式对
|
|
|
|
|
|
const dpsArr = Object.entries(queryItem.values);//[ ["0",[1577959830.781,"0"]], ["1",[1577959845.781,"0"]] ]
|
2020-04-17 08:15:13 +08:00
|
|
|
|
// 判断是否有数据, && tagsArr.length > 0
|
|
|
|
|
|
if (dpsArr.length > 0 && this.$refs.editChart[index]) {
|
2020-01-03 17:17:09 +08:00
|
|
|
|
tagsArr.forEach((tag, i) => {
|
|
|
|
|
|
if (tag !== '__name__') {
|
2020-01-09 17:02:33 +08:00
|
|
|
|
host += `${tag}="${queryItem.metric[tag]}",`;
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if(host.endsWith(',')){host = host.substr(0,host.length-1);}
|
2020-04-17 08:15:13 +08:00
|
|
|
|
if(queryItem.metric.__name__){
|
|
|
|
|
|
host +="}";
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!host || host===''){
|
|
|
|
|
|
host = chartItem.elements[innerPos].expression;
|
|
|
|
|
|
}
|
2020-03-04 09:58:19 +08:00
|
|
|
|
//处理legend别名
|
2020-03-12 14:10:37 +08:00
|
|
|
|
let alias=this.$refs.editChart[index].dealLegendAlias(host,chartItem.elements[innerPos].legend);
|
2020-04-17 08:15:13 +08:00
|
|
|
|
if(!alias || alias===''){
|
|
|
|
|
|
alias = chartItem.elements[innerPos].expression;
|
|
|
|
|
|
}
|
2020-03-04 09:58:19 +08:00
|
|
|
|
legend.push({name:host,alias:alias});
|
2020-01-03 17:17:09 +08:00
|
|
|
|
// 图表中每条线的名字,去掉最后的逗号与空格:metric名称, 标签1=a,标签2=c
|
|
|
|
|
|
seriesItem.theData.name = host;
|
|
|
|
|
|
seriesItem.metric_name = seriesItem.theData.name;
|
|
|
|
|
|
// 将秒改为毫秒
|
2020-01-07 17:12:48 +08:00
|
|
|
|
//alert('table=='+JSON.stringify(queryItem))
|
2020-01-03 17:17:09 +08:00
|
|
|
|
seriesItem.theData.data = queryItem.values.map((dpsItem, dpsIndex) => {
|
|
|
|
|
|
/*曲线汇总暂不需要
|
|
|
|
|
|
if (sumData.data[dpsIndex]) {
|
|
|
|
|
|
const sumNum = sumData.data[dpsIndex][1] || 0;
|
|
|
|
|
|
sumData.data[dpsIndex][1] = sumNum + dpsItem[1];
|
|
|
|
|
|
} else {
|
|
|
|
|
|
sumData.data[dpsIndex] = [dpsItem[0] * 1000, dpsItem[1]];
|
|
|
|
|
|
}
|
|
|
|
|
|
*/
|
2020-01-07 17:12:48 +08:00
|
|
|
|
let t_date = new Date(dpsItem[0] * 1000);
|
2020-02-17 19:37:06 +08:00
|
|
|
|
let timeTmp = bus.timeFormate(t_date, 'yyyy-MM-dd hh:mm:ss');
|
2020-01-07 17:12:48 +08:00
|
|
|
|
tableData.push({//表格数据
|
2020-03-04 20:30:25 +08:00
|
|
|
|
// label: host.slice(host.indexOf('{') + 1,host.indexOf('}')),//label
|
|
|
|
|
|
// metric: queryItem.metric.__name__?queryItem.metric.__name__:'',//metric列
|
|
|
|
|
|
element:{element:host,alias:alias},
|
2020-01-07 17:12:48 +08:00
|
|
|
|
time: timeTmp,//采集时间
|
|
|
|
|
|
value: dpsItem[1],//数值
|
|
|
|
|
|
});
|
2020-01-03 17:17:09 +08:00
|
|
|
|
return [dpsItem[0] * 1000, dpsItem[1]];
|
|
|
|
|
|
});
|
|
|
|
|
|
series.push(seriesItem.theData);
|
2020-01-07 17:12:48 +08:00
|
|
|
|
|
2020-01-03 17:17:09 +08:00
|
|
|
|
} else if (chartItem.elements && chartItem.elements[innerPos]) {
|
|
|
|
|
|
// 无数据提示
|
|
|
|
|
|
/*
|
|
|
|
|
|
const currentInfo = chartItem.elements[innerPos];
|
|
|
|
|
|
const errorMsg = `图表 ${chartItem.title} 中 ${currentInfo.metric},${currentInfo.tags} 无数据`;
|
|
|
|
|
|
this.$message.warning({
|
|
|
|
|
|
duration: 15,
|
|
|
|
|
|
content: errorMsg,
|
|
|
|
|
|
closable: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2020-01-13 09:07:35 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
if(response.msg){
|
|
|
|
|
|
this.$message.error(response.msg);
|
2020-02-17 10:32:31 +08:00
|
|
|
|
}else if(response.error){
|
|
|
|
|
|
this.$message.error(response.error);
|
2020-01-13 09:07:35 +08:00
|
|
|
|
}else {
|
|
|
|
|
|
this.$message.error(response);
|
|
|
|
|
|
}
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2020-03-10 22:40:45 +08:00
|
|
|
|
if(this.$refs.editChart&&this.$refs.editChart[index]) {
|
2020-02-22 18:44:01 +08:00
|
|
|
|
if (chartItem.type === 'table') {//表格
|
|
|
|
|
|
if (filterType === 'showFullScreen') {//table的全屏查询
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, tableData,
|
|
|
|
|
|
this.filter.panelId, this.filter, filterType);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, tableData,
|
|
|
|
|
|
this.filter.panelId, this.filter);
|
|
|
|
|
|
}
|
2020-03-10 22:40:45 +08:00
|
|
|
|
} else if (chartItem.type === 'line' || chartItem.type === 'bar' || chartItem.type === 'stackArea' || chartItem.type === 4) {
|
2020-02-22 18:44:01 +08:00
|
|
|
|
if (series.length && chartItem.type === 4) {//曲线汇总
|
|
|
|
|
|
//series.push(sumData);//后续需要
|
|
|
|
|
|
}
|
|
|
|
|
|
if (filterType === 'showFullScreen') {//table的全屏查询
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, series,
|
|
|
|
|
|
this.filter.panelId, this.filter, legend, filterType);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, series,
|
|
|
|
|
|
this.filter.panelId, this.filter, legend);
|
|
|
|
|
|
}
|
2020-02-19 21:33:54 +08:00
|
|
|
|
}
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const type = chartItem.type;
|
2020-02-22 18:44:01 +08:00
|
|
|
|
if(this.$refs.editChart[index]) {
|
|
|
|
|
|
if (type === 'table') {
|
|
|
|
|
|
if (filterType === 'showFullScreen') {//table的全屏查询
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, [], this.filter.panelId,
|
|
|
|
|
|
this.filter, filterType);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, [], this.filter.panelId,
|
|
|
|
|
|
this.filter);
|
|
|
|
|
|
}
|
2020-03-10 22:40:45 +08:00
|
|
|
|
} else if (type === 'line' || type === 'bar' || type === 'stackArea' || chartItem.type === 4) {
|
2020-02-22 18:44:01 +08:00
|
|
|
|
if (filterType === 'showFullScreen') {//table的全屏查询
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, [], this.filter.panelId,
|
|
|
|
|
|
this.filter, filterType);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$refs.editChart[index].setData(chartItem, [], this.filter.panelId,
|
|
|
|
|
|
this.filter);
|
|
|
|
|
|
}
|
2020-02-19 21:33:54 +08:00
|
|
|
|
}
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
|
if (error) {
|
2020-02-21 22:01:33 +08:00
|
|
|
|
this.$message.error(error.toString());
|
2020-03-04 20:30:25 +08:00
|
|
|
|
console.error(error)
|
2020-01-03 17:17:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 设置图表的宽度
|
2020-01-06 17:10:57 +08:00
|
|
|
|
setSize(size, index) {
|
2020-01-03 17:17:09 +08:00
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
const chartBox = document.getElementsByClassName('chartBox');
|
|
|
|
|
|
chartBox[index].style.width = `${(size / 12) * 100}%`;
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
getNewTime(time, num) {
|
|
|
|
|
|
const date = new Date(time);
|
|
|
|
|
|
const newDate = new Date(parseInt(date.getTime(), 10) + num);
|
2020-01-08 16:44:41 +08:00
|
|
|
|
return bus.timeFormate(newDate, 'yyyy-MM-dd hh:mm:ss');
|
2020-01-03 17:17:09 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 删除图表
|
2020-03-09 08:41:21 +08:00
|
|
|
|
removeChart(chartId) { //from 区分从哪里点击的删除 1.从图表面板 2.从编辑框
|
2020-01-03 17:17:09 +08:00
|
|
|
|
const chart = this.dataList.find(item => item.id === chartId);
|
|
|
|
|
|
if (chart) {
|
2020-01-06 17:10:57 +08:00
|
|
|
|
this.$emit('on-remove-chart', chart);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
// 编辑图表
|
|
|
|
|
|
editData(chartId) {
|
|
|
|
|
|
// 获取该id下chart的相关信息
|
|
|
|
|
|
const chart = this.dataList.find(item => item.id === chartId);
|
|
|
|
|
|
if (chart) {
|
|
|
|
|
|
this.$emit('on-edit-chart', chart);
|
|
|
|
|
|
}
|
2020-01-03 17:17:09 +08:00
|
|
|
|
},
|
2020-03-20 18:47:51 +08:00
|
|
|
|
|
|
|
|
|
|
editChartForDrag(chartItem){
|
|
|
|
|
|
let chart = this.dataList.find(item => item.id === chartItem.id);
|
|
|
|
|
|
chart.span = chartItem.span;
|
|
|
|
|
|
chart.height = chartItem.height;
|
|
|
|
|
|
},
|
2020-01-03 17:17:09 +08:00
|
|
|
|
// 刷新列表中的一个图表
|
2020-01-16 16:56:28 +08:00
|
|
|
|
refreshChart(chartId,searchTime) {
|
2020-01-03 17:17:09 +08:00
|
|
|
|
this.dataList.forEach((item, index) => {
|
|
|
|
|
|
if (item.id === chartId) {
|
|
|
|
|
|
this.getChartData(item, index, 'refresh');
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2020-01-16 16:56:28 +08:00
|
|
|
|
searchData(chartId,searchTime){
|
|
|
|
|
|
if(searchTime){//全屏时间查询
|
|
|
|
|
|
this.filter.start_time=bus.timeFormate(searchTime[0], 'yyyy-MM-dd hh:mm:ss');
|
|
|
|
|
|
this.filter.end_time=bus.timeFormate(searchTime[1], 'yyyy-MM-dd hh:mm:ss');
|
|
|
|
|
|
}
|
|
|
|
|
|
this.dataList.forEach((item, index) => {
|
|
|
|
|
|
if (item.id === chartId) {
|
2020-02-19 21:33:54 +08:00
|
|
|
|
this.getChartData(item, index, 'showFullScreen');
|
2020-01-16 16:56:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2020-01-08 16:44:41 +08:00
|
|
|
|
/*
|
2020-01-03 17:17:09 +08:00
|
|
|
|
// 刷新数据
|
|
|
|
|
|
refreshData() {
|
|
|
|
|
|
this.getData(this.filter);
|
|
|
|
|
|
},
|
|
|
|
|
|
*/
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
|
|
},
|
|
|
|
|
|
beforeDestroy() {
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|