This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nezha-fronted/nezha-fronted/src/components/common/project/meta2d/js/meta2dMain.js

368 lines
11 KiB
JavaScript
Raw Normal View History

2023-02-16 16:33:20 +08:00
import { Meta2d, registerNode } from '@meta2d/core'
import { flowPens } from '@meta2d/flow-diagram'
import { activityDiagram } from '@meta2d/activity-diagram'
import { classPens } from '@meta2d/class-diagram'
import { sequencePens, sequencePensbyCtx } from '@meta2d/sequence-diagram'
// import { chartsPens } from '@meta2d/le5le-charts'
import {
Tools,
canvasRegister,
imageTemp,
onChangeAnimate,
onChangeAnimateLine,
myCubec,
myCubeAnchors
} from '../../L5/services/canvas.js'
import { getTopology, setTopology, dealImg, topologyImg } from '@/components/common/js/common'
2023-02-20 19:11:10 +08:00
import bus from '@/libs/bus'
2023-02-21 19:05:49 +08:00
import topoUtil from '@/components/common/project/meta2d/js/topoUtil'
2023-02-16 16:33:20 +08:00
export default {
data () {
return {
selectPens: [],
editFlag: false,
2023-02-20 14:25:09 +08:00
prevFlag: false,
2023-02-22 15:29:17 +08:00
meta2dLoading: true,
position: {
top: 50,
2023-02-22 18:21:39 +08:00
left: 0,
show: false
2023-02-22 15:29:17 +08:00
},
2023-02-22 18:21:39 +08:00
timer3: null,
2023-02-22 15:29:17 +08:00
chartParams: {
chartType: 'line',
content: '',
legends: [],
title: '',
2023-02-22 18:21:39 +08:00
titleShow: true
},
contextmenu: {
left: null,
top: null,
bottom: null
},
setContextmenu: true
2023-02-16 16:33:20 +08:00
}
},
2023-02-21 19:05:49 +08:00
mixins: [topoUtil],
2023-02-16 16:33:20 +08:00
methods: {
init: function () {
2023-02-21 19:05:49 +08:00
const meta2dOptions = {
minScale: 0.25,
maxScale: 2
}
2023-02-16 16:33:20 +08:00
const meta2d = new Meta2d(this.meta2dId, meta2dOptions)
meta2d.register(flowPens())
meta2d.register(activityDiagram())
meta2d.register(classPens())
meta2d.register(sequencePens())
meta2d.registerCanvasDraw(sequencePensbyCtx())
// meta2d.registerCanvasDraw(formPens())
// meta2d.registerCanvasDraw(chartsPens())
/* 画布绑定事件 */
meta2d.beforeAddPens = (pens) => { // 添加画笔前
bus.$emit('changeDrawState')
2023-03-07 14:44:05 +08:00
const name = 'elements - ' + meta2d.store.data.pens.length
console.log('123123123123')
2023-02-16 16:33:20 +08:00
if (pens.length === 1) {
if (!pens[0].type) {
2023-03-07 14:44:05 +08:00
this.nodeInit(pens[0], name)
2023-02-16 16:33:20 +08:00
} else {
2023-03-07 14:44:05 +08:00
this.lineInit(pens[0], name)
2023-02-16 16:33:20 +08:00
}
}
return true
}
2023-02-20 19:11:10 +08:00
meta2d.beforeRemovePens = async (pens) => {
bus.$emit('changeSelectPens', [])
// 返回 true 允许 remove
return true
}
meta2d.on('translate', this.topTranslate) // 平移·
2023-02-16 16:33:20 +08:00
meta2d.on('active', this.pensActive) // 选中·
// meta2d.on('translatePens', () => {}) // 移动画笔结束·
// meta2d.on('translatingPens', () => {}) // 移动画笔进行中·
meta2d.on('enter', this.penEnter) // 移入画笔·
meta2d.on('leave', this.penLeave) // 移出画笔·
// meta2d.on('add', this.appPen) // 添加新画笔·
meta2d.on('click', this.topoClick) // click画笔·
setTopology(this.meta2dId, meta2d)
2023-02-20 14:25:09 +08:00
},
reload () {
this.position.show = false
2023-02-20 14:25:09 +08:00
const endTime = new Date().getTime()
2023-02-22 18:21:39 +08:00
const startTime = endTime - 60 * this.params.timeType * 1000
2023-02-20 14:25:09 +08:00
this.getQueryValues(this.querysArray, startTime, endTime).then((arr) => {
this.clacTopoData(this.topoData, arr).then((data) => {
getTopology(this.meta2dId).resize()
getTopology(this.meta2dId).open(data)
getTopology(this.meta2dId).centerView()
getTopology(this.meta2dId).lock(1)
})
2023-02-16 16:33:20 +08:00
})
},
2023-03-07 14:44:05 +08:00
nodeInit (pen, name) { // 初始化节点参数
2023-02-20 19:11:10 +08:00
if (pen.data && pen.data.params) {
return
}
2023-02-16 16:33:20 +08:00
pen.data = {
params: { // 用于编辑时 重置为节点初始状态
2023-02-20 19:11:10 +08:00
background: pen.background || '#22222200',
color: pen.color || '#222222ff',
2023-02-22 15:29:17 +08:00
textColor: pen.textColor || '#222222ff'
2023-02-16 16:33:20 +08:00
},
imageId: '',
valueMapping: [],
legend: '',
2023-02-21 19:05:49 +08:00
statistic: 'last',
parent: '',
value: '',
source: 'text',
textParent: '',
textLegend: '',
text: pen.text || '',
textValue: '',
2023-02-16 16:33:20 +08:00
enable: {
valueMapping: true,
tooltip: true
},
tooltip: {
title: '',
titleShow: true,
chartType: 'line',
content: '',
legends: [] // {legend: '' , alias}
}
}
2023-03-07 14:44:05 +08:00
pen.nzName = name
2023-02-20 19:11:10 +08:00
pen.disableInput = pen.disableInput || true
pen.background = pen.background || '#22222200'
pen.textAlign = pen.textAlign || 'center'
pen.textBaseline = pen.textBaseline || 'middle'
pen.color = pen.color || '#222222ff'
pen.textColor = pen.textColor || '#222222ff'
pen.image = pen.image || ''
pen.imageId = pen.imageId || ''
pen.imageRatio = pen.imageRatio || false
pen.ratio = pen.ratio || false
pen.rotate = pen.rotate || 0
pen.globalAlpha = pen.globalAlpha || 1
pen.borderType = pen.borderType || 0
pen.lineWidth = pen.lineWidth || 1
pen.lineDash = pen.lineDash || []
pen.borderRadius = pen.borderRadius || 0
2023-02-20 14:25:09 +08:00
pen.paddingTop = 5
pen.paddingBottom = 5
pen.paddingLeft = 5
pen.paddingRight = 5
2023-02-20 19:11:10 +08:00
pen.visible = pen.visible || true
pen.isNz = true
pen.locked = pen.locked || 0
2023-03-07 10:32:02 +08:00
pen.isBottom = false
2023-02-16 16:33:20 +08:00
},
2023-03-07 14:44:05 +08:00
lineInit (pen, name) { // 初始化连线参数
2023-02-20 19:11:10 +08:00
if (pen.data && pen.data.params) {
return
}
2023-02-16 16:33:20 +08:00
pen.data = {
params: {
2023-02-20 19:11:10 +08:00
animateColor: pen.animateColor || '#FA901CFF',
borderColor: pen.borderColor || '#22222200',
color: pen.color || '#222222FF'
2023-02-20 14:25:09 +08:00
},
valueMapping: [],
legend: '',
2023-02-21 19:05:49 +08:00
statistic: 'last',
parent: '',
value: '',
2023-02-20 14:25:09 +08:00
enable: {
valueMapping: true,
tooltip: true
2023-02-20 19:11:10 +08:00
}
2023-02-16 16:33:20 +08:00
}
2023-03-07 14:44:05 +08:00
pen.nzName = name
2023-02-20 19:11:10 +08:00
pen.disableInput = pen.disableInput || true
2023-03-07 10:32:02 +08:00
pen.lineAnimateType = pen.lineAnimateType || 0
2023-02-20 19:11:10 +08:00
pen.animateSpan = pen.animateSpan || 1
pen.animateReverse = pen.animateReverse || false
pen.fromArrow = pen.fromArrow || ''
pen.animateColor = pen.animateColor || '#FA901CFF'
pen.borderColor = pen.borderColor || '#22222200'
pen.borderWidth = pen.borderWidth || 0
pen.color = pen.color || '#222222ff'
pen.toArrow = pen.toArrow || ''
pen.borderType = pen.borderType || 0
pen.lineWidth = pen.lineWidth || 1
pen.lineDash = pen.lineDash || []
pen.isNz = pen.isNz || true
pen.visible = pen.visible || true
pen.locked = pen.locked || 0
2023-03-07 10:32:02 +08:00
pen.isBottom = false
pen.autoPlay = false
2023-02-16 16:33:20 +08:00
},
pensActive (pens, e) { // 选中节点
this.selectPens = pens
2023-02-22 18:21:39 +08:00
2023-02-20 19:11:10 +08:00
setTimeout(() => {
2023-02-21 19:05:49 +08:00
this.$refs.meta2dProps && (this.$refs.meta2dProps.isUpdate = true)
2023-02-20 19:11:10 +08:00
})
2023-02-16 16:33:20 +08:00
},
topoClick (params, e) { // 点击节点
if (!params.pen && this.$refs.meta2dProps) {
this.$refs.meta2dProps.activeName = 'canvas'
this.selectPens = []
}
},
topTranslate () {
this.setContextmenu = false
},
2023-02-22 18:21:39 +08:00
penEnter (pen, e) { // 移入节点
if (this.timer3) {
clearTimeout(this.timer3)
this.timer3 = null
}
this.position.show = false
if (!pen.type && pen.data.enable.tooltip) {
if (!pen.data.tooltip.legends.length) {
return
}
2023-02-28 15:38:18 +08:00
let positionShow = false
pen.data.tooltip.legends.forEach(item => {
2023-02-28 15:38:18 +08:00
if (item.legend) {
positionShow = true
}
})
if (!positionShow) {
return
2023-02-28 15:38:18 +08:00
}
2023-02-22 15:29:17 +08:00
this.chartParams = {
...pen.data.tooltip,
unit: this.params.unit,
statistic: this.params.statistic
}
2023-02-22 18:21:39 +08:00
this.timer3 = setTimeout(() => {
let ePosition = window.ePosition
let boxWidth = this.$refs.meta2dBox.offsetWidth
let boxHeight = this.$refs.meta2dBox.offsetHeight
this.position.left = ePosition.layerX
this.position.top = ePosition.layerY
this.$nextTick(() => {
if ((boxWidth / 2) > ePosition.layerX) {
this.position.left = ePosition.layerX + 20
} else {
this.position.left = ePosition.layerX - 20 - 400
}
if (boxHeight > (ePosition.layerY + 300)) {
this.position.top = ePosition.layerY + 50
} else {
this.position.top = ePosition.layerY - 300
}
ePosition = null
boxWidth = null
boxHeight = null
})
this.position.show = true
// this.$refs.meta2dTooltip.$refs.panelChart && (this.$refs.meta2dTooltip.$refs.panelChart.loading = false)
2023-02-22 18:21:39 +08:00
clearTimeout(this.timer3)
}, 100)
2023-02-22 15:29:17 +08:00
}
2023-02-16 16:33:20 +08:00
},
2023-02-22 18:21:39 +08:00
penLeave () {
if (!this.timer3) {
this.timer3 = setTimeout(() => {
this.position.show = false
this.timer3 = null
}, 50)
} else {
clearTimeout(this.timer3)
this.timer3 = null
this.timer3 = setTimeout(() => {
this.position.show = false
this.timer3 = null
}, 50)
}
},
tooltipOver () {
clearTimeout(this.timer3)
this.timer3 = null
},
tooltipOut () {
this.timer3 = setTimeout(() => {
this.position.show = false
this.timer3 = null
}, 50)
2023-02-16 16:33:20 +08:00
},
updatePens (pen, key) { // 更新对应的节点
// meta2d.setValue({ id: pen.id, text: 'new text' }, { render: false });
const obj = { id: pen.id }
obj[key] = pen[key]
if (key === 'lineName') {
getTopology(this.meta2dId).updateLineType(pen, pen[key])
}
2023-02-28 16:16:14 +08:00
if (key === 'lineAnimateType') {
if (!pen[key]) {
obj.autoPlay = false
} else {
obj.autoPlay = true
}
}
2023-03-01 11:08:33 +08:00
if (key === 'x' || key === 'y' || key === 'width' || key === 'height') {
const findPen = getTopology(this.meta2dId).getPenRect(pen)
obj[key] = findPen[key]
}
2023-02-28 16:16:14 +08:00
getTopology(this.meta2dId).setValue(obj) // 更新pen
2023-02-16 16:33:20 +08:00
if (key === 'lineAnimateType') {
if (!pen[key]) {
getTopology(this.meta2dId).stopAnimate(pen.id)
return
}
getTopology(this.meta2dId).startAnimate(pen.id)
}
2023-02-20 14:25:09 +08:00
},
exitEdit (isRefresh) {
this.editFlag = false
this.position.show = false
2023-02-20 14:25:09 +08:00
if (isRefresh) {
this.$emit('reload')
}
},
beforeEdit () {
this.editFlag = true
this.contextmenu = {
left: null,
top: null,
bottom: null
}
this.position.show = false
},
onContextMenu (event) {
if (!this.setContextmenu) {
return
}
event.preventDefault()
event.stopPropagation()
if (event.clientY + 360 < document.body.clientHeight) {
this.contextmenu = {
left: event.clientX + 'px',
top: event.clientY + 'px'
}
} else {
this.contextmenu = {
left: event.clientX + 'px',
bottom: document.body.clientHeight - event.clientY + 'px'
}
}
},
contextmenuNone () {
this.contextmenu = {
left: null,
top: null,
bottom: null
}
2023-02-16 16:33:20 +08:00
}
2023-02-20 19:11:10 +08:00
},
beforeDestroy () {
2023-02-16 16:33:20 +08:00
}
}