index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <sketch-rule
  3. v-if="configShow"
  4. :thick="thick"
  5. :scale="scale"
  6. :width="canvasBox().width"
  7. :height="canvasBox().height"
  8. :startX="startX"
  9. :startY="startY"
  10. :lines="lines"
  11. ></sketch-rule>
  12. </template>
  13. <script setup lang="ts">
  14. import { ref, toRefs, computed, watch, nextTick, onBeforeUnmount } from 'vue'
  15. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  16. import { useDesignStore } from '@/store/modules/designStore/designStore'
  17. import { useChartLayoutStore } from '@/store/modules/chartLayoutStore/chartLayoutStore'
  18. const chartEditStore = useChartEditStore()
  19. const chartLayoutStore = useChartLayoutStore()
  20. const designStore = useDesignStore()
  21. const { width, height } = toRefs(chartEditStore.getEditCanvasConfig)
  22. const { scale, lockScale } = toRefs(chartEditStore.getEditCanvas)
  23. const { getLayers, getCharts, getDetails } = toRefs(chartLayoutStore)
  24. const configShow = ref(true)
  25. // x轴标尺开始的坐标数值
  26. const startX = -10
  27. // y轴标尺开始的坐标数值
  28. const startY = -10
  29. // 标尺的厚度
  30. const thick = 20
  31. // 初始化水平标尺上的参考线
  32. const lines = {
  33. h: [],
  34. v: []
  35. }
  36. const canvasBox = () => {
  37. const layoutDom = document.getElementById('go-chart-edit-layout')
  38. if (layoutDom) {
  39. return {
  40. height: layoutDom.clientHeight - 40,
  41. width: layoutDom.clientWidth
  42. }
  43. }
  44. return {
  45. width: width.value,
  46. height: height.value
  47. }
  48. }
  49. // 颜色
  50. const themeColor = computed(() => {
  51. return designStore.getAppTheme
  52. })
  53. // 处理标尺重制大小
  54. const ruleChangeHandle = () => {
  55. configShow.value = false
  56. setTimeout(() => {
  57. configShow.value = true
  58. })
  59. }
  60. const ruleChangeHandleTimeOut = () => {
  61. if (lockScale.value) {
  62. setTimeout(() => {
  63. ruleChangeHandle()
  64. }, 500)
  65. }
  66. }
  67. watch(
  68. () => scale.value,
  69. () => ruleChangeHandle()
  70. )
  71. watch(
  72. () => getLayers.value,
  73. () => ruleChangeHandleTimeOut()
  74. )
  75. watch(
  76. () => getCharts.value,
  77. () => ruleChangeHandleTimeOut()
  78. )
  79. watch(
  80. () => getDetails.value,
  81. () => ruleChangeHandleTimeOut()
  82. )
  83. </script>
  84. <style>
  85. /* 使用 SCSS 会报错,直接使用最基础的 CSS 进行修改,
  86. 此库有计划 Vue3 版本,但是开发的时候还没发布 */
  87. #mb-ruler {
  88. top: 0;
  89. left: 0;
  90. }
  91. /* 适配底部的工具栏不遮盖 */
  92. #mb-ruler .v-container {
  93. height: calc(100% - 65px) !important;
  94. }
  95. /* 横线 */
  96. #mb-ruler .v-container .lines .line {
  97. /* 最大缩放 200% */
  98. width: 200vw !important;
  99. border-top: 1px dashed v-bind('themeColor') !important;
  100. }
  101. #mb-ruler .v-container .indicator {
  102. border-bottom: 1px dashed v-bind('themeColor') !important;
  103. }
  104. /* 竖线 */
  105. #mb-ruler .h-container .lines .line {
  106. /* 最大缩放 200% */
  107. height: 200vh !important;
  108. border-left: 1px dashed v-bind('themeColor') !important;
  109. }
  110. #mb-ruler .h-container .indicator {
  111. border-left: 1px dashed v-bind('themeColor') !important;
  112. }
  113. /* 坐标数值背景颜色 */
  114. #mb-ruler .indicator .value {
  115. background-color: rgba(0, 0, 0, 0);
  116. }
  117. /* 删除按钮 */
  118. #mb-ruler .line .del {
  119. padding: 0;
  120. color: v-bind('themeColor');
  121. font-size: 26px;
  122. font-weight: bolder;
  123. }
  124. #mb-ruler .corner {
  125. border-width: 0 !important;
  126. }
  127. </style>