refactor: 优化箭头展示,并适配屏幕变化
This commit is contained in:
parent
585cd1e65f
commit
383534037a
|
@ -2,12 +2,12 @@
|
||||||
<div class="rel-box">
|
<div class="rel-box">
|
||||||
<svg v-for="(relLine, idx) in relLines" :key="idx" class="rel"
|
<svg v-for="(relLine, idx) in relLines" :key="idx" class="rel"
|
||||||
xmlns="http://www.w3.org/2000/svg" version="1.1" >
|
xmlns="http://www.w3.org/2000/svg" version="1.1" >
|
||||||
<marker id="arrow" markerUnits="strokeWidth" markerWidth="10" markerHeight="10" viewBox="0 0 12 12" refX="6" refY="6" orient="auto">
|
<marker id="arrow" markerUnits="strokeWidth" markerWidth="8" markerHeight="8" viewBox="0 0 12 12" refX="6" refY="6" orient="auto">
|
||||||
<path d="M2,2 L10,6 L2,10 L6,6 L2,2" :style="`fill:${types[relDetails[idx]['type']]['color']}`"/>
|
<path d="M2,2 L10,6 L2,10 L6,6 L2,2" :style="`fill:${types[relDetails[idx]['type']]['color']}`"/>
|
||||||
</marker>
|
</marker>
|
||||||
<path :d="relLine"
|
<path :d="relLine"
|
||||||
:title="relDetails[idx]['type']"
|
:title="relDetails[idx]['type']"
|
||||||
:style="`stroke:${types[relDetails[idx]['type']]['color']};stroke-width:2;fill:#0000;marker-end:url(#arrow)`"
|
:style="`stroke:${types[relDetails[idx]['type']]['color']};stroke-width:3;fill:#0000;marker-end:url(#arrow)`"
|
||||||
@contextmenu="delRel($event, idx)"
|
@contextmenu="delRel($event, idx)"
|
||||||
/>
|
/>
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -15,7 +15,6 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
export default ({
|
export default ({
|
||||||
name: 'Rel',
|
name: 'Rel',
|
||||||
props: {
|
props: {
|
||||||
|
@ -53,27 +52,34 @@ export default ({
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
this.relDetails.splice(idx, 1)
|
this.relDetails.splice(idx, 1)
|
||||||
this.save()
|
this.save()
|
||||||
|
},
|
||||||
|
calRelLines (val) {
|
||||||
|
console.log('21341234');
|
||||||
|
if (!val) {
|
||||||
|
val = this.relDetails
|
||||||
|
}
|
||||||
|
console.log(this.types)
|
||||||
|
let _relLines = []
|
||||||
|
for (let i = 0; i < val.length; i++) {
|
||||||
|
const item = val[i]
|
||||||
|
let startCharDom = document.getElementById(item.start)
|
||||||
|
let endCharDom = document.getElementById(item.end)
|
||||||
|
let sx = startCharDom.offsetLeft + startCharDom.offsetWidth / 2
|
||||||
|
let sy = startCharDom.offsetTop + 9
|
||||||
|
let ex = endCharDom.offsetLeft + endCharDom.offsetWidth / 2
|
||||||
|
let ey = endCharDom.offsetTop + 9
|
||||||
|
let cx = (sx + ex) / 2
|
||||||
|
let cy = (sy + ey) / 2 - 20
|
||||||
|
_relLines.push(`M${sx} ${sy} Q${cx} ${cy} ${ex} ${ey}`)
|
||||||
|
}
|
||||||
|
console.log(_relLines)
|
||||||
|
this.relLines = _relLines
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
relDetails: {
|
relDetails: {
|
||||||
handler (val) {
|
handler (val) {
|
||||||
console.log(this.types)
|
this.calRelLines(val)
|
||||||
let _relLines = []
|
|
||||||
for (let i = 0; i < val.length; i++) {
|
|
||||||
const item = val[i]
|
|
||||||
let startCharDom = document.getElementById(item.start)
|
|
||||||
let endCharDom = document.getElementById(item.end)
|
|
||||||
let sx = startCharDom.offsetLeft + startCharDom.offsetWidth / 2
|
|
||||||
let sy = startCharDom.offsetTop + 9
|
|
||||||
let ex = endCharDom.offsetLeft + endCharDom.offsetWidth / 2
|
|
||||||
let ey = endCharDom.offsetTop + 9
|
|
||||||
let cx = (sx + ex) / 2
|
|
||||||
let cy = (sy + ey) / 2 - 20
|
|
||||||
_relLines.push(`M${sx} ${sy} Q${cx} ${cy} ${ex} ${ey}`)
|
|
||||||
}
|
|
||||||
console.log(_relLines)
|
|
||||||
this.relLines = _relLines
|
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
},
|
},
|
||||||
|
@ -81,6 +87,12 @@ export default ({
|
||||||
handler (val) {
|
handler (val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
let that = this
|
||||||
|
window.onresize = function () {
|
||||||
|
that.calRelLines()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -101,4 +113,8 @@ export default ({
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
.rel:hover {
|
||||||
|
/* 抬起来一些 */
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue