FontAmount.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <span :style="{ fontSize: amount_font_size + 'px' }">
  3. <a-tooltip :title="amount">
  4. {{ getBit(amount) }}
  5. </a-tooltip>
  6. </span>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. amount: {
  12. type: String,
  13. default: ''
  14. },
  15. width: {
  16. type: Number,
  17. default: 360
  18. },
  19. fontSize: {
  20. type: Number,
  21. default: 56
  22. },
  23. },
  24. data() {
  25. return {
  26. amount_font_size: 60,
  27. }
  28. },
  29. watch: {
  30. amount(newV) {
  31. if (newV) {
  32. this.setFontSize()
  33. }
  34. },
  35. width(newV) {
  36. if (newV) {
  37. this.setFontSize()
  38. }
  39. },
  40. fontSize(newV) {
  41. if (newV) {
  42. this.setFontSize()
  43. }
  44. },
  45. },
  46. mounted() {
  47. this.setFontSize()
  48. },
  49. methods: {
  50. setFontSize() {
  51. let _num = parseInt(this.width / this.amount.length);
  52. this.amount_font_size = _num < this.fontSize ? _num : this.fontSize;
  53. },
  54. getBit (value) {
  55. const reg = /([0-9]+\.[0-9]{4})[0-9]*/;
  56. if(value) {
  57. let str = value.toString();
  58. str = str.replace(reg,"$1");
  59. return str;
  60. } else {
  61. return value;
  62. }
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="scss" scoped>
  68. </style>