font-zoom.vue 924 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <span class="zoom-text" :style="{ fontSize: amount_font_size + 'px' }">{{ amount }}</span>
  3. </template>
  4. <script setup>
  5. import { ref, defineProps, onMounted, watch } from 'vue'
  6. import { getBit } from "@/uilts/help";
  7. let props = defineProps({
  8. amount: {
  9. type: String,
  10. default: ''
  11. },
  12. width: {
  13. type: Number,
  14. default: 360
  15. },
  16. fontSize: {
  17. type: Number,
  18. default: 56
  19. },
  20. })
  21. let amount_font_size = ref(props.fontSize);
  22. watch(props, () => {
  23. setFontSize()
  24. })
  25. function setFontSize(){
  26. let amount = getBit(props.amount);
  27. let _num = parseInt(props.width / amount.length);
  28. amount_font_size.value = _num < props.fontSize ? _num : props.fontSize;
  29. }
  30. onMounted(() => {
  31. setFontSize()
  32. })
  33. </script>
  34. <style lang="scss" scoped>
  35. .zoom-text {
  36. word-break: break-all;
  37. font-weight: 800;
  38. font-size: 22px;
  39. color: #FFFFFF;
  40. }
  41. </style>