u--text-price.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view class="u-text-price-wrap">
  3. <text
  4. v-for="(item,index) in textArray"
  5. :key="index"
  6. :style="{'font-size': (index === 1 ? integerSize : size) + 'px', 'color': color}"
  7. >
  8. {{item}}
  9. </text>
  10. </view>
  11. </template>
  12. <script>
  13. /**
  14. * 此组件存在只为简单的显示特定样式的(人名币)价格数字
  15. */
  16. export default {
  17. name: "u--text-price",
  18. components: {
  19. },
  20. props: {
  21. text: {
  22. type: String,
  23. default: '0.00'
  24. },
  25. color: {
  26. type: String,
  27. default: '#333333'
  28. },
  29. //字体大小
  30. size: {
  31. type: [String, Number],
  32. default: uni.$u.props.text.size
  33. },
  34. //整形部分字体大小可单独定义
  35. intSize: {
  36. type: [String, Number],
  37. default: uni.$u.props.text.size
  38. }
  39. },
  40. computed: {
  41. textArray() {
  42. let array = ['¥'];
  43. if (!/^\d+(\.\d+)?$/.test(this.text)) {
  44. uni.$u.error('组件<u--text-price :text="???" 此处参数应为金额数字');
  45. } else {
  46. let arr = parseFloat(this.text).toFixed(2).split('.');
  47. array.push(arr[0]);
  48. array.push('.' + arr[1]);
  49. }
  50. return array;
  51. },
  52. integerSize() {
  53. return this.intSize ? this.intSize : this.size
  54. }
  55. }
  56. };
  57. </script>
  58. <style>
  59. </style>