border.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <div class="hc-datav-border-box">
  3. <svg ref="mainRef" class="hc-datav-svg">
  4. <polygon fill="transparent" :points="`10, 22 ${mainWidth - 30}, 22 ${mainWidth - 30}, 64 ${mainHeight - 25}, ${mainHeight - 25} 10, 126`" />
  5. <polyline :points="`8, 5 ${mainWidth - 5}, 5 ${mainWidth - 5}, ${mainHeight - 100} ${mainWidth - 100}, ${mainHeight - 4} 8, ${mainHeight - 4} 8, 5`" class="hc-datav-line-1" stroke="#83bff6" />
  6. <polyline :points="`3, 5 ${mainWidth - 18}, 5 ${mainWidth - 18}, ${mainHeight - 74} ${mainWidth - 84}, ${mainHeight - 4} 3, ${mainHeight - 4} 3, 5`" class="hc-datav-line-2" stroke="#00CED1" />
  7. <polyline :points="`50, 13 ${mainWidth - 30}, 13`" class="hc-datav-line-3" stroke="#00CED1" />
  8. <polyline :points="`15, 20 ${mainWidth - 30}, 20`" class="hc-datav-line-4" stroke="#00CED1" />
  9. <polyline :points="`15, ${mainHeight - 20} ${mainWidth - 108}, ${mainHeight - 20}`" class="hc-datav-line-5" stroke="#00CED1" />
  10. <polyline :points="`15, ${mainHeight - 13} ${mainWidth - 108}, ${mainHeight - 13}`" class="hc-datav-line-6" stroke="#00CED1" />
  11. </svg>
  12. <div class="border-box-content" :style="{ width: `${mainWidth - 108}px` }">
  13. <slot />
  14. </div>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { onMounted, ref } from 'vue'
  19. //渲染完成
  20. onMounted(() => {
  21. windowResize()
  22. setTimeout(() => {
  23. onWindowResize()
  24. }, 500)
  25. })
  26. //监听浏览器窗口变化
  27. const windowResize = () => {
  28. window.addEventListener('resize', resizeEvent)
  29. }
  30. const resizeEvent = () => {
  31. window.requestAnimationFrame(() => {
  32. onWindowResize()
  33. })
  34. }
  35. //设置尺寸
  36. const mainRef = ref(null)
  37. const mainWidth = ref(0)
  38. const mainHeight = ref(0)
  39. const onWindowResize = () => {
  40. const el = mainRef.value
  41. mainWidth.value = el.clientWidth
  42. mainHeight.value = el.clientHeight
  43. }
  44. </script>
  45. <style scoped lang="scss">
  46. .hc-datav-border-box {
  47. position: relative;
  48. width: 100%;
  49. height: 100%;
  50. .hc-datav-svg {
  51. position: absolute;
  52. inset: 0;
  53. width: 100%;
  54. height: 100%;
  55. polyline {
  56. fill: none;
  57. }
  58. .hc-datav-line-1, .hc-datav-line-2 {
  59. stroke-width: 1;
  60. }
  61. .hc-datav-line-3, .hc-datav-line-6 {
  62. stroke-width: 5;
  63. }
  64. .hc-datav-line-4, .hc-datav-line-5 {
  65. stroke-width: 2;
  66. }
  67. }
  68. .border-box-content {
  69. position: relative;
  70. width: 100%;
  71. height: 100%;
  72. padding-top: 28px;
  73. padding-bottom: 28px;
  74. padding-left: 15px;
  75. }
  76. }
  77. </style>