消毒机设备
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.3 KiB

  1. <script lang="ts" setup>
  2. import { computed, ref, watch } from 'vue'
  3. // 接收外部传入的最大刻度值参数,比如 3000、5000 等
  4. // const props = defineProps({
  5. // maxScale: {
  6. // type: number
  7. // default: 2500
  8. // },
  9. // rulerHeight: {
  10. // type: number
  11. // default: 0
  12. // }
  13. // })
  14. const props = defineProps({
  15. maxScale: {
  16. type: Number,
  17. default: 2500,
  18. },
  19. rulerHeight: {
  20. type: Number,
  21. default: 0,
  22. },
  23. })
  24. // 基础配置,可根据需求调整
  25. const baseInterval = 300 // 大刻度间隔(显示文字的刻度间隔)
  26. const smallInterval = 20 // 小刻度间隔
  27. const totalHeight = ref(props.rulerHeight) // 刻度标尺总高度(px)
  28. const markHeight = 2 // 刻度线高度(px)
  29. watch(props.rulerHeight, (newVal) => {
  30. totalHeight.value = newVal
  31. })
  32. // 计算要渲染的刻度数据
  33. const renderedMarks = computed(() => {
  34. const marks: Liquid.Marks[] = []
  35. for (let value = 0; value <= Number(props.maxScale); value += smallInterval) {
  36. const showText = value % baseInterval === 0 || value % Number(props.maxScale) === 0
  37. const startY = (value / Number(props.maxScale)) * totalHeight.value
  38. marks.push({ value, startY, showText })
  39. }
  40. return marks
  41. })
  42. const rulerWidth = (mark) => {
  43. console.log('mark--', mark)
  44. if (mark.value % 100 === 0) {
  45. return 80
  46. }
  47. if (mark.value % 5 === 0) {
  48. return 40
  49. }
  50. return 20
  51. }
  52. </script>
  53. <template>
  54. <div class="scale-ruler-container" :style="{ height: `${totalHeight}px` }">
  55. <div
  56. v-for="(mark, index) in renderedMarks"
  57. :key="index"
  58. class="scale-mark"
  59. :style="{
  60. height: `${markHeight}px`,
  61. top: `${totalHeight - mark.startY}` + 'px',
  62. width: `${rulerWidth(mark)}%`,
  63. }"
  64. >
  65. <div v-if="mark.showText" class="mark-text" :style="{ transform: 'translateX(-120%) translateY(-50%)' }">
  66. <div>{{ mark.value }}g</div>
  67. </div>
  68. </div>
  69. </div>
  70. </template>
  71. <style scoped lang="scss">
  72. .scale-ruler-container {
  73. position: relative;
  74. width: 40px; /* 刻度容器宽度,可按需调整 */
  75. border-left: 1px solid #000; /* 刻度标尺边框 */
  76. margin-left: 20px; /* 给文字留出显示空间,可按需调整 */
  77. }
  78. .scale-mark {
  79. position: absolute;
  80. background-color: #000;
  81. }
  82. .mark-text {
  83. position: absolute;
  84. font-size: 12px;
  85. white-space: nowrap;
  86. }
  87. </style>